Beispiel #1
0
 public void RecycleObject(PoolableObjectInstance poi)
 {
     if (poi.UseStatus == PoolableObjectInstance.UsageStatus.InUse)
     {
         poi.gameObject.SetActive(false);
         poi.transform.SetParent(this.transform);
         poi.UseStatus = PoolableObjectInstance.UsageStatus.Ready;
         ObjectsPool[poi.Key].Add(poi.gameObject);
     }
 }
Beispiel #2
0
    private List <GameObject> InstantiateObjectForPool(PoolableObjectConfig obj)
    {
        List <GameObject> objects = new List <GameObject>();

        for (int i = 0; i < obj.count; i++)
        {
            GameObject objInstance = Instantiate(obj.prefab);
            objInstance.SetActive(false);
            objInstance.transform.SetParent(this.transform);
            objInstance.name = obj.prefab.name;
            objInstance.AddComponent <PoolableObjectInstance>();
            PoolableObjectInstance poolableRef = objInstance.GetComponent <PoolableObjectInstance>();
            poolableRef.Key       = obj.key;
            poolableRef.UseStatus = PoolableObjectInstance.UsageStatus.Ready;
            objects.Add(objInstance);
        }
        return(objects);
    }