- 最后登录
- 2017-5-15
- 注册时间
- 2012-3-1
- 阅读权限
- 90
- 积分
- 32973
- 纳金币
- 32806
- 精华
- 12
|
用的c#写的脚本。项目中需要把2进制资源文件读出来给FileStream 变量。然后解析这个FileStream 变量。
目前用的方法是:
FileStream stFile = null;
string path = Application.dataPath + "/Resources/test.dat";
stFile = new FileStream(path, FileMode.Open, FileAccess.Read);
连接android设备编译,找不到文件test.dat文件。经测试是path的路径设置问题。
从网上找解决办法。
目前试过如下的代码:
方法01:
string path = Application.dataPath + "/Raw/test.dat"
stFile = new FileStream(path, FileMode.Open, FileAccess.Read);
方法02:
string path= Application.persistentDataPath + "/test.dat" ;
stFile = new FileStream(path, FileMode.Open, FileAccess.Read);
方法03:
资源文件放到\Assets\StreamingAssets目录下
string path = "jar:file://" + Application.dataPath + "!/assets/test.dat"
WWW www = new WWW(path);
stFile = new FileStream(www.url, FileMode.Open, FileAccess.Read);
方法04:
TextAsset t = (TextAsset)Resources.Load("text", typeof(TextAsset));
stFile = new FileStream(t.ToString, FileMode.Open, FileAccess.Read);
目前都有问题,android还未运行通过。以下是我找的一些资料网址。
http://forum.unity3d.com/threads/102451-WWW-file-protocol-error
http://forum.unity3d.com/threads/84478-How-can-i-load-assetsbundle-from-android-local-device
http://forum.unity3d.com/threads/65344-Assert-bundles-in-the-data-folder?p=466159&viewfull=1#post466159
http://answers.unity3d.com/questions/184651/how-to-load-text-file.html
http://answers.unity3d.com/questions/126578/how-do-i-get-into-my-streamingassets-folder-from-t.html
http://forum.unity3d.com/threads/61198-Data-Storage-How-to-read-write-files
http://www.mindthecube.com/blog/2009/11/reading-text-data-into-a-unity-game
http://www.previewlabs.com/file-io-in-unity3d/
http://www.google.com.hk/webhp?hl=zh-CN&sourceid=cnhp#hl=zh-CN&safe=strict&gbv=2&q=unity+android+load+txt+file+&oq=unity+android+load+txt+file+&aq=f&aqi=&aql=&gs_**=e&gs_upl=1632819l1673813l17l1673956l32l29l2l14l16l0l221l1453l6.5.1l12l0&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=32485b744981b8ba&biw=1280&bih=710
哪位有实际经验的可否给点解决办法。十分感谢。
|
|