public override T LoadAsset <T>(string fileName) { string[] files = fileName.Split('/'); fileName = files[files.Length - 1]; BundleInfo info = null; fileMap.TryGetValue(fileName, out info); if (null == info) { return(null); } string path = DataUrl.GetFilePersistentUrl(info.bundleName); bool isPersistentDataPath = System.IO.File.Exists(path); if (!isPersistentDataPath) { path = DataUrl.GetFileStreamingUrl(info.bundleName); if (!System.IO.File.Exists(path)) { return(null); } } AssetBundle asset = null; loadedBundleDic.TryGetValue(path, out asset); if (asset == null) { asset = AssetBundle.LoadFromFile(path); loadedBundleDic.Add(path, asset); } if (asset == null) { return(null); } if (null != info.dependencies) { foreach (string dep in info.dependencies) { AssetBundle _asset = null; string dependPath = isPersistentDataPath ? DataUrl.GetFilePersistentUrl(dep) : DataUrl.GetFileStreamingUrl(dep); if (IsHadLoadDeps(dependPath)) { continue; } _asset = AssetBundle.LoadFromFile(dependPath); depsDic.Add(dependPath, _asset); } } return(asset.LoadAsset <T>(info.assetName)); }
string GetScenePath(string fileName) { string path = DataUrl.GetFilePersistentUrl(fileName) + ".unity3d"; // string path= DataUrl.LOCAL_URL_PREFIX + Application.dataPath + "/StreamingAssets/" + "Scene_Main" + ".unity3d"; //读取Per目录的时候不需要加prefix,但是读取Streaming目录时候需加上prefix bool isPersistentDataPath = System.IO.File.Exists(path); if (!isPersistentDataPath) { path = DataUrl.GetFileStreamingUrl(fileName) + ".unity3d"; return(path); } return(DataUrl.LOCAL_URL_PREFIX + path); }
//void LoadAtlas() //{ // string[] atlsPaths = { "MainAtlas.unity3d", "PlayingAtlas.unity3d", "cardAtlas.unity3d" }; // for (int i = 0; i < atlsPaths.Length; i++) // { // AssetBundle asset = null; // string path = atlsPaths[i]; // //bool isPersistentDataPath = System.IO.File.Exists(path); // //if (!isPersistentDataPath) // //{ // // path = DataUrl.GetFileStreamingUrl(info.bundleName); // // if (!System.IO.File.Exists(path)) // // AssetBundle asset = null; // loadedBundleDic.TryGetValue(path, out asset); // if (asset == null) // { // path =DataUrl.GetFilePersistentUrl(atlsPaths[i]); // asset = AssetBundle.LoadFromFile(path); // if(asset == null) // { // path = DataUrl.GetFileStreamingUrl(atlsPaths[i]); // asset = AssetBundle.LoadFromFile(path); // if(asset == null) // { // } // else // { // loadedBundleDic.Add(atlsPaths[i], asset); // } // } // else // { // loadedBundleDic.Add(atlsPaths[i], asset); // } // } // else // { // loadedBundleDic.Add(atlsPaths[i], asset); // } // } //} /// <summary> /// StreamingAssets.xml 初始化 /// </summary> void InitFileMap() { string fileName = GlobalData.mStreamingAssetsXml; string path = DataUrl.GetFilePersistentUrl(fileName); bool isPersistentPath = System.IO.File.Exists(path); Debug.Log("isPersistentPath:" + isPersistentPath.ToString()); if (!isPersistentPath) { path = DataUrl.GetFileStreamingUrl(fileName); //安卓读取该目录有错误,所以,只能读取Per目录中的数据。 if (!System.IO.File.Exists(path)) { //Debug.LogError(fileName + "文件加载失败..."); return; } } XmlDocument doc = new XmlDocument(); doc.Load(path); Debug.Log(fileName + doc.Name); XmlNodeList nodeList = doc.SelectSingleNode("files").ChildNodes; foreach (XmlElement xe in nodeList) { BundleInfo info = new BundleInfo(); string _fileName = xe.SelectSingleNode("fileName").InnerText.Replace("\\", "/"); info.assetName = xe.SelectSingleNode("assetName").InnerText.Replace("\\", "/"); info.bundleName = xe.SelectSingleNode("bundleName").InnerText.Replace("\\", "/"); XmlNode deps = xe.SelectSingleNode("deps"); if (null != deps) { XmlNodeList depList = deps.ChildNodes; foreach (XmlElement _xe in depList) { info.AddDependence(_xe.InnerText.Replace("\\", "/")); } } string[] strs = _fileName.Substring("Assets/Resources/".Length).Split('.'); string strValue = strs[0]; fileMap.Add(strValue, info); } }