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); } } }
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); }
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; }
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); } }
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; }