예제 #1
0
 public void AddToHolder(CacheObjInfo varCacheInfo)
 {
     if (varCacheInfo == null || varCacheInfo.mHolder == null)
     {
         return;
     }
     varCacheInfo.mHolder.SetParent(mHolder);
 }
예제 #2
0
 /// <summary>
 /// 重新指定引用
 /// </summary>
 /// <returns></returns>
 public CacheObjInfo ReAssign()
 {
     if (mOriginalObjInfo != null)
     {
         CacheObjInfo info = mOriginalObjInfo.GetCacheObj(mOriginalObjInfo.pObjFlag);
         return(info);
     }
     return(null);
 }
예제 #3
0
 public void Callback(CacheObjInfo varInfo)
 {
     if (mFunc != null)
     {
         mFunc(varInfo, mParam);
         if (pHandle != null)
         {
             pHandle.OnTaskEnd(this, varInfo);
         }
     }
 }
예제 #4
0
 /// <summary>
 /// 移除当前的缓存物体
 /// </summary>
 /// <param name="varCacheInfo"></param>
 public void RemoveCacheObj(CacheObjInfo varCacheInfo)
 {
     if (varCacheInfo == null)
     {
         return;
     }
     if (varCacheInfo.IsLock() == true)
     {
         mRefCount--;
     }
     varCacheInfo.UnLock();
     mCacheObjs.Remove(varCacheInfo);
     RefreshHolder();
 }
예제 #5
0
 /// <summary>
 /// 回收使用完的对象
 /// </summary>
 /// <param name="varCacheInfo"></param>
 public void RecycleObj(CacheObjInfo varCacheInfo)
 {
     mRefCount--;
     if (varCacheInfo == null)
     {
         return;
     }
     //if (varCacheInfo.mObj == null)
     //{
     //    mCacheObjs.Remove(varCacheInfo);
     //}
     varCacheInfo.UnLock();
     RefreshHolder();
 }
예제 #6
0
 public void OnTaskEnd(LoadTask varTask, CacheObjInfo varObjInfo)
 {
     if (TaskCount < 0)
     {
         return;
     }
     TaskCount--;
     if (TaskCount == 0)
     {
         if (Callback != null)
         {
             Callback(null, Params);
         }
     }
 }
예제 #7
0
        /// <summary>
        /// 获取一个缓存对象,varIsUseOriObj:是否使用源对象
        /// </summary>
        /// <param name="varIsUseOriObj"></param>
        /// <returns></returns>
        public CacheObjInfo GetCacheObj(GameObjPool.ObjFlag varResult)
        {
            if (mCacheObjs == null)
            {
                mCacheObjs = new List <CacheObjInfo>();
            }
            CacheObjInfo info = null;

            for (int i = 0; i < mCacheObjs.Count; i++)
            {
                CacheObjInfo tmpInfo = mCacheObjs[i];
                if (tmpInfo == null)
                {
                    mCacheObjs.Remove(tmpInfo);
                    i--;
                    continue;
                }
                if (tmpInfo.IsLock() == false)
                {
                    info = tmpInfo;
                }
            }
            if (info == null)
            {
                switch (varResult)
                {
                case GameObjPool.ObjFlag.Clone:
                    info = new CacheObjInfo(UnityEngine.Object.Instantiate(mObj), this);
                    break;

                case GameObjPool.ObjFlag.UseOriObj:
                    info = new CacheObjInfo(mObj, this);
                    break;

                case GameObjPool.ObjFlag.CloneWhenUse:
                    info = new CacheObjInfo(null, this);
                    break;
                }
                mCacheObjs.Add(info);
            }
            info.Lock();
            mRefCount++;
            RefreshHolder();
            return(info);
        }
예제 #8
0
        private void OnLoadCfgFileCallback(CacheObjInfo varObjInfo, object varParam)
        {
            Handle handle = varParam as Handle;

            if (handle == null)
            {
                Helper.LogError("LocalCfg OnLoadCfgFileCallback: Error caused by null Handle instance");
                return;
            }
            if (varObjInfo == null)
            {
                Helper.LogError("LocalCfg OnLoadCfgFileCallback: Error caused by null CacheObjInfo instance");
                return;
            }
            if (varObjInfo.GetObj() == null)
            {
                Helper.LogError("LocalCfg OnLoadCfgFileCallback: Error caused by null CacheObjInfo.GetObj() instance");
                return;
            }
            TextAsset textAsset = varObjInfo.GetObj() as TextAsset;

            if (textAsset == null)
            {
                Helper.LogError("LocalCfg OnLoadCfgFileCallback: Error caused by null TextAsset instance");
                return;
            }
            Stream stream = new MemoryStream(textAsset.bytes, false);

            if (stream == null)
            {
                Helper.LogError("LocalCfg OnLoadCfgFileCallback: Error caused by null MemoryStream instance");
                return;
            }
            object targetObj = Serializer.Deserialize(handle.TargetType, stream);

            varObjInfo.Recycle();
            handle.Callback(targetObj);
        }