PS:首先感谢给我带来帮助信息的各位博主。尊重原创收藏以温故。文末附上原参考链接以及示例工程
更新自:2022-05-13
2:StreamingAssets文件夹
虚拟目录,PC平台读取正常,打包发布后时会被压缩加密,只能进行WWW读取。主要存放二进制文件和如视频文件等
www读取路径如下:
IEnumerator LoadXML()
{
string sPath= "file://"+Application.streamingAssetsPath + "/my.xml";
WWW www = new WWW(sPath);
yield return www;
_result = www.text;//XML表数据
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(www.text);
XmlNodeList nodeList = xmlDoc.SelectSingleNode("gameObjects").ChildNodes;
foreach (XmlElement scene in nodeList)
{
}
}
或:
IEnumerator InstantiateObject()
{
string path = string.Empty;
if (Application.platform == RuntimePlatform.Android) //安卓系统
{
path = "jar:file://" + Application.dataPath + "!/assets/" + "model";
}
else
{
//以下3种方法在window端皆可
//path = "file:///" + Application.dataPath + "/StreamingAssets/model";
//path = Application.dataPath + "/StreamingAssets/model";
path= "file://" + Application.streamingAssetsPath + "/model";
}
UnityEngine.Networking.UnityWebRequest request
=UnityWebRequestAssetBundle.GetAssetBundle(path, 0);
yield return request.SendWebRequest();
}
本文工程:动态加载场景Demo(完善版).zip_免费高速下载|百度网盘-分享无限制
原参考工程:Unity3D_42_XML与JSON导出还原场景.unitypackage_免费高速下载|百度网盘-分享无限制
参考链接:
1:[雨松MOMO] Unity3D研究院之将场景导出XML或JSON或二进制并且解析还原场景(四十二)
http://www.manew.com/thread-21417-1-1.html
2:[雨松MOMO] Unity3D之Android同步方法读取streamingAssets(八十八)
http://www.manew.com/thread-89202-1-1.html
3:Unity3D移动平台动态读取外部文件全解析 Unity3D移动平台动态读取外部文件全解析 - 慕容小匹夫 - 博客园
4: unity Android 打包后读取 xml 文件 登录 - 推酷
5:unity 在移动平台中,文件操作路径详解 (转) unity 在移动平台中,文件操作路径详解 - ☆A希亿 - 博客园
9:Unity3d新网络请求方式UnityWebRequest详解 http://gad.qq.com/article/detail/34139%20target=
如有疑问之处,欢迎指正和探讨。