/// <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> /// 获取一个缓存对象,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); }