Unity平台调用IOS

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];
}


//显示对话框

//显示遮罩


转载于:https://my.oschina.net/u/698044/blog/610430

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值