IEnumerator LoadAsync(string path) { if (request != null) { ResMgr.Log(Tag, "LoadAsync", "this should never happen tooo !!"); } if (!File.Exists(path)) { ResMgr.Log(Tag, "LoadAsync", "async path is not exist"); State = AbBundleState.error; yield break; } request = AssetBundle.LoadFromFileAsync(path); yield return(request); if (request.isDone) { this.Log("AbAsyncLoader LoadAsync succ==>" + path); Bundle = request.assetBundle; State = AbBundleState.success; AbMgr.GetInstance().OnAbAsyncDownloadOver(m_Ab_Name.GetHashCode()); } else { State = AbBundleState.error; this.Log("async big problem"); } }
private void LoadPageCallback(UIBase ub, int uiid) { if (ub != null) { if (ub.IsNeedMask) { if (!m_bgMask.gameObject.activeInHierarchy) { m_bgMask.Show(); } m_bgMask.transform.SetSiblingIndex(-2); } ub.transform.SetAsLastSibling(); if (null != m_curPage) { m_curPage.Close(); } m_curPage = ub; ResMgr.Log(Tag, "LoadCallback", "load ui succ " + ub.GetType().ToString()); } else { ResMgr.LogError(Tag, "LoadCallback", "load ui fail"); } }
public void AsyncLoad(string path, Action <AssetBundle> callback, bool isdepend = false) { if (m_manifest == null) { ResMgr.Log(Tag, "AsyncLoad", "manifest is null"); return; } string abname; if (isdepend) { abname = path; } else { abname = XGamePath.Path2ResName(path); } int hash = abname.GetHashCode(); AbAbstractLoader loader = null; if (m_Ab_Dic.TryGetValue(hash, out loader)) { if (callback != null) { callback(loader.Bundle); } return; } string[] depends = AbMgr.GetInstance().GetDepends(abname); for (int i = 0; i < depends.Length; i++) { ResMgr.Log(Tag, "AsyncLoad|depends", depends[i]); int hash2 = depends[i].GetHashCode(); AbAbstractLoader loader2 = null; if (m_Ab_Dic.TryGetValue(hash2, out loader2)) { continue; } if (m_loading_Dic.ContainsKey(hash2)) { AbAsyncLoader asyncloader = m_loading_Dic[hash2] as AbAsyncLoader; asyncloader.request.priority++; continue; } AbMgr.GetInstance().AsyncLoad(depends[i], null, true); } loader = new AbAsyncLoader(path, abname, callback); path = XGamePath.GetStreamingAbPath(abname); loader.LoadAsset(path); m_loading_Dic.Add(hash, loader as AbAsyncLoader); }
public IEnumerator Init() { ResMgr.Log(Tag, "Init", "Start Async Init"); string path = XGamePath.GetStreamingAbPath(m_manifest_name); ResMgr.Log(Tag, "Init", "==>" + path); if (File.Exists(path)) { //同步加载 //FileStream fs = File.Open(path, FileMode.Open); //m_manifest_ab = AssetBundle.LoadFromStream(fs); //m_manifest = m_manifest_ab.LoadAsset<AssetBundleManifest>("AssetBundleManifest"); //if (m_Ab_Dic.Count > 0) //{ // Debug.LogError("不应该发生的事情发生了"); //} //m_Ab_Dic.Clear(); //loader = new AbSyncLoader(); //异步加载 AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(path); yield return(request); if (request.isDone) { m_manifest = request.assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); if (m_Ab_Dic.Count > 0) { ResMgr.LogError(Tag, "Init", "this should never happen !!!!"); } //string[] depends = m_manifest.GetAllAssetBundles(); //foreach (var item in depends) //{ // Debug.Log("depends log ==>" + item); //} m_Ab_Dic.Clear(); ResMgr.Log(Tag, "Init", "load manifest success"); } else { ResMgr.Log(Tag, "Init", "load manifest fail"); } } else { ResMgr.Log(Tag, "Init", "manifest not exist"); } }
private void ShowUIAsync(int uiid, Action <UIBase, int> callback = null, params object[] argc) { //System.Diagnostics.Stopwatch wa = new System.Diagnostics.Stopwatch(); //wa.Reset(); //wa.Start(); ResMgr.Log(Tag, "ShowUIAsync", "==>" + uiid); UIBase ub = _ins.m_uicache[uiid]; if (ub == null) { Action <GameObject> cb = (go) => { if (m_uiRoot == null) { Debug.Log("muiRoot is null"); } go.transform.SetParent(m_uiRoot.transform, false); go.transform.localPosition = Vector3.zero; go.transform.localScale = Vector3.one; ub = go.GetComponent <UIBase>(); _ins.m_uicache[uiid] = ub; if (callback != null) { callback(ub, uiid); } }; LoadUIAsync(uiid, cb); } else { ub.gameObject.SetActive(true); if (ub.IsNeedMask) { if (!m_bgMask.gameObject.activeInHierarchy) { m_bgMask.Show(); } m_bgMask.transform.SetSiblingIndex(-2); } ub.transform.SetAsLastSibling(); if (callback != null) { callback(ub, uiid); } //Debug.Log("2:"+wa.ElapsedMilliseconds); } }
private void ShowUIAsync_Tips(int uiid, Action <UIBase, int> callback = null, params object[] argv) { ResMgr.Log(Tag, "ShowUIAsync", "==>" + uiid); UITips ub = (UITips)_ins.m_uicache[uiid]; if (ub == null) { Action <GameObject> cb = (go) => { if (m_uiRoot == null) { Debug.Log("muiRoot is null"); } go.transform.SetParent(m_uiRoot.transform, false); go.transform.localPosition = Vector3.zero; go.transform.localScale = Vector3.one; ub = go.GetComponent <UITips>(); ub.argv = argv; ub.OnShowTips(); _ins.m_uicache[uiid] = ub; if (callback != null) { callback(ub, uiid); } }; LoadUIAsync(uiid, cb); } else { ub.argv = argv; ub.gameObject.SetActive(true); ub.OnShowTips(); if (ub.IsNeedMask) { if (!m_bgMask.gameObject.activeInHierarchy) { m_bgMask.Show(); } m_bgMask.transform.SetSiblingIndex(-2); } ub.transform.SetAsLastSibling(); if (callback != null) { callback(ub, uiid); } } }
private void LoadWindCallback(UIBase ub, int uiid) { if (ub != null) { if (ub.IsNeedMask) { if (!m_bgMask.gameObject.activeInHierarchy) { m_bgMask.Show(); } m_bgMask.transform.SetSiblingIndex(-2); } ub.transform.SetAsLastSibling(); Push(uiid); ResMgr.Log("UIMgr", "LoadCallback", "load ui succ " + ub.GetType().ToString()); } else { ResMgr.LogError("UIMgr", "LoadCallback", "load ui fail"); } }
public override void LoadAsset(string path) { ResMgr.Log(Tag, "LoadAsset", path); if (File.Exists(path)) { AssetBundle tempbundle = AssetBundle.LoadFromFile(path); if (tempbundle != null) { State = AbBundleState.success; Bundle = tempbundle; } else { State = AbBundleState.error; } } else { this.Log("sync path is not exist ==>" + path); State = AbBundleState.error; } }
public AssetBundle SyncLoad(string path, bool isdepend = false) { if (m_manifest == null) { return(null); } string abname; if (isdepend) { abname = path; } else { abname = XGamePath.Path2ResName(path); } string fullpath = XGamePath.GetStreamingAbPath(abname); int hash = abname.GetHashCode();//path.GetHashCode(); string[] depends = AbMgr.GetInstance().GetDepends(abname); for (int i = 0; i < depends.Length; i++) { ResMgr.Log(Tag, "SyncLoad|depends", depends[i]); int hash2 = depends[i].GetHashCode(); AbAbstractLoader loader2 = null; if (m_Ab_Dic.TryGetValue(hash2, out loader2)) { continue; } if (m_loading_Dic.ContainsKey(hash2)) { AbAsyncLoader asyncloader = m_loading_Dic[hash2] as AbAsyncLoader; asyncloader.request.priority++; continue; } AbMgr.GetInstance().SyncLoad(depends[i], true); } AbAbstractLoader loader; if (m_Ab_Dic.TryGetValue(hash, out loader)) { switch (loader.State) { case AbBundleState.success: return(loader.Bundle); case AbBundleState.loading: if (!loader.isSync) { //todo 转同步加载 } break; case AbBundleState.none: default: break; } return(loader.Bundle); } loader = new AbSyncLoader(fullpath, abname); loader.LoadAsset(fullpath); m_Ab_Dic.Add(hash, loader); return(m_Ab_Dic[hash].Bundle); }