unity3d屏幕截图功能
来源:互联网 发布:保卫萝卜3炮塔数据挖掘 编辑:程序博客网 时间:2024/04/27 14:06
function OnGUI(){ if(GUI.Button(Rect(Screen.width*0.5-50,Screen.height*0.5-50,100,100),"screen")){ Application.CaptureScreenshot("Screenshot.png"); }}
这张Screenshot.png图片被存在了当前工程的子目录下了。之前在android上面一直不知道路径,后来把所有路径试玩了总算ok了,呵呵~~~在android上截取的图片存在Application.persistentDataPath上面,在pc上存在Application.dataPath。
private var www:WWW;private var image:Texture;private var path:String;function Awake(){ Application.CaptureScreenshot("Screenshot.png");}function Start () { if(Application.platform==RuntimePlatform.Android){ path=Application.persistentDataPath; }else if(Application.platform==RuntimePlatform.WindowsPlayer){ path=Application.dataPath; }else if(Application.platform==RuntimePlatform.WindowsEditor){ path=Application.dataPath; path=path.Replace("/Assets",null); } www=new WWW("file://"+path+"/Screenshot.png"); yield www; image=www.texture;}function OnGUI(){ GUI.Label(Rect(0,0,400,50),"1:"+Application.persistentDataPath); GUI.Label(Rect(0,50,400,50),"2:"+Application.dataPath); GUI.Label(Rect(0,100,400,50),"3:"+Application.temporaryCachePath); GUI.Label(Rect(0,150,400,50),"4:"+Application.absoluteURL); GUI.Label(Rect(0,200,400,50),"5:"+Application.streamingAssetsPath); GUI.DrawTexture(Rect(0,250,300,200),image);}在编辑器上各种路径:
在pc上各种路径:
在web上各种路径:
在android上面各种路径:
第二种方法:
import System.IO;var www:WWW;var image:Texture;function Start () {}function OnGUI() { if(GUI.Button(Rect(0,0,100,100),"png")){ writeFile(); } if(Input.GetKey(KeyCode.Escape)){ Application.Quit(); } www=new WWW("file://"+path); image=www.texture; GUI.Button(Rect(Screen.width-100,0,100,100),image); }private var fileName : String = "jietu2";private var path:String;function writeFile(){ path=Application.dataPath; var tex : Texture2D= new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24, false); tex.ReadPixels(Rect(0,0,Screen.width,Screen.height),0,0); tex.Apply(); var bytes : byte[]=tex.EncodeToPNG(); Destroy(tex); var thisName : String = fileName+".png"; if(Application.platform==RuntimePlatform.Android){ path="/mnt/sdcard/"+thisName; }else{ path=path+thisName; } var cache = new FileStream(path, FileMode.Create); cache.Write(bytes,0,bytes.Length); cache.Close();}
后来我又试了一下这个方法,结果又不行了,运行到var cache = new FileStream(path, FileMode.Create);就不运行了。
- unity3d屏幕截图功能
- unity3d 屏幕截图
- Unity3D-屏幕截图
- Unity3d屏幕截图方法
- Android屏幕截图功能
- 屏幕截图功能实现
- iOS屏幕截图功能
- python屏幕截图功能
- unity3d 屏幕截图多种写法
- unity3d 屏幕截图多种写法
- unity3d 屏幕截图 核心代码
- unity3d 屏幕截图多种写法
- Android-屏幕截图功能实现
- Unity3D游戏开发之“屏幕截图”
- Vb.net2005实现屏幕截图功能
- 傲游Maxthon强大的屏幕截图功能
- cocos2d-x实现简易屏幕截图功能
- 系统自带屏幕截图功能
- juery中的事件委托-delegate
- java 数组转List
- hibernate4-过程
- Verilog HDL 测量相位差
- SQL查询
- unity3d屏幕截图功能
- 省份城市oracle脚本
- Vim 配置详解
- QT添加库目录
- Ruby字符串操作
- MFC类型转换那些事
- 服务引用和web引用
- Error in spool C call: spool overflow
- VS2010不能正确加载 'VSTS for Database Professionals Sql Server Data-tier Application'