当前位置:   article > 正文

Unity3d截图功能实现一(非AR版)_unity 截图功能不要ui

unity 截图功能不要ui

原文链接:AR学院
ARVR技术交流群:129340649,欢迎加入!

和之前介绍的扫描二维码的教程类似,对于在unity3d中截图的功能实现,也可以两种方式, 

1、 使用现成插件  
2、 自己从Android端开发,然后做成插件  
其实这两个方法原理一样,都是调用Android的接口  
另外,Unity3d自己本身也提供了截图的API  
 
这里先介绍使用现成的插件截图:  
注意事项:  
1AndroidManifest.xml文件权限设置:  

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?xml version= "1.0"  encoding= "utf-8" ?>
    
<manifest xmlns:android= "http://schemas.android.com/apk/res/android"  package= "com.qualcomm.QCARUnityPlayer"  android:versionCode= "1"  android:versionName= "1.0" >
    
<uses-sdk android:minSdkVersion= "8"  />
    
<uses-feature android:name= "android.hardware.camera"  />
    
<supports-screens android:smallScreens= "true"  android:normalScreens= "true"  android:largeScreens= "true"  android:anyDensity= "true"  />
    
<uses-permission android:name= "android.permission.INTERNET"  />
    
<uses-permission android:name= "android.permission.CAMERA"  />
    
<uses-permission android:name= "android.permission.ACCESS_NETWORK_STATE"  />
    
<uses-permission android:name= "android.permission.READ_EXTERNAL_STORAGE"  />
    
<uses-permission android:name= "android.permission.WRITE_EXTERNAL_STORAGE"  />
    
<application android:icon= "@drawable/app_icon"  android:label= "@string/app_name"  android:theme= "@android:style/Theme.NoTitleBar.Fullscreen"  android:debuggable= "false" >
    
<activity android:name= "com.qualcomm.QCARUnityPlayer.QCARPlayerNativeActivity"  android:label= "@string/app_name"  android:screenOrientation= "portrait"  android:configChanges= "fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
    
<meta-data android:name= "android.app.lib_name"  android:value= "unity"  />
    
<meta-data android:name= "unityplayer.ForwardNativeEventsToDalvik"  android:value= "false"  />
    
<intent-filter>
    
<action android:name= "android.intent.action.MAIN"  />
    
<category android:name= "android.intent.category.LAUNCHER"  />
    
</intent-filter>
    
</activity>
    
<activity android:name= "com.unity3d.player.VideoPlayer"  android:label= "@string/app_name"  android:screenOrientation= "portrait"  android:configChanges= "fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" >
    
</activity>
    
</application>
    
</manifest>
    
<!-- android:installLocation= "preferExternal"  -->

源文件没有添加写入 SD卡的权限,所以需要开发者手动添加。  
 
或者设置Write AccessExternalSDCard  
 
 
2、 代码调用  

复制代码
1
StartCoroutine(ScreenshotManager.Save( "test" "myScreenShot" , false ));

第一个参数为截图名称,第二个参数是文件夹名称。  
看源码之后,得知  
截图文件名称定义如下:  

复制代码
1
2
3
4
5
string  date = System.DateTime.Now.ToString( "dd-MM-yy" );
    
ScreenshotManager.ScreenShotNumber++;
    
string  screenshotFilename = fileName +  "_"  + ScreenshotManager.ScreenShotNumber +  "_"  + date +  ".png" ;
 
另外文件夹的位置如下:  

复制代码
1
string  androidPath =  "/../../../../DCIM/"  + albumName +  "/"  + screenshotFilename;
 
插件地址:http://www.arvrschool.com/read.php?tid=109&fid=71#read_8  
源码地址:http://www.arvrschool.com/read.php?tid=119&fid=60  

这是非AR版,AR版地址: 

AR版
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/715885
推荐阅读
相关标签
  

闽ICP备14008679号