现在的位置: 首页 > 综合 > 正文

Unity3d 截屏

2018年05月25日 ⁄ 综合 ⁄ 共 948字 ⁄ 字号 评论关闭
1.js脚本(添加到ARCamera上)

#pragma strict

function Start () {}

function Update () {}

function ScreenImage(){

Application.CaptureScreenshot("Screenshot.png"); 

}

2.添加button

   UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];       

    [button1 setFrame:CGRectMake(0, 0, 30, 30)];  

    [button1 addTarget:self action:@selector(ScreenImage) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button1];

3.响应函数

-(void)ScreenImage{  

    ///调取脚本函数

    UnitySendMessage("ARCamera","ScreenImage","");  

    

 //保存到相册

    NSFileManager *fileManager = [NSFileManager defaultManager];  

    NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,                                                                          NSUserDomainMask, YES);  

    NSString *documentsDirectory = [paths objectAtIndex:0];  

    NSString *filePath2 = [documentsDirectory stringByAppendingPathComponent:@"Screenshot.png"];  

    UIImage *image = [UIImage imageWithContentsOfFile:filePath2];  

    UIImageWriteToSavedPhotosAlbum(image,nil, nil, nil);//保存

}

抱歉!评论已关闭.