Ejemplo n.º 1
0
        private GameObject AddNewGameObjectToPool(IPoolableAsset asset, List <GameObject> objectPool)
        {
            GameObject   go       = asset.InstantiatePrefabToPool(m_poolFolder.transform);
            ObjectRepool repooler = go.AddComponent <ObjectRepool>();

            repooler.Initialise(asset, this);

            int prefix = objectPool.Count + 1;

            go.name = prefix + " " + asset.GetName();

            if (go)
            {
                objectPool.Add(go);
            }
            return(go);
        }
Ejemplo n.º 2
0
        public GameObject GetObjectFromPool(IPoolableAsset asset, Vector3 position, Quaternion rotation)
        {
            if (position == null)
            {
                position = Vector3.zero;
            }
            if (rotation == null)
            {
                rotation = Quaternion.identity;
            }

            if (!m_poolMaster.ContainsKey(asset.GetName()))
            {
                TryCreateNewPool(asset);
                //return null;        //TODO - this means the first GO will always be missing when adding on the fly
            }

            var objectPool = m_poolMaster[asset.GetName()];

            var go = FindInactiveObjectInPool(objectPool);

            if (go == null)
            {
                go = AddNewGameObjectToPool(asset, objectPool);
                go.SetActive(true);
            }

            if (go != null)
            {
                //go.transform.parent = null;
                SetObjectPositionAndRotation(go, position, rotation);
            }

            ObjectRepool repoolComponent = go.GetComponent <ObjectRepool>();

            repoolComponent.Activate();

            go.SetActive(true);

            return(go);
        }