Example #1
0
 protected virtual void InstanceTaken(PooledObject pObj)
 {
     foreach (var kvp in pObj.ManagedComponents) {
         foreach (var c in kvp.Value) {
             sTypeEnableMap [kvp.Key].SetValue (c, true, null);
         }
     }
 }
Example #2
0
        protected virtual void InstanceReturned(PooledObject pObj)
        {
            foreach (var kvp in pObj.ManagedComponents) {
                foreach (var c in kvp.Value) {
                    sTypeEnableMap [kvp.Key].SetValue (c, false, null);
                }
            }

            // once disabled, parent under pool object
            pObj.transform.SetParent (this.transform, false);
        }
Example #3
0
        public bool Steal(PooledObject pObj)
        {
            if (!pObj || pObj.Pool != this) {
                return false;
            }

            _pool [pObj.IndexInPool] = null;
            _free.Push (pObj.IndexInPool);
            pObj.Pool = null;
            --Allocated;

            // destroy the component
            Object.Destroy (pObj);
            return true;
        }
Example #4
0
 protected virtual void InstanceCreated(PooledObject pObj)
 {
     pObj.ManagedComponents = new Dictionary<System.Type, Component[]> ();
     foreach (var kvp in sTypeEnableMap) {
         pObj.ManagedComponents[kvp.Key] = pObj.GetComponentsInChildren (kvp.Key, false);
     }
 }
Example #5
0
        public bool Return(PooledObject pObj)
        {
            if (!pObj || pObj.Pool != this) {
                Debug.LogError ("Cannot release object from pool", this);
                return false;
            }

            if (!pObj.IsActiveInPool) {
                return false;
            }

            int index = pObj.IndexInPool;
            UnityEngine.Assertions.Assert.IsTrue (object.ReferenceEquals(pObj, _pool[pObj.IndexInPool]));

            pObj.IsActiveInPool = false;
            _free.Push (index);

            InstanceReturned (pObj);
            return true;
        }