Exemplo n.º 1
0
        Recyclable InstantiateNewObject(Vector3 position, Quaternion rotation)
        {
            Recyclable obj = Instantiate <Recyclable>(objectToPool, position, rotation, transform);

            obj.onRecycle += Recycle;
            obj.gameObject.SetActive(false);

            objects.Add(obj);
            return(obj);
        }
Exemplo n.º 2
0
 void Recycle(Recyclable recycledObj)
 {
     if (objects.Contains(recycledObj))
     {
         recycledObj.SetActive(false);
     }
     else
     {
         Debug.Log("Attempting to recycle foreign object");
     }
 }
Exemplo n.º 3
0
 protected void Recycle(Recyclable obj)
 {
     if (onRecycle != null)
     {
         onRecycle(obj);
     }
     else
     {
         Debug.Log("No subscribers onRecycle");
     }
 }
Exemplo n.º 4
0
        public Recyclable Get(Vector3 position, Quaternion rotation)
        {
            foreach (Recyclable obj in objects)
            {
                if (!obj.activeSelf)
                {
                    obj.transform.position = position;
                    obj.transform.rotation = rotation;

                    obj.SetActive(true);
                    return(obj);
                }
            }

            Recyclable newObj = InstantiateNewObject(position, rotation);

            newObj.SetActive(true);
            return(newObj);
        }