public void AddToHolder(CacheObjInfo varCacheInfo) { if (varCacheInfo == null || varCacheInfo.mHolder == null) { return; } varCacheInfo.mHolder.SetParent(mHolder); }
/// <summary> /// 重新指定引用 /// </summary> /// <returns></returns> public CacheObjInfo ReAssign() { if (mOriginalObjInfo != null) { CacheObjInfo info = mOriginalObjInfo.GetCacheObj(mOriginalObjInfo.pObjFlag); return(info); } return(null); }
public void Callback(CacheObjInfo varInfo) { if (mFunc != null) { mFunc(varInfo, mParam); if (pHandle != null) { pHandle.OnTaskEnd(this, varInfo); } } }
/// <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(); }
/// <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(); }
public void OnTaskEnd(LoadTask varTask, CacheObjInfo varObjInfo) { if (TaskCount < 0) { return; } TaskCount--; if (TaskCount == 0) { if (Callback != null) { Callback(null, Params); } } }
/// <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); }
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); }