Пример #1
0
        private PoolableObject _NewPooledInstance(Vector3?position, Quaternion?rotation)
        {
            GameObject go;

            _isDuringInstantiate = true;

            if (position != null && rotation != null)
            {
                go = (GameObject)GameObject.Instantiate(_prefabPoolObj.gameObject, (Vector3)position, (Quaternion)rotation);
            }
            else
            {
                go = (GameObject)GameObject.Instantiate(_prefabPoolObj.gameObject);
            }

            _isDuringInstantiate = false;

            PoolableObject poolObj = go.GetComponent <PoolableObject>();

            poolObj._createdWithPoolController = true;
            poolObj._myPool = this;
            poolObj._isAvailableForPooling = false;
            poolObj._serialNumber          = ++_globalSerialNumber;
            poolObj._usageCount++;

            if (poolObj.doNotDestroyOnLoad)
            {
                GameObject.DontDestroyOnLoad(go);
            }

            _pool.Add(poolObj);

            go.BroadcastMessage("OnPoolableInstanceAwake", SendMessageOptions.DontRequireReceiver);
            return(poolObj);
        }
Пример #2
0
        private PoolableObject _NewPooledInstance(Vector3?position, Quaternion?rotation)
        {
            _isDuringInstantiate = true;
            GameObject gameObject;

            if (position != null && rotation != null)
            {
                gameObject = (GameObject)UnityEngine.Object.Instantiate(_prefabPoolObj.gameObject, position.Value, rotation.Value);
            }
            else
            {
                gameObject = (GameObject)UnityEngine.Object.Instantiate(_prefabPoolObj.gameObject);
            }
            _isDuringInstantiate = false;
            PoolableObject component = gameObject.GetComponent <PoolableObject>();

            component._createdWithPoolController = true;
            component._myPool = this;
            component._isAvailableForPooling = false;
            component._serialNumber          = ++_globalSerialNumber;
            component._usageCount++;
            if (component.doNotDestroyOnLoad)
            {
                UnityEngine.Object.DontDestroyOnLoad(gameObject);
            }
            _pool.Add(component);
            gameObject.BroadcastMessage("OnPoolableInstanceAwake", SendMessageOptions.DontRequireReceiver);
            return(component);
        }