コード例 #1
0
    static T FetchObjectFromPoolEntry(FreePoolEntry <T> poolEntry)
    {
        T obj = poolEntry.GetObjectFromPool();

        ActivateObject(obj);

        return(obj);
    }
コード例 #2
0
    static FreePoolEntry <T> GetPoolEntryFor(T prefab)
    {
        if (!assetPool.ContainsKey(prefab.name))
        {
            FreePoolEntry <T> entry = new FreePoolEntry <T> (prefab);

            assetPool.Add(prefab.name, entry);
        }

        return(assetPool [prefab.name]);
    }
コード例 #3
0
        public override bool Equals(object obj)
        {
            eComp = obj as FreePoolEntry <U>;

            if (eComp == null)
            {
                return(false);
            }

            return(eComp.GetHashCode() == GetHashCode());
        }
コード例 #4
0
    public static void Destroy(T instantiatedObject)
    {
        if (poolingEnabled && instantiatedObject.ShouldPoolObject())
        {
            FreePoolEntry <T> poolEntry = GetPoolEntryFor(instantiatedObject);

            DeactivateObject(instantiatedObject);

            poolEntry.AddObjectToPool(instantiatedObject);
        }
        else
        {
            DestroyObject(instantiatedObject);
        }
    }
コード例 #5
0
    public static T Instantiate(T prefab)
    {
        if (poolingEnabled && prefab.ShouldPoolObject())
        {
            FreePoolEntry <T> poolEntry = GetPoolEntryFor(prefab);

            if (poolEntry.IsPoolEmpty())
            {
                INSTANTIATE_COUNT++;

                return(InstantiatePrefab(prefab));
            }
            else
            {
                POOL_RETRIEVAL_COUNT++;

                return(FetchObjectFromPoolEntry(poolEntry));
            }
        }
        else
        {
            return(InstantiatePrefab(prefab));
        }
    }