public static String LoadText(String fileName) { try { if (SystemSwitch.ReleaseMode) { return(FileAccessManager.LoadText(fileName)); } else { if (SystemConfig.IsEditor) { return(Utils.LoadFile(String.Concat(SystemConfig.DataPath, "/Resources/", fileName))); } else { return(Utils.LoadResource(fileName)); } } } catch (Exception ex) { LoggerHelper.Except(ex); return(""); } }
private static void LoadCreateRequestAssets(List <Resource> list, MonoBehaviour mono, Action loaded) { //var resources = new List<Resource>(); //foreach (var res in list) //{ // if (res.IsDone || res.IsLoading) // continue; // var path = WithSuffix(res.RelativePath); // var fileName = String.Concat(SystemConfig.ResourceFolder, path); // res.fileData = Utils.LoadByteFile(fileName);//FileAccessManager.LoadBytes(path); // if (res.fileData != null && res.fileData.Length != 0) // resources.Add(res); // else // Debug.LogError("Load file failure: " + path); //} //mono.StartCoroutine(DoLoadCreateRequestAssets(resources, loaded)); var resources = new List <Resource>(); foreach (var res in list) { if (res.IsDone) { continue; } resources.Add(res); } Action action = () => { var loadedResources = new List <Resource>(); foreach (var res in resources) { var path = WithSuffix(res.RelativePath); //var fileName = String.Concat(SystemConfig.ResourceFolder, path); //res.fileData = Utils.LoadByteFile(fileName);//FileAccessManager.LoadBytes(path); res.fileData = FileAccessManager.LoadBytes(path); if (res.fileData != null && res.fileData.Length != 0) { loadedResources.Add(res); } else { Debug.LogError("Load file failure: " + path); } } TimerHeap.AddTimer(0, 0, () => mono.StartCoroutine(DoLoadCreateRequestAssets(loadedResources, loaded))); }; #if UNITY_IPHONE action(); #else action.BeginInvoke(null, null); #endif }
public static string LoadText(string fileName) { try { return(SystemSwitch.ReleaseMode ? FileAccessManager.LoadText(fileName) : Utils.LoadResource(fileName)); } catch (Exception exception) { LoggerHelper.Except(exception, null); return(""); } }
public static string LoadText(string fileName) { try { if (SystemSwitch.ReleaseMode) { return(FileAccessManager.LoadText(fileName)); } if (SystemConfig.IsEditor) { return(Utils.LoadFile(SystemConfig.DataPath + "/Resources/" + fileName)); } return(Utils.LoadResource(fileName)); } catch (Exception exception) { LoggerHelper.Except(exception, null); return(""); } }
public static void LoadMetaOfResource(string path, Action cb = null) { //meta现已全部拷到sd卡 //if (!File.Exists(Path.Combine(SystemConfig.ResourceFolder, path))) //{ // Driver.Instance.StartCoroutine(Driver.Instance.LoadWWWText(Utils.GetStreamPath(path), // (xmlText) => // { // var xml = XMLParser.LoadXML(xmlText); // if (xml == null) // { // if (cb != null) // { // cb(); // } // return; // } // foreach (SecurityElement item in xml.Children) // { // var meta = new ResourceMetaData(); // meta.RelativePath = item.Attribute("path"); // meta.MD5 = item.Attribute("md5"); // var dependencies = item.Children; // if (dependencies != null && dependencies.Count > 0) // { // meta.Dependencies = new List<string>(); // foreach (SecurityElement dependency in dependencies) // { // meta.Dependencies.Add(dependency.Attribute("path")); // } // } // metaOfResource[meta.RelativePath] = meta; // } // if (cb != null) // { // cb(); // } // })); //} //else //{ var xml = XMLParser.LoadXML(FileAccessManager.LoadText(path)); if (xml == null) { if (cb != null) { cb(); } return; } for (int i = 0; i < xml.Children.Count; i++) { SecurityElement item = xml.Children[i] as SecurityElement; var meta = new ResourceMetaData(); meta.RelativePath = item.Attribute("path"); meta.MD5 = item.Attribute("md5"); var dependencies = item.Children; if (dependencies != null && dependencies.Count > 0) { meta.Dependencies = new List <string>(); foreach (SecurityElement dependency in dependencies) { meta.Dependencies.Add(dependency.Attribute("path")); } } metaOfResource[meta.RelativePath] = meta; } if (cb != null) { cb(); } //} }
public static void LoadMetaOfMeta(Action cb, Action <int, int> process) { metaOfMeta = new Dictionary <string, string>(); //meta现已全部拷到sd卡 //if (!File.Exists(Path.Combine(SystemConfig.ResourceFolder, ResourceManager.MetaFileName))) //{ // Driver.Instance.StartCoroutine(Driver.Instance.LoadWWWText(Utils.GetStreamPath(ResourceManager.MetaFileName), // (xmlText) => // { // var xml = XMLParser.LoadXML(xmlText); // if (xml == null) // { // if (cb != null) // { // cb(); // } // return; // } // foreach (SecurityElement item in xml.Children) // { // metaOfMeta[item.Attribute("path")] = item.Attribute("md5"); // } // RecursiveLoadMetaOfResource(metaOfMeta.Keys.ToList(), 0, metaOfMeta.Keys.Count, () => // { // AssetCacheMgr.AssetMgr.SetPathMap(); // if (cb != null) // { // cb(); // } // }, process); // })); //} //else //{ Action action = () => { var xml = XMLParser.LoadXML(FileAccessManager.LoadText(ResourceManager.MetaFileName)); if (xml == null) { if (cb != null) { #if UNITY_ANDROID Driver.Invoke(cb); #elif UNITY_IPHONE Driver.Invoke(cb); #else Driver.Invoke(cb); #endif } return; } for (int i = 0; i < xml.Children.Count; i++) { SecurityElement item = xml.Children[i] as SecurityElement; metaOfMeta[item.Attribute("path")] = item.Attribute("md5"); } RecursiveLoadMetaOfResource(metaOfMeta.Keys.ToList(), 0, metaOfMeta.Keys.Count, () => { AssetCacheMgr.AssetMgr.SetPathMap(); if (cb != null) { #if UNITY_ANDROID Driver.Invoke(cb); #elif UNITY_IPHONE Driver.Invoke(cb); #else Driver.Invoke(cb); #endif } }, process); }; action.BeginInvoke(null, null); //} }
public static IEnumerator LoadResource(Resource resource, Action loaded) { if (resource.IsDone) { if (loaded != null) { loaded(); } yield break; } var list = new List <Resource>(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); list.AddRange(GetDeepDependencies(resource.RelativePath)); list.Add(resource); list = list.Distinct().ToList(); sw.Stop(); //Debug.Log("sw.ElapsedMilliseconds: " + sw.ElapsedMilliseconds); int index = 0; //Debug.Log("list.Count: " + list.Count); while (index < list.Count) { var res = list[index]; index++; if (res.IsDone) { yield return(null); } else { var path = WithSuffix(res.RelativePath); if (SystemSwitch.UseFileSystem) { //var fileName = String.Concat(SystemConfig.ResourceFolder, path); //var resourceData = Utils.LoadByteFile(fileName); var resourceData = FileAccessManager.LoadBytes(path); var cr = AssetBundle.LoadFromMemoryAsync(resourceData); yield return(cr); res.createRequest = cr; if (res.createRequest.assetBundle != null) { res.createRequest.assetBundle.LoadAllAssets(); } } else { var www = new WWW(String.Concat(SystemConfig.ASSET_FILE_HEAD, SystemConfig.ResourceFolder, path)); //Debug.Log(res.RelativePath); yield return(www); res.www = www; if (res.www.assetBundle != null) { res.www.assetBundle.LoadAllAssets(); } } } } if (loaded != null) { loaded(); } }
public static byte[] LoadBytes(string fileName) { return(SystemSwitch.ReleaseMode ? FileAccessManager.LoadBytes(fileName) : Utils.LoadByteResource(fileName)); }