public void Dispose(IPooled pooled) { if (activeObjects.Contains(pooled)) { activeObjects.Remove(pooled); } }
public List <GameObject> SpawnEntirePool(string _tag, Queue <Vector3> _positions, Queue <Quaternion> _rotations) { List <GameObject> objectsToSpawn = new List <GameObject>(); if (!poolDictionary.ContainsKey(_tag)) { Debug.Log("Object with tag " + _tag + " doesn't exist"); return(null); } foreach (GameObject objectToSpawn in poolDictionary[_tag]) { objectToSpawn.transform.localPosition = _positions.Dequeue(); objectToSpawn.transform.localRotation = _rotations.Dequeue(); objectToSpawn.SetActive(true); IPooled pooledObject = objectToSpawn.GetComponent <IPooled>(); if (pooledObject != null) { pooledObject.OnObjectSpawn(); } objectsToSpawn.Add(objectToSpawn); } return(objectsToSpawn); }
public GameObject SpawnPoolObject(string _tag, Vector3 _position, Quaternion _rotation) { if (!poolDictionary.ContainsKey(_tag)) { Debug.Log("Object with tag " + _tag + " doesn't exist"); return(null); } GameObject objectToSpawn = poolDictionary[_tag].Dequeue(); objectToSpawn.transform.localPosition = _position; objectToSpawn.transform.localRotation = _rotation; objectToSpawn.SetActive(true); IPooled pooledObject = objectToSpawn.GetComponent <IPooled>(); if (pooledObject != null) { pooledObject.OnObjectSpawn(); } poolDictionary[_tag].Enqueue(objectToSpawn); return(objectToSpawn); }
public void Return(IPooled pooledObject) { if (activeItems.Remove(pooledObject)) { poolStack.Push(pooledObject); } }
public void ReturnAll() { for (int i = activeObjects.Count - 1; i >= 0; i--) { IPooled pooled = activeObjects[i] as IPooled; pooled.ReturnToPool(); } }
public void Return(IPooled pooledObject) { P item = pooledObject as P; instances.Push(item); activeObjects.Remove(item); OnItemReturnedToPool(item); }
private void AddInstanceToPool() { IPooled item = createInstanceHandler(); item.Init(this); activeItems.Add(item); item.ReturnToPool(); }
public ConnectToken(CancellationToken cancellation, Action <ConnectToken, SocketAsyncEventArgs> cancel, IPooled <SocketAsyncEventArgs> pooled) { _pooled = pooled; _tcs = new TaskCompletionSource <ISocket>(); if (cancellation.CanBeCanceled) { _cancellationTokenRegistration = cancellation.Register(() => cancel(this, pooled.Instance)); } }
public void DestroyPool(GameObject spawned) { IPooled pooledObj = spawned.GetComponent <IPooled>(); if (pooledObj != null) { pooledObj.OnUnSpawn(); } spawned.transform.SetParent(transform); spawned.SetActive(false); }
public IPooled Take() { if (poolStack.Count == 0) { AddInstanceToPool(); } IPooled item = poolStack.Pop(); item.TakeFromPool(); activeItems.Add(item); return(item); }
/// <summary> /// Recycles an object to the object pool /// </summary> /// <param name="InstanceId">Instance id of the object</param> public void Recycle(GameObject go) { if (!PooledObjects.Contains(go) && PooledObjects.Count < MaxItems) { IPooled ip = go.GetComponent <IPooled>(); if (ip != null) { ip.OnRecycle(); } go.SetActive(false); go.transform.position = Vector3.zero; PooledObjects.Push(go); } }
/// <summary> /// Returns a GameObject from object pool and enables it /// </summary> /// <param name="pos">New Position</param> /// <param name="rot">New Rotation</param> private GameObject GetFromPool(Vector3 pos, Quaternion rot) { if (PooledObjects.Count > 0) { GameObject g = PooledObjects.Pop(); g.transform.position = pos; g.transform.rotation = rot; g.SetActive(true); IPooled ip = g.GetComponent <IPooled>(); if (ip != null) { ip.OnSpawn(); } return(g); } return(null); }
/// <summary> /// Use thid method to instantiate a gameobject using a Gameobject reference /// </summary> /// <param name="obj"> PREFAB </param> /// <param name="pos"> Position </param> /// <param name="rot"> Rotation </param> /// <returns></returns> private GameObject InstantiatePool(GameObject obj, Vector3 pos, Quaternion rot) { if (!m_poolObjects.ContainsKey(obj.name)) { CreatePool(obj); } foreach (GameObject poolObj in m_poolObjects[obj.name]) { if (poolObj == null) { continue; } if (poolObj.activeSelf == false) { poolObj.transform.position = pos; poolObj.transform.rotation = rot; IPooled pooledObj = poolObj.GetComponent <IPooled>(); if (pooledObj != null) { pooledObj.OnInstantiate(); } poolObj.SetActive(true); return(poolObj); } } GameObject currentObj = Instantiate(obj) as GameObject; currentObj.transform.position = pos; currentObj.transform.rotation = rot; currentObj.name = obj.name; currentObj.SetActive(true); IPooled newpooledObj = currentObj.GetComponent <IPooled>(); if (newpooledObj != null) { newpooledObj.OnInstantiate(); } m_poolObjects[obj.name].Add(currentObj); return(currentObj); }
public GpuRawFrame(FrameInfo info, IPooled<ITexture2D> texturePooled) { Info = info; TexturePooled = texturePooled; }
public PooledToken(IPooled <SocketAsyncEventArgs> pooled) { _pooled = pooled; TaskCompletionSource = new TaskCompletionSource <T>(); _pooled.Instance.UserToken = this; }
public CompressedFrame(IPooled<byte[]> data, int compressedSize) { DataPooled = data; CompressedSize = compressedSize; }
public void Return(IPooled pooledObject) { instances.Push(pooledObject as P); }
public void Dispose(IPooled pooled) { activeObjects.RemoveAll(o => o == (P)pooled); }