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 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); }