您现在的位置是:首页 > 文章详情

Unity与安卓开发的一些路径知识

日期:2018-04-06点击:386



APK安装之后找不到路径

公司的测试机(安卓)基本都是不带SD卡的。

APK在安卓手机上安装之后,使用手机助手类的软件打开文件管理,打开 内置SDK卡/Android/data/ 在这个目录下却发现 找不到以应用的包名(com.xxx.xxx) 开头的文件夹,那比如要打开这个目录查看里面的文件呢?

image

但是却能看到一些其它APP的目录,那么请检查以下设置:

1、打开 File -  Build Settings -  选择 Player Settings ,请确认已经切换到了Android 平台,找到 Configuration 这一部分设置

2、Install Location 选择 Automatic

Write Permission 选择 External (SDCard)

image

3、重新打包APK,并安装,就可以在文件管理中找到这个目录了。

 

安卓的写入路径

比如你想在安装目录下创建一个目录并往里面写入文件,路径建议这样写:(和windows下的路径符号不同,而是和浏览器中网络的路径符号相同)

string savePath = Application.persistentDataPath + "/" + "SaveTextures/";

而如果你这样写,那么极有可能出现错误!

string savePath = Application.persistentDataPath + "\\SaveTextures\\"

我在安卓上测试,会出现文件名变成:files\SaveTextures\2017-01-13_02-12-54.png 也就是说文件名变成了路径,所以当你使用路径加载时,就会报文件不存在。

 

WWW加载的文件协议

使用WWW 加载非Assetbundle文件,比如原始的音乐文件(mp3,wav),原始的贴图文件(png,jpg)

比如这个文件放在应用程序的沙盒内或SD卡内:Application.persistentDataPath

复制代码
public static string GetFileProtocol() { string fileProtocol = "file://"; if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer #if !UNITY_5_4_OR_NEWER || Application.platform == RuntimePlatform.WindowsWebPlayer #endif ) { fileProtocol = "file:///"; } return fileProtocol; }
复制代码

使用 www 加载示例:

复制代码
public static IEnumerator LoadByWWW(string fullFilePath, Action<Texture2D> callback) { string loadPath = GetFileProtocol() + fullFilePath; WWW www = new WWW(loadPath); yield return www; if (www != null && string.IsNullOrEmpty(www.error)) { //获取Texture Texture2D texture = www.texture; if (callback != null) callback(texture); } else { Log.LogError("www 加载图片失败:{0}", www.error); if (callback != null) callback(null); } }
复制代码

 

测试环境

本文的测试环境如下:

Unity 5.5.0f3

安卓4.2.3


本文转自赵青青博客园博客,原文链接:http://www.cnblogs.com/zhaoqingqing/p/6283763.html,如需转载请自行联系原作者

posted @  2017-01-13 18:31  赵青青 阅读( 315) 评论( 0编辑  收藏

原文链接:https://yq.aliyun.com/articles/352861
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章