コード例 #1
0
ファイル: Pool.cs プロジェクト: asgard-born/CandyCrush
        private void AddObject(PoolObject sample, Transform objectsParent)
        {
            GameObject poolGameObject;

            if (sample.gameObject.scene.name == null)
            {
                poolGameObject      = Object.Instantiate(sample.gameObject, objectsParent, true);
                poolGameObject.name = sample.name;
            }
            else
            {
                poolGameObject = sample.gameObject;
            }

            var poolObject = poolGameObject.GetComponent <PoolObject>();

            poolObject.OnPoolReturned += this.OnObjectReturnedToPool;

            this.objects.Add(poolObject);
            poolGameObject.SetActive(false);
        }
コード例 #2
0
ファイル: Pool.cs プロジェクト: ysk1965/UnityProject
 public void ReturnObjectToPool(PoolObject po)
 {
     if (poolName.Equals(po.poolName))
     {
         /* we could have used availableObjStack.Contains(po) to check if this object is in pool.
          * While that would have been more robust, it would have made this method O(n)
          */
         if (po.isPooled)
         {
             Debug.LogWarning(po.gameObject.name + " is already in pool. Why are you trying to return it again? Check usage.");
         }
         else
         {
             AddObjectToPool(po);
         }
     }
     else
     {
         Debug.LogError(string.Format("Trying to add object to incorrect pool {0} {1}", po.poolName, poolName));
     }
 }