private void AddDeleteTime(Type poolKey, DeleteTime deleteTime) { mDeleteTimes.Add(poolKey, deleteTime); if (mPoolItems.TryGetValue(poolKey, out var poolItemBase)) { poolItemBase.SetDeleteTime(deleteTime); } }
public bool TryGetDeleteTime <T>(out DeleteTime deleteTime) where T : class, new() { return(mDeleteTimes.TryGetValue(typeof(T), out deleteTime)); }
public ObjectPoolItem(ObjectPool.LoadMode loadMode, string bundleName, string assetName, DeleteTime deleteTime) : base(deleteTime) { mLoadMode = loadMode; mBundleName = bundleName; mAssetName = assetName; mIsGameObject = typeof(T) == typeof(GameObject); mItemIDs = new HashSet <int>(); mItems = new LinkedList <Item>(); switch (mLoadMode) { case ObjectPool.LoadMode.Resource: m_ObjRes = Resources.Load <T>(assetName); break; // TODO: Add yourself AssetBundle load method // case ObjectPool.LoadMode.AssetBundle: // m_ObjRes = AssetBundleManager.GetAsset<T>(bundleName, assetName); // break; // MARK: Add yourself load methods } if (mIsGameObject) { mSpawnHandlers = new List <ISpawnHandler>(); mDisposeHandlers = new List <IDisposeHandler>(); #if UNITY_EDITOR //直接添加在预制体上 if (mLoadMode != ObjectPool.LoadMode.Resource) { if (m_ObjRes && m_ObjRes is GameObject go) { var itemKey = go.GetComponent <ObjectPoolItemKey>(); if (!itemKey) { itemKey = go.AddComponent <ObjectPoolItemKey>(); } itemKey.Init(mLoadMode, mBundleName, mAssetName); } } #else //直接添加在预制体上 if (m_ObjRes && m_ObjRes is GameObject go) { var itemKey = go.GetComponent <ObjectPoolItemKey>(); if (!itemKey) { itemKey = go.AddComponent <ObjectPoolItemKey>(); } itemKey.Init(mLoadMode, mBundleName, mAssetName); } #endif } if (!m_ObjRes) { Debug.LogError("ObjectItem load asset is null! Type: " + typeof(T) + ", LoadMode: " + loadMode + ", BundleName: " + bundleName + ", AssetName: " + assetName); } }
public CommonPoolItem(DeleteTime deleteTime) : base(deleteTime) { mItems = new LinkedList <Item>(); }
public bool TryGetDeleteTime <T>(LoadMode loadMode, string bundleName, string assetName, out DeleteTime deleteTime) where T : Object { return(mDeleteTimes.TryGetValue(new PoolKey(typeof(T), loadMode, bundleName, assetName), out deleteTime)); }