/// <summary> /// 卸载bundle /// </summary> /// <param name="bundle">要卸载的bundle</param> internal void UnLoad(ABundle bundle) { if (bundle == null) { throw new ArgumentException($"{nameof(BundleManager)}.{nameof(UnLoad)}() bundle is null."); } //引用-1 bundle.ReduceReference(); //引用为0,直接释放 if (bundle.reference == 0) { if (!bundle.done && bundle is BundleAsync) { BundleAsync bundleAsync = bundle as BundleAsync; if (m_AsyncList.Contains(bundleAsync)) { m_AsyncList.Remove(bundleAsync); } } m_BundleDic.Remove(bundle.url); bundle.UnLoad(); } }
public void LateUpdate() { if (m_NeedUnloadList.Count == 0) { return; } while (m_NeedUnloadList.Count > 0) { ABundle bundle = m_NeedUnloadList.First.Value; m_NeedUnloadList.RemoveFirst(); if (bundle == null) { continue; } m_BundleDic.Remove(bundle.url); if (!bundle.done && bundle is BundleAsync) { BundleAsync bundleAsync = bundle as BundleAsync; if (m_AsyncList.Contains(bundleAsync)) { m_AsyncList.Remove(bundleAsync); } } bundle.UnLoad(); //依赖引用-1 if (bundle.dependencies != null) { for (int i = 0; i < bundle.dependencies.Length; i++) { ABundle temp = bundle.dependencies[i]; UnLoad(temp); } } } }
/// <summary> /// 卸载bundle /// </summary> /// <param name="bundle">要卸载的bundle</param> internal void UnLoad(ABundle bundle) { if (bundle == null) { throw new ArgumentException($"{nameof(BundleManager)}.{nameof(UnLoad)}() bundle is null."); } //引用-1 bundle.ReduceReference(); //引用为0,直接释放 if (bundle.reference == 0) { //严格遵循要加载完了才能释放 if (!bundle.done) { return; } m_BundleDic.Remove(bundle.url); bundle.UnLoad(); } }