C#调用IOS脚本
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class SDK_Manager_IOS
{
[DllImport("__Internal")]
private static extern void _MinePlayMove();
[DllImport("__Internal")]
private static extern void _XiYouCopyToClipboard(string str);
//播放视频
public static void MinePlayMove()
{
if( Application.platform == RuntimePlatform.IPhonePlayer )
_MinePlayMove();
}
//复制到剪贴板
public static void CopyToClipboard(string str)
{
if (Application.platform == RuntimePlatform.IPhonePlayer)
_XiYouCopyToClipboard(str);
}
}
IOS脚本
UnityAppController.mm
///
extern "C" {
void _MinePlayMove();
void _XiYouCopyToClipboard(const char* str);
}
//播放视频
void _MinePlayMove()
{
NSLog(@"Start");
i++;
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"MP4"];
NSLog(@"FilePath is %@ ", path);
//视频URL
NSURL *url = [NSURL fileURLWithPath:path];
//视频播放对象
GetAppController().movie = [[MPMoviePlayerController alloc] initWithContentURL:url];
GetAppController().movie.controlStyle = MPMovieControlStyleNone;
[GetAppController().movie.view setFrame:GetAppController().unityView.bounds];
UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:@"backButton.png"] forState:0];
//btn.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-200, [UIScreen mainScreen].bounds.size.height-100, 187 , 76);
float widht =[UIScreen mainScreen].bounds.size.width;
float height =[UIScreen mainScreen].bounds.size.height;
float temp = widht;
if(widht < height)
{
widht = height;
height =temp;
}
if(widht >= 1024)
{
btn.frame = CGRectMake(widht-190, height-80, 187 , 76);
}
else
{
btn.frame = CGRectMake(widht-187*0.8, height-76*0.8, 187*0.6 , 76*0.6);
}
NSLog(@"width=%f,height=%f",btn.frame.origin.x,btn.frame.origin.y);
NSLog(@"width=%f,height=%f",[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height);
// [btn setTitle:@"Stop" forState:UIControlStateNormal];
[btn addTarget:GetAppController() action:@selector(FinishedCallback) forControlEvents:UIControlEventTouchUpInside];
//[btn release];
// movie.initialPlaybackTime = -1;
[GetAppController().unityView addSubview:GetAppController().movie.view];
// 注册一个播放结束的通知
[[NSNotificationCenter defaultCenter] addObserver:GetAppController()
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:GetAppController().movie];
[GetAppController().movie.view addSubview:btn];
[GetAppController().movie play];
}
//复制到剪贴板
void _XiYouCopyToClipboard(const char* str)
{
NSString *copyStr = [NSString stringWithCString:str encoding:NSUTF8StringEncoding];
NSLog(@"开始复制到剪贴板 :%@",copyStr);
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = copyStr;
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"系统提示" message:@"已复制到剪贴板。" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alter show];
[alter release];
}
//显示对话框
//显示遮罩