Beispiel #1
0
        public void DespawnObject <TValue>(TValue poolableObject) where TValue : Component, IPoolableBase
        {
            if (poolableObject == null)
            {
                return;
            }

            string prefabID = poolableObject.GetComponent <PoolObjectID>().poolID;

            if (!memoryPools.ContainsKey(prefabID))
            {
                return;
            }

            IDespawnableMemoryPool <TValue> pool = memoryPools[prefabID] as IDespawnableMemoryPool <TValue>;

            if (pool != null)
            {
                pool.Despawn(poolableObject);
            }
            else
            {
                Debug.LogError($"MultiPrefabPool Not Exists : {prefabID}");
            }
        }
Beispiel #2
0
        void StoreSpawnedObject <T>(T obj, IDespawnableMemoryPool <T> pool)
        {
            if (typeof(T).DerivesFrom <IDisposable>())
            {
                Add((IDisposable)obj);
            }
            else
            {
                // This allocation is ok because it's a struct
                var pair = new SpawnedObjectPoolPair
                {
                    Pool   = pool,
                    Object = obj
                };

                if (_objectPoolPairs == null)
                {
                    _objectPoolPairs = ListPool <SpawnedObjectPoolPair> .Instance.Spawn();
                }
                _objectPoolPairs.Add(pair);
            }
        }