public void UnloadUnusedBundle(bool force = false)
        {
            if ((!this._isCurrentLoading && !XSingleton <XResourceLoaderMgr> .singleton.isCurrentLoading) || force)
            {
                List <uint> list = ListPool <uint> .Get();

                list.AddRange(this._loadedAssetBundle.Keys);
                int  num  = 20;
                int  num2 = 0;
                bool flag;
                do
                {
                    flag = false;
                    int num3 = 0;
                    while (num3 < list.Count && !this._isCurrentLoading && num2 < num && ((!this._isCurrentLoading && !XSingleton <XResourceLoaderMgr> .singleton.isCurrentLoading) || force))
                    {
                        uint            key             = list[num3];
                        AssetBundleInfo assetBundleInfo = this._loadedAssetBundle[key];
                        if (assetBundleInfo.isUnused)
                        {
                            flag = true;
                            num2++;
                            this.RemoveBundleInfo(assetBundleInfo);
                            list.RemoveAt(num3);
                            num3--;
                        }
                        num3++;
                    }
                }while (flag && !this._isCurrentLoading && !XSingleton <XResourceLoaderMgr> .singleton.isCurrentLoading && num2 < num);
                ListPool <uint> .Release(list);

                while (this._requestUnloadBundleQueue.Count > 0 && !this._isCurrentLoading && !XSingleton <XResourceLoaderMgr> .singleton.isCurrentLoading && num2 < num)
                {
                    AssetBundleInfo assetBundleInfo2 = this._requestUnloadBundleQueue.Dequeue();
                    if (assetBundleInfo2 != null)
                    {
                        assetBundleInfo2.UnloadBundle();
                        num2++;
                    }
                }
            }
        }
Esempio n. 2
0
        public void AssetBundleLoadCompleteCb(AssetBundleInfo info)
        {
            this.complete = true;
            if (info.mainObject == null)
            {
                XResourceLoaderMgr.LoadErrorLog(this.location);
                this.ReturnNull();
                return;
            }
            if (XSingleton <XResourceLoaderMgr> .singleton.useNewMgr)
            {
                XResourceLoaderMgr.UniteObjectInfo uniteObjectInfo;
                bool objectAsync = XSingleton <XResourceLoaderMgr> .singleton.GetObjectAsync(this.location, this.hash, null, info, this.isSharedRes, out uniteObjectInfo);

                if (uniteObjectInfo != null)
                {
                    int i     = 0;
                    int count = this.loadCbList.Count;
                    while (i < count)
                    {
                        LoadInfo loadInfo = this.loadCbList[i];
                        if (loadInfo.loadCb != null)
                        {
                            UnityEngine.Object @object = XSingleton <XResourceLoaderMgr> .singleton.GetObject(uniteObjectInfo, this.isSharedRes, loadInfo.usePool, objectAsync);

                            loadInfo.loadCb(@object, this.location, this.isSharedRes);
                        }
                        i++;
                    }
                    this.loadCbList.Clear();
                    return;
                }
            }
            else
            {
                XSingleton <XResourceLoaderMgr> .singleton.AddAssetInPool(info.mainObject, this.hash, info);

                int j      = 0;
                int count2 = this.loadCbList.Count;
                while (j < count2)
                {
                    LoadInfo loadInfo2 = this.loadCbList[j];
                    if (loadInfo2.loadCb != null)
                    {
                        if (this.isSharedRes)
                        {
                            this.GetSharedResourceCb(loadInfo2.loadCb, info);
                        }
                        else
                        {
                            UnityEngine.Object obj = null;
                            if (loadInfo2.usePool && XSingleton <XResourceLoaderMgr> .singleton.GetInObjectPool(ref obj, this.hash))
                            {
                                loadInfo2.loadCb(obj, this.location, this.isSharedRes);
                            }
                            else
                            {
                                this.CreateFromPrefabCb(loadInfo2.loadCb, info);
                            }
                        }
                    }
                    j++;
                }
                this.loadCbList.Clear();
            }
        }
 private void OnBundleUnload(AssetBundleInfo abi)
 {
     this.bundleInfo = null;
     this.state      = LoadState.State_None;
 }
 private void OnDepCompleteImm(AssetBundleInfo abi)
 {
     this._currentLoadingDepCount--;
     this.CheckDepCompleteImm();
 }
 internal void RemoveBundleInfo(AssetBundleInfo abi)
 {
     abi.Dispose();
     this._loadedAssetBundle.Remove(abi.bundleName);
 }