Unity平臺調用IOS

C#調用IOS腳本c#

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腳本ide

UnityAppController.mmurl

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


//顯示對話框

//顯示遮罩
相關文章
相關標籤/搜索