private void Return(ObjectPoolObject obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } _pool.Add(obj); }
// ******************************************************************** #endregion // ******************************************************************** // ******************************************************************** #region Private Methods // ******************************************************************** private ObjectPoolObject CreateObject(bool _active = true) { GameObject newObject = null; if (m_prefab == null) { newObject = new GameObject("ObjectPool Object"); } else { bool wasEnabled = m_prefab.activeSelf; m_prefab.SetActive(false); newObject = GameObject.Instantiate <GameObject>(m_prefab); m_prefab.SetActive(wasEnabled); } ObjectPoolObject objectPoolObject = newObject.AddComponent <ObjectPoolObject>(); objectPoolObject.pool = this; newObject.SetActive(_active); return(objectPoolObject); }
protected void Button2_Click(object sender, EventArgs e) { QueuePool qPool = new QueuePool(); qPool.Store(new Person()); //Person p = qPool.Fetch(); QueuePool <Person> qPoolPerson = new QueuePool <Person>(); qPoolPerson.Store(new Person()); Person p1 = qPoolPerson.Fetch(); ObjectPoolObject <Person> pPoolObject = new ObjectPoolObject <Person>(10); Person a = pPoolObject.Get(); Person a1 = pPoolObject.Get(); a.Name = "Sophy"; a1.Name = "Tammy"; this.TextBox1.Text += string.Format($"\r\n {a.Name } meet {a1.Name} total employee in the queue {pPoolObject.Count()}"); this.TextBox1.Text += "\r\nQueue is a Simple DataStucture which allows Add or Remove of Items at one of the ends only. It is basically called as First in First out data structure. Enqueue() and Dequeue()"; }
// Return an object to the pool public static void Pull(ObjectPoolObject obj) { obj.transform.SetParent(obj.parentPool); ResetPosition(obj.gameObject, obj.parentPool); obj.gameObject.SetActive(false); }
// ******************************************************************** public void ObjectDestroyed(ObjectPoolObject _object) { // Debug.Log ("object destroyed: "+_object.name); m_available.Remove(_object); m_inUse.Remove(_object); }
// ******************************************************************** public void ObjectBecameUnavailable(ObjectPoolObject _object) { // Debug.Log ("object became unavailable: "+_object.name); m_available.Remove(_object); m_inUse.Add(_object); }
public ObjectPool(Func <ObjectPoolObject> creationMethod) { ObjectPoolObject objectPoolObject = creationMethod(); objectPoolObject.m_pool = this; }
// ******************************************************************** // Function: ObjectBecameUnavailable() // Purpose: Moves object from available to in use // ******************************************************************** public void ObjectBecameUnavailable (ObjectPoolObject _object) { Debug.Log ("object became unavailable: "+_object.name); m_available.Remove(_object); m_inUse.Add(_object); }