protected void OnBundleRequestComplete(Request request) { #if ASSETMANAGER_LOG Debug.Log("BundleRequestComplete " + info.fullName + "," + Time.frameCount); #endif if (!request.haveError) { state = State.Loaded; if (onAssetBundleLoaded != null) { onAssetBundleLoaded(this); } //Create result m_Result = new AssetBundleReference(request.assetBundle, info != null ? info.fullName : ""); m_Result.AddTags(paramTags); if (m_DependenciesIsDone) //|| (m_DependenciesIsLoaded && DeepCheckDependenciesComplete())) { m_Result.AddDependencies(m_Dependencies); Complete(); } } else { Debug.LogError("AssetBundleLoader fail load " + info.fullName); Error(); } }
public void UnloadUnusedBundles(string tag) { if (m_AssetBundles.Count == 0) { return; } AssetBundleReference abr = null; Stack <string> checkQueue = StackPool <string> .Get(); HashSet <string> checkings = HashSetPool <string> .Get(); Action <string> checkFun = (key) => { abr = m_AssetBundles[key]; checkings.Remove(key); if (abr.isUnused()) { //check dependencies if (abr.dependencies != null && abr.dependencies.Count > 0) { foreach (AssetBundleReference sub in abr.dependencies) { //只有同样tag和空tag的ref才需要重新检查。 if (sub.inChain && (sub.tagCount == 0 || sub.HaveTag(tag)) && !checkings.Contains(sub.name)) { checkQueue.Push(sub.name); } } } abr.Dispose(); m_AssetBundles.Remove(key); } }; foreach (string key in m_AssetBundles.Keys) { abr = m_AssetBundles[key]; if (abr.HaveTag(tag) && abr.inChain) { checkQueue.Push(key); checkings.Add(key); } } //recheck unused asset bundle while (checkQueue.Count > 0) { checkFun(checkQueue.Pop()); } StackPool <string> .Release(checkQueue); HashSetPool <string> .Release(checkings); }
/// <summary> /// /// </summary> /// <param name="assetBundleName"></param> public void UnusedAssetBundle(string assetBundleName) { if (m_AssetBundles.ContainsKey(assetBundleName)) { AssetBundleReference abr = m_AssetBundles[assetBundleName]; abr.UnChain(); } }
void UnusedAllAssetBundles() { foreach (var iter in m_AssetBundles) { AssetBundleReference abr = iter.Value; abr.UnChain(); } }
public override void Clean() { onComplete = null; onBeforeComplete = null; onAfterComplete = null; info = null; type = null; assetBundleReference = null; m_Result = null; base.Clean(); }
void LoadDependencies() { string[] dependencies = info.dependencies; for (int i = 0, l = dependencies.Length; i < l; ++i) { string dep = dependencies[i]; AssetBundleReference abr = assetManager.LoadAssetBundleSync(dep, null, false); if (abr != null) { m_Dependencies.Add(abr); } } }
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); }
protected void OnDependencyComplete(AssetBundleReference abr) { m_Dependencies.Add(abr); #if ASSETMANAGER_LOG Debug.Log("DependencyComplete " + info.fullName + "=>" + abr.name + "," + Time.frameCount + ",(" + m_WaitDependencyCompleteCount + ")"); #endif if (--m_WaitDependencyCompleteCount == 0) { m_DependenciesIsDone = true; if (m_State == State.Loaded && m_Result != null) { m_Result.AddDependencies(m_Dependencies); Complete(); } } }
public override void Clean() { onComplete = null; onBeforeComplete = null; onAfterComplete = null; m_Result = null; info = null; if (m_Dependencies != null) { m_Dependencies.Clear(); } base.Clean(); }
protected void RemoveAssetBundlesTag(string tag) { if (m_AssetBundles.Count == 0) { return; } AssetBundleReference abr = null; var iter = m_AssetBundles.GetEnumerator(); while (iter.MoveNext()) { abr = iter.Current.Value; if (abr.inChain && abr.HaveTag(tag)) { abr.RemoveTag(tag); } } }
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; } }
void OnAssetBundleDispose(AssetBundleReference abr) { m_AssetBundles.Remove(abr.name); }
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); }