Exemplo n.º 1
0
        public GameObject Spawn(Vector3 position, Quaternion rotation)
        {
            GameObject instance;

            if (inactiveObjects.Count == 0)
            {
                instance      = Object.Instantiate(prefab, position, rotation);
                instance.name = prefab.name + " (" + idCount++ + " )";
                PoolEntry.Create(instance, this);
            }
            else
            {
                instance = inactiveObjects.Pop();
                if (instance == null)
                {
                    Spawn(position, rotation);
                }
            }

            if (instance == null)
            {
                Debug.Log("GameObject \"instance\" was null.");
                return(null);
            }

            instance.transform.position = position;
            instance.transform.rotation = rotation;
            instance.SetActive(true);

            return(instance);
        }
Exemplo n.º 2
0
        public static void Destroy(GameObject instance)
        {
            PoolEntry poolEntry = instance.GetComponent <PoolEntry>();

            if (poolEntry == null)
            {
                Object.Destroy(instance);
            }
            else
            {
                poolEntry.Pool.Destroy(instance);
            }
        }