Beispiel #1
0
        public void UnLoadUnUsed(bool force)
        {
            int LimitUnLoadCnt = 10;

            if (force)
            {
                LimitUnLoadCnt = 65536;
            }

            var keys = new List <string>(this.RefCaches.Keys);

            for (int i = 0; i < keys.Count; ++i)
            {
                if (i < LimitUnLoadCnt)
                {
                    string     key    = keys[i];
                    IBundleRef bundle = this.RefCaches[key];
                    if (bundle == null || (bundle.InstanceRefCount == 0 && bundle.SelfRefCount == 0))
                    {
                        bundle.UnLoad(true);
                    }
                }
                else
                {
                    break;
                }
            }
        }
Beispiel #2
0
        private void LoadDone(bool ret, AssetBundleResult result)
        {
            if (ret)
            {
                bundle = result.MainObject;
                if (bundle == null)
                {
                    throw new FrameWorkResMissingException(string.Format("Missing {0}", result.LoadPath));
                }

                if (SprKeys == null)
                {
                    SprKeys = new List <string>(bundle.GetAllAssetNames());
                }
                //else
                //{
                //    SprKeys.Clear();
                //    SprKeys.AddRange(bundle.GetAllAssetNames());
                //}

                while (this.imageLoaders.Count > 0)
                {
                    KeyValuePair <string, Image> kv = this.imageLoaders.Dequeue();
                    AfterDone(kv.Value, kv.Key);
                }
            }

            if (cacheCbk != null)
            {
                cacheCbk(ret, this.bundle);
                cacheCbk = null;
            }
        }
Beispiel #3
0
        private IBundleRef _LoadBundle(BundlePkgInfo pkginfo)
        {
            IBundleRef bundle = this.LoadFullAssetToMem(pkginfo);

            this.AddDepends(pkginfo, bundle);
            return(bundle);
        }
        protected void AddDepends(BundlePkgInfo pkginfo, IBundleRef bundle)
        {
            if (!isABMode)
            {
                return;
            }

            if (bundle != null)
            {
                for (int i = 0; i < pkginfo.Depends.Length; ++i)
                {
                    IBundleRef depbund = ResBundleMgr.mIns.Cache.TryGetValue(pkginfo.Depends[i]);
                    if (depbund != null)
                    {
                        bundle.NeedThis(depbund);
                    }
                    else
                    {
                        this.ThrowBundleMissing(pkginfo.Depends[i]);
                    }
                }
            }
            else
            {
                this.ThrowBundleMissing(pkginfo.BundleName);
            }
        }
Beispiel #5
0
        private void Loadspite(string imageSpr)
        {
            if (this.bundle == null)
            {
                ResBundleMgr.mIns.LoadAsset(this.AtlasName);
                this.bundle = ResBundleMgr.mIns.Cache.TryGetValue(this.AtlasName);
            }

            if (!spritelist.ContainsKey(imageSpr))
            {
                UnityEngine.Object[] objs;
                if (this.bundle.LoadAllAssets(out objs))
                {
                    for (int i = 0; i < objs.Length; i++)
                    {
                        Sprite spr = objs[i] as Sprite;
                        if (spr != null)
                        {
                            spritelist[spr.name] = spr;
                        }
                        //else
                        //    LogMgr.LogErrorFormat("类型不一致 :{0}", objs[i]);
                    }
                }

                bool inserted = spritelist.ContainsKey(imageSpr);
                if (!inserted)
                {
                    LogMgr.LogErrorFormat("不存在这个图片 :{0}", imageSpr);
                    return;
                }
            }
        }
Beispiel #6
0
        public void LogDepends()
        {
            //this.UpdateRefs();

            for (int i = 0; i < this.depends.Count; ++i)
            {
                IBundleRef bundle = this.depends[i];
                LogMgr.LogFormat("<color=#ff0ff0ff>[{0}] Need This Bundle [{1}] ,its RefCount is {2},its SelfRefCnt is {3} ,its DependedCnt is {4}</color>", this.name, bundle.name, bundle.InstanceRefCount, bundle.SelfRefCount, bundle.DependCount);
            }
        }
        public AssetBundleResult(IBundleRef bundleref, UnityEngine.Object bundle, GameObject parentPath, GameObject hadload, string loadpath)
        {
            this.MainObject       = bundleref;
            this.LoadPath         = loadpath;
            this.ParentPath       = parentPath;
            this.SceneAsyncResult = null;

            this.m_LoadedObject = bundle;
            this._autoObject    = hadload;
        }
Beispiel #8
0
            private void CheckEnd()
            {
                if (m_count == 0)
                {
                    m_callback(m_ref);
                    m_callback = null;
                    m_ref      = null;

                    Recover(this);
                }
            }
 public virtual void RemoveToPool()
 {
     this._BundleMainObject  = null;
     this._BundleRef         = null;
     this.loadingpkg         = null;
     this.LoadResPath        = null;
     this.LoadState          = BundleLoadState.Prepared;
     this.onComplete         = null;
     this.LoaderInsObject    = null;
     this.PreParedGameObject = null;
     this._AsyncOpation      = null;
 }
Beispiel #10
0
        protected IBundleRef LoadFullAssetToMem(BundlePkgInfo pkginfo)
        {
            IBundleRef bundle = null;

            if (ResBundleMgr.mIns.Cache.Contains(pkginfo))
            {
                bundle = ResBundleMgr.mIns.Cache.TryGetValue(pkginfo);
                return(bundle);
            }

#if UNITY_IOS || UNITY_IPHONE || UNITY_ANDROID
            if (GameApplication.isPlaying && MainLoop.getInstance().OpenABMode)
            {
                AssetBundle ab = null;
                using (gstring.Block())
                {
                    ab = this.LoadAssetBundle(BundlePathConvert.GetRunningPath(pkginfo.AbFileName));
                }

                if (ab == null)
                {
                    this.ThrowAssetMissing(this.LoadResPath);
                }

                bundle = ResBundleMgr.mIns.Cache.PushAsset(pkginfo, ab);
                return(bundle);
            }
            else
#endif
            {
                UnityEngine.Object target = AssetDatabaseLoad(pkginfo.EditorPath);
                if (target == null)
                {
                    if (BundleConfig.SAFE_MODE)
                    {
                        this.ThrowAssetMissing(pkginfo.BundleName);
                    }
                    else
                    {
                        this.LoadState = BundleLoadState.Error;
                        LogMgr.LogErrorFormat("Asset {0} Missing", pkginfo.BundleName);
                    }
                }
                else
                {
#if UNITY_EDITOR
                    bundle = ResBundleMgr.mIns.Cache.PushEditorAsset(pkginfo, target);
#endif
                }
                return(bundle);
            }
        }
Beispiel #11
0
 public void NeedThis(IBundleRef dep)
 {
     for (int i = 0; i < this.depends.Count; ++i)
     {
         IBundleRef Ibundle = this.depends[i];
         if (Ibundle != null && Ibundle.Equals(dep))
         {
             return;
         }
     }
     dep.Retain();
     this.depends.Add(dep);
 }
Beispiel #12
0
 private void SetLoadRef(BundlePkgInfo pkginfo)
 {
     for (int i = 0; i < pkginfo.Depends.Length; ++i)
     {
         BundlePkgInfo pkg       = this._SeekPkgInfo(pkginfo.Depends[i]);
         IBundleRef    refBundle = ResBundleMgr.mIns.Cache.TryGetValue(pkg);
         if (refBundle != null)
         {
             LoadedRefs[pkg.AbFileName] = refBundle;
         }
         //set child pkg
         SetLoadRef(pkg);
     }
 }
Beispiel #13
0
        /// <summary>
        /// 移除引用的bundle
        /// </summary>
        /// <param name="bundlename"></param>
        /// <returns></returns>
        public bool Remove(IBundleRef bundle)
        {
            bool ret = this.RefCaches.RemoveValue(bundle);

            if (FrameWorkConfig.Open_DEBUG)
            {
                LogMgr.LogFormat("Bundle Will Remove From this Pool :{0} ,{1}", bundle, ret ? "True" : "False");
            }

            if (ret)
            {
                this.ptrcaches.RemoveKey(bundle.filename);
            }
            return(ret);
        }
Beispiel #14
0
        public IBundleRef PushEditorAsset(BundlePkgInfo pkg, UnityEngine.Object ab)
        {
            IBundleRef bundle = null;

            if (!this.Contains(pkg.AbFileName))
            {
                bundle = new EditorRef(ab, pkg.BundleName, pkg.AbFileName, pkg.EditorPath);
                this[pkg.AbFileName] = bundle;
            }
            else
            {
                bundle = this[pkg.AbFileName];
            }
            return(bundle);
        }
Beispiel #15
0
        /// <summary>
        /// 添加bundle
        /// </summary>
        /// <param name="pkg"></param>
        /// <param name="ab"></param>
        /// <returns></returns>
        public IBundleRef PushAsset(BundlePkgInfo pkg, AssetBundle ab)
        {
            IBundleRef bundle = null;

            if (!this.Contains(pkg.AbFileName))
            {
                bundle = BundleRef.Create(this.TryGetPtr(pkg.AbFileName, ab), pkg.AbFileName, pkg.EditorPath, pkg.BundleName);
                this[pkg.AbFileName] = bundle;
            }
            else
            {
                bundle = this[pkg.AbFileName];
            }
            return(bundle);
        }
Beispiel #16
0
        protected bool CreateFromAsset(IBundleRef bundle, out UnityEngine.Object asset)
        {
            if (isSceneLoad)
            {
                asset = null;
                return(true);
            }

            bool ret = bundle.LoadAsset(out asset);

            if (!ret)
            {
                this.ThrowAssetMissing(this.LoadResPath);
            }

            return(ret);
        }
Beispiel #17
0
        private void RefreshLoaded()
        {
            if (this.Needed == this.LoadedRefs.Count)
            {
                return;
            }

            SetLoadRef(loadingpkg);

            //self
            IBundleRef selfBundle = ResBundleMgr.mIns.Cache.TryGetValue(this.loadingpkg);

            if (selfBundle != null)
            {
                LoadedRefs[loadingpkg.AbFileName] = selfBundle;
            }
        }
Beispiel #18
0
        public void LogDebugInfo()
        {
            LogMgr.LogFormat("<color=#0000ffff>----------Bundle In Pool Cnt is {0}-------------</color>", this.CacheCnt);

            var keys = new List <string>(this.RefCaches.Keys);

            for (int i = 0; i < keys.Count; ++i)
            {
                string        key        = keys[i];
                IBundleRef    bundle     = this.RefCaches[key];
                string        bundlename = bundle.name;
                BundlePkgInfo info       = ResBundleMgr.mIns.BundleInformation.SeekInfo(bundle.name);
                if (info != null)
                {
                    bundlename = info.BundleName;
                }

                LogMgr.LogFormat("<color=#00aa00ff>Root Bundle is {0}:{1} ,InsRefCount is {2} ,DependedCnt is {3} ,SelfRefCount:{4}</color>", bundle.name, bundlename, bundle.InstanceRefCount, bundle.DependCount, bundle.SelfRefCount);
                bundle.LogDepends();
            }
            LogMgr.Log("<color=#0000ffff>----------Bundle In Pool Log End-------------</color>");
        }
Beispiel #19
0
    public void EnableScene()
    {
        if (FrameWorkConfig.Open_DEBUG)
        {
            LogMgr.LogFormat("启动场景 :{0}", this.ScenePath);
        }

        this._async.allowSceneActivation = true;
#if TOLUA
        if (MainLoop.getInstance().OpenLua&& LuaClient.GetMainState() != null)
        {
            LuaClient.GetMainState().Collect();
        }
#endif

        IBundleRef bundle = ResBundleMgr.mIns.Cache.TryGetValue(ScenePath);
        if (bundle != null)
        {
            bundle.UnLoad(true);
        }

        // TimeCommand.Create(1f, setFalse).Excute();
    }
Beispiel #20
0
 /// <summary>
 /// 搜查并删除
 /// </summary>
 /// <param name="name"></param>
 /// <param name="force"></param>
 public static void SeekUnLoad(string name, bool force = false)
 {
     if (mIns != null)
     {
         BundlePkgInfo info = mIns.Info.SeekInfo(name);
         if (info != null)
         {
             IBundleRef bundle = mIns.Cache.TryGetValue(info);
             if (bundle != null)
             {
                 bundle.UnLoad(force);
             }
             else
             {
                 LogMgr.LogErrorFormat("The Bundle which your seek isnt in the Pool Or Loaded Yield :{0}", name);
             }
         }
         else
         {
             LogMgr.LogErrorFormat("Not Found your Seek Info :{0}", name);
         }
     }
 }
Beispiel #21
0
 public void MainLoadDown(IBundleRef _ref)
 {
     m_ref = _ref;
 }
Beispiel #22
0
 public void Reset()
 {
     m_ref      = null;
     m_count    = 0;
     m_callback = null;
 }
Beispiel #23
0
 public void NeedThis(IBundleRef dep)
 {
 }
Beispiel #24
0
        private void AutoCreateBundle()
        {
            if (Task.asyncType == AsyncBundleTp.AB_LOAD)
            {
                AssetBundleRequest abReq = Task.currentAsync as AssetBundleRequest;
                this.LoadMainAsyncRequest(abReq);
            }
            else if (Task.asyncType == AsyncBundleTp.AB_CREATE)
            {
                AssetBundleCreateRequest abCreateReq = Task.currentAsync as AssetBundleCreateRequest;
                if (abCreateReq.assetBundle == null)
                {
                    ThrowAssetMissing(this.LoadResPath);
                }

                IBundleRef bundle = ResBundleMgr.mIns.Cache.PushAsset(Task.CurrentLoadInfo, abCreateReq.assetBundle);

                BundlePkgInfo pkg = this._SeekPkgInfo(abCreateReq.assetBundle.name);
                this.AddDepends(pkg, bundle);

                ResBundleMgr.mIns.Cache.RemoveLoading(pkg.BundleName);
                if (FrameWorkConfig.Open_DEBUG)
                {
                    LogMgr.LogFormat("成功加载了 :{0} => {1} => {2} => RefCnt :{3} =>SelfRefCnt:{4}", this.UID, pkg.BundleName, pkg.AbFileName, bundle.InstanceRefCount, bundle.SelfRefCount);
                }
                this.RefreshLoaded();
            }
            else if (Task.asyncType == AsyncBundleTp.SCENE_LOAD)
            {
                this.LoadSceneAssetFinish();
            }
            else
            {
                if (isABMode)
                {
                    if (BundleConfig.SAFE_MODE)
                    {
                        throw new FrameWorkResNotMatchException(string.Format("不被支持的异步类型 {0}", Task.currentAsync));
                    }
                    else
                    {
                        LogMgr.LogError("不被支持的异步类型 ");
                        this.LoadState = BundleLoadState.Error;
                    }
                }
                else
                {
                    this._BundleRef        = LoadFullAssetToMem(this.loadingpkg);
                    this._BundleMainObject = this._BundleRef.MainObject;
                    this.AddDepends(this.loadingpkg, this._BundleRef);

                    if (isSceneLoad)
                    {
                        SceneOperation asyncOp = GameSceneCtr.LoadSceneAsync(Path.GetFileNameWithoutExtension(this.LoadResPath));
                        asyncOp.DisableScene();
                        this._AsyncOpation = asyncOp;

                        this._PushTaskAndExcute(this.loadingpkg, asyncOp);
                    }
                    else
                    {
                        this._FinishAndRelease();
                    }
                }
            }
        }
Beispiel #25
0
 public void OneLoadDown(IBundleRef _ref)
 {
     m_count--;
     CheckEnd();
 }