互联网站,怎么做纯文本网站,wordpress 音乐 主题,优秀个人网站设计模板在安卓下无法获取StreamingAssets目录下所有目录和文件名#xff0c;所以需要提前将文件名整理成一个文件filelist.txt。
1.用批处理命令将StreamingAssets下所有文件名输出到filelist.txt中
chcp 65001是使用UTF-8编码#xff0c;否则中文是乱码。
echo off
chcp 65001
d…在安卓下无法获取StreamingAssets目录下所有目录和文件名所以需要提前将文件名整理成一个文件filelist.txt。
1.用批处理命令将StreamingAssets下所有文件名输出到filelist.txt中
chcp 65001是使用UTF-8编码否则中文是乱码。
echo off
chcp 65001
dir /b /s /a-d filelist.txt
2.将filelist.txt中绝对路径转换成相对路径
打开filelist.txt去掉StreamingAssets 3.确何filelist.txt为UTF-8 4.复制StreamingAssets目录下所有文件到PersistentData
void Start () {CopySteamingAssetsFileToPersistentDataPath();
}void CopySteamingAssetsFileToPersistentDataPath()
{string listFile Path.Combine(Application.streamingAssetsPath, filelist.txt);WWW reader new WWW(listFile);while (!reader.isDone) { }string textString reader.text;Debug.Log(textString.Length);Liststring striparr textString.Split(new string[] { \r\n }, StringSplitOptions.None).ToList();Liststring lines striparr.Where(s !string.IsNullOrEmpty(s)).ToList();for (int i 0; i lines.Count; i){string srcfile Path.Combine(Application.streamingAssetsPath, lines[i]);WWW reader1 new WWW(srcfile);while (!reader1.isDone) { }string dstFile Path.Combine(Application.persistentDataPath, lines[i]);//安卓的路径只能是/反斜杠\无效dstFile dstFile.Replace(\\,/);string dir Path.GetDirectoryName(dstFile);if (!Directory.Exists(dir)){Directory.CreateDirectory(dir);Debug.Log(dstFile);}File.WriteAllBytes(dstFile, reader1.bytes);}
}
5.AssetBundle资源需要针对Android单独打包与Windows的不通用。 打包完将资源复制到StreamingAssets下 ROBOCOPY Android ..\Assets\StreamingAssets\Android /E 加载AssetBundle
//存放AssetBundle的根目录名字private static string rootFolder Android;//本地资源路径public string AbPath{ get{string path
#if UNITY_ANDROID !UNITY_EDITORApplication.persistentDataPath /;
#elseApplication.streamingAssetsPath /;
#endifreturn string.Format({0}{1}/, path, rootFolder);}}
AssetBundle assetBundle AssetBundle.LoadFromFile(string.Format({0}{1}, AbPath, rootFolder));
......