public static void RemoveUnusedLoader(LoadHelper helper) { if (dicDownloader.ContainsKey(helper.OriginalUrl)) { dicDownloader.Remove(helper.OriginalUrl); } }
IEnumerator DownAsset(object parm) { LoadHelper helper = parm as LoadHelper; WWW www = new WWW("file://" + helper.Url); while (true) { if (www.error != null) { Debug.LogError("ImgDownloader DownAsset error:" + helper.Url + www.error); break; } if (www.isDone) { LoadedData data = new LoadedData(www.texture, www.url, helper.OriginalUrl); helper.CompleteHandler(data); if (www != null) { www.Dispose(); GameObject.Destroy(this.gameObject); } break; } else { yield return(www); } } }
private IEnumerator ReDown(LoadHelper loadHelper) { if (this.data == null) { while (true) { if (this.data != null) { try { loadHelper.CompleteHandler(this.data); } catch (System.Exception ex) { LoadedData loadedData = this.data as LoadedData; Debug.LogError("加载资源" + loadedData.FilePath + "错误:" + ex.ToString()); } break; } else { yield return(null); } } } else { loadHelper.CompleteHandler(data); } }
public void LoadXML(string url, LoadHandler completeHandler, XMLResolverHandler resolverHandler) { LoadHelper loadHelper = new LoadHelper(url, completeHandler, this.ErrorHandler, this.ProgressHandler, resolverHandler); IDownloader downloader = FactoryDownloader.GetDownloader(loadHelper); downloader.StartDown(loadHelper); }
IEnumerator DownAsset(object parm) { this.isDownling = true; LoadHelper helper = parm as LoadHelper; WWW www = new WWW("file://" + helper.Url); while (true) { if (www.isDone) { this.isDownling = false; if (www.assetBundle != null) { this.objs = www.assetBundle.LoadAllAssets(); } this.data = new LoadedData(this.objs, www.url, helper.OriginalUrl); helper.CompleteHandler(this.data); if (www.assetBundle != null) { www.assetBundle.Unload(false); } break; } else { yield return(www); } } }
public static IDownloader GetDownloader(LoadHelper helper) { IDownloader loader = null; if (dicDownloader.ContainsKey(helper.OriginalUrl)) { loader = dicDownloader[helper.OriginalUrl]; } else if (dicSlDownloader.ContainsKey(helper.OriginalUrl)) { loader = dicSlDownloader[helper.OriginalUrl]; } else { GameObject go = null; switch (helper.ExtensionName) { case ".xml": go = new GameObject(); Object.DontDestroyOnLoad(go); loader = go.AddComponent <XMLDownloader>(); break; case ".json": loader = new JsonDownloader(); break; case ".txt": loader = new TxtDownloader(); break; case ".png": case ".jpg": go = new GameObject("imgLoadGO"); Object.DontDestroyOnLoad(go); loader = go.AddComponent <ImgDownloader>(); break; case ".sl": go = new GameObject(); loader = go.AddComponent <SceneLibraryDownloader>(); if (!dicSlDownloader.ContainsKey(helper.OriginalUrl)) { dicSlDownloader.Add(helper.OriginalUrl, loader); } break; default: go = new GameObject(); loader = go.AddComponent <UnityDownloader>(); if (!dicDownloader.ContainsKey(helper.OriginalUrl)) { dicDownloader.Add(helper.OriginalUrl, loader); } break; } } return(loader); }
IEnumerator DownAsset(object parm) { this.isDownling = true; LoadHelper helper = parm as LoadHelper; WWW www = new WWW("file://" + helper.Url); while (true) { if (www.error != null) { Debug.LogError("UnityDownloader DownAsset error:" + helper.Url + www.error); break; } if (www.isDone) { try { this.data = new LoadedData(www, www.url, helper.OriginalUrl); this.isDownling = false; if (helper.IsPublicRes && www.assetBundle != null) { this.objs = www.assetBundle.LoadAllAssets(); //if(GlobalDef.IsDev) //{ // Debug.Log("Load Asset:" + helper.Url); // foreach (object temp in objs) // { // Debug.Log("object in Asset in LoadedData:" + temp.ToString()); // } // Debug.Log("AssetBundle End."); //} } helper.CompleteHandler(this.data); } catch (System.Exception ex) { Debug.LogError("加载资源" + helper.Url + "错误:" + ex.ToString()); } finally { //if (!helper.IsPublicRes) //{ // if (www.assetBundle != null) // { // www.assetBundle.Unload(false); // } // www.Dispose(); // GameObject.Destroy(this.gameObject); //} } break; } else { yield return(www); } } }
public void StartDown(LoadHelper loadHelper) { if (this.data == null && !this.isDownling) { this.name = loadHelper.OriginalUrl; this.StartCoroutine("DownAsset", loadHelper); } else { this.StartCoroutine("ReDown", loadHelper); } }
public void LoadRes(string url, LoadHandler completeHandler, LoadHandler errorHandler, LoadHandler progressHandler) { LoadHelper loadHelper = new LoadHelper(url, completeHandler, errorHandler, progressHandler); if (loadHelper.ExtensionName == ".xml" && loadHelper.XMLResolver == null) { Debug.LogError("加载xml文件 请使用 LoadXML方法"); } IDownloader downloader = FactoryDownloader.GetDownloader(loadHelper); downloader.StartDown(loadHelper); }
public void StartDown(LoadHelper loadHelper) { string xmlText = IOHelper.OpenText(loadHelper.Url); //if (needDecrupt) //{ // xmlText = AESManager.AESDecrypt(xmlText); //} if (loadHelper.CompleteHandler != null) { loadHelper.CompleteHandler(new LoadedData(xmlText, loadHelper.Url, loadHelper.OriginalUrl)); } }
private IEnumerator ReDown(LoadHelper loadHelper) { if (this.data == null) { while (true) { if (this.data != null) { loadHelper.CompleteHandler(this.data); break; } else { yield return(null); } } } else { loadHelper.CompleteHandler(data); } }
public void StartDown(LoadHelper loadHelper) { this.name = loadHelper.OriginalUrl; this.StartCoroutine("DownAsset", loadHelper); }
IEnumerator DownXML(object parm) { LoadHelper loadHelper = parm as LoadHelper; string xmlText = IOHelper.OpenText(loadHelper.Url); //if (needDecrupt) //{ // xmlText = AESManager.AESDecrypt(xmlText); //} yield return(null); Regex regex = new Regex("<object .*/>"); MatchCollection matchCollection = regex.Matches(xmlText); string pattern = "([A-Za-z0-9_-]*?=\".*?\"){1}"; int totalRow = matchCollection.Count; yield return(null); for (int i = 0; i < totalRow; i++) { MatchCollection mc = Regex.Matches(matchCollection[i].Value, pattern, RegexOptions.IgnoreCase); Dictionary <string, string> dic = new Dictionary <string, string>(); if (mc.Count > 0) { for (int j = 0; j < mc.Count; j++) { string str = mc[j].Value.Replace("\"", ""); string[] keyValue = str.Split('='); string key = keyValue[0]; string value = keyValue[1]; if (dic.ContainsKey(key)) { string error = string.Format("{0} has exist key:{1},Row index is:{2}", loadHelper.FileName, key, j); Debug.LogError(error); } else { dic.Add(key, value); } } } if (loadHelper.XMLResolver != null) { try { loadHelper.XMLResolver(dic); } catch (Exception ex) { string info = string.Empty; foreach (KeyValuePair <string, string> keyValue in dic) { info += keyValue.Key + ":" + keyValue.Value + " "; } string error = string.Format("Resolver {0}.xml wrong:row index {1}---{2} exception:{3}", loadHelper.FileName, i, info, ex.ToString()); Debug.LogError(error); } } else { Debug.LogError("Resolver" + loadHelper.FileName + ".xml error:XMLResolver is null"); } } yield return(null); if (loadHelper.CompleteHandler != null) { loadHelper.CompleteHandler(new LoadedData(xmlText, loadHelper.Url, loadHelper.OriginalUrl)); GameObject.Destroy(this.gameObject); } }
public void StartDown(LoadHelper loadHelper) { this.name = loadHelper.Url; StartCoroutine("DownXML", loadHelper); }