public AssetBundleReference LoadAssetBundleSync(string path, string tag, bool standalone = true) { if (string.IsNullOrEmpty(path)) { return(null); } AssetBundleReference abr = null; if (m_AssetBundles.ContainsKey(path)) { #if ASSETMANAGER_LOG Debug.LogFormat("LoadAssetBundleSync bundle is loaded {0},{1}", path, Time.frameCount); #endif abr = m_AssetBundles[path]; //refresh abr.AddTag(tag); if (standalone) { abr.Chain(); } } else { if (m_LoadingAssetBundleLoaders.ContainsKey(path)) { Debug.LogErrorFormat("LoadAssetBundleSync async loader is active {0},{1}", path, Time.frameCount); //TODO Stop async return(null); } else { #if ASSETMANAGER_LOG Debug.LogFormat("LoadAssetBundleSync create new loader {0},{1}", path, Time.frameCount); #endif AssetBundleSyncLoader loader = m_LoaderManager.CreateAssetBundleSyncLoader(path); if (loader != null) { loader.state = Loader.State.Inited; loader.Start(); abr = loader.result; OnAssetBundleLoaded(loader); } } } return(abr); }
void OnAssetBundleLoaded(AssetBundleLoader loader) { AssetBundleReference abr = loader.result; if (abr != null) { m_AssetBundles[abr.name] = abr; if (loader.standalone) { abr.Chain(); } else { abr.inChain = false; } if (m_LoadingAssetBundleLoaders.ContainsKey(abr.name)) { if (loader.autoRelease) { if (loader is AssetBundleAsyncLoader) { LoaderPool.AssetBundleAsyncLoader.Release(loader as AssetBundleAsyncLoader); } else { loader.Clean(); } } m_LoadingAssetBundleLoaders.Remove(abr.name); } abr.onDispose += OnAssetBundleDispose; } }
public AssetBundleLoader LoadAssetBundle(string path, string tag, bool standalone, Action <AssetBundleReference> completeHandle = null) { AssetBundleLoader loader = null; if (string.IsNullOrEmpty(path)) { return(loader); } if (m_AssetBundles.ContainsKey(path)) { #if ASSETMANAGER_LOG Debug.Log("LoadAssetBundle asset bundle is loaded " + path + "," + Time.frameCount); #endif //asset bundle is loaded AssetBundleReference abr = m_AssetBundles[path]; //refresh abr.AddTag(tag); if (standalone) { abr.Chain(); } loader = m_LoaderManager.CreateAssetBundleAsyncLoader(path); loader.forceDone = true; loader.result = abr; //call complete callback if (completeHandle != null) { completeHandle(abr); } } else { if (m_LoadingAssetBundleLoaders.ContainsKey(path)) { #if ASSETMANAGER_LOG Debug.Log("LoadAssetBundle using loading loader " + path + "," + Time.frameCount); #endif loader = m_LoadingAssetBundleLoaders[path]; } else { #if ASSETMANAGER_LOG Debug.Log("LoadAssetBundle create new loader " + path + "," + Time.frameCount); #endif loader = m_LoaderManager.CreateAssetBundleAsyncLoader(path); m_LoadingAssetBundleLoaders[path] = loader; } loader.AddParamTag(tag); if (loader.standalone == false && standalone) { loader.standalone = true; } if (completeHandle != null) { loader.onComplete += completeHandle; } if (loader.state == Loader.State.Idle) { loader.onAfterComplete += OnAssetBundleLoaded; loader.state = Loader.State.Inited; m_LoaderManager.ActiveLoader(loader); } } return(loader); }