private ObjectPool CreateNewPool(ReturnToPool returnCondition) { ObjectPool pool = new ObjectPool(returnCondition.gameObject, ObjectPoolsHolder); CreateObjectPool(pool); objectPools.TryGetValue(returnCondition.Id, out pool); return(pool); }
public void Lasting(Transform target, float time, float d, bool isOverlay = false) { if (m_rtp == null) m_rtp = GetComponent<ReturnToPool>(); m_rtp.deathTime = 0.1f + Mathf.Max(m_rtp.deathTime, time); GetControlled(target); if (m_ctrl.controlFuncDic.ContainsKey(type)) StartCoroutine(m_ctrl.controlFuncDic[type](time, d)); }
public void ReturnToPool(GameObject gameObject) { ReturnToPool returnCondition = gameObject.GetComponent <ReturnToPool>(); if (returnCondition) { ReturnToPool(returnCondition); } }
public void ReturnToPool(ReturnToPool returnCondition) { ObjectPool pool; if (!objectPools.TryGetValue(returnCondition.Id, out pool)) { pool = CreateNewPool(returnCondition); } pool.ReturnToPool(returnCondition.gameObject); spawnedObjects.Remove(returnCondition.gameObject); }
public void Lasting(Transform target, float time, float d, bool isOverlay = false) { if (m_rtp == null) { m_rtp = GetComponent <ReturnToPool>(); } m_rtp.deathTime = 0.1f + Mathf.Max(m_rtp.deathTime, time); GetControlled(target); if (m_ctrl.controlFuncDic.ContainsKey(type)) { StartCoroutine(m_ctrl.controlFuncDic[type](time, d)); } }
private void AddProjectilesToPool(int amountToAdd) { ReturnToPool delegateToUse = HandleReturnToPool; for (int i = 0; i < amountToAdd; i++) { GameObject newGameObject = Instantiate(_weaponProjectile, transform.position, Quaternion.identity); LinearProjectile projectile = newGameObject.GetComponent <LinearProjectile>(); projectile._returnToPool = delegateToUse; _projectilesNotInUse.Push(projectile); // turn projectile off newGameObject.SetActive(false); } }
// Use this for initialization void Awake() { pool = new Stack <GameObject>(); for (int i = 0; i < Max; i++) { pool.Push(Instantiate(Prefab)); pool.Peek().transform.SetParent(transform); ReturnToPool rtp = pool.Peek().GetComponent <ReturnToPool>(); if (rtp) { rtp.active = false; } pool.Peek().SetActive(false); } poolDirectory[Prefab] = this; }
protected void OnReturnToPool() { ReturnToPool?.Invoke(this, null); }
public void Initialize(SpawnableObjectPool <Clone> PoolToReturn) { this.PoolToReturn = PoolToReturn; MyReturnToPool = new ReturnToPool(PoolToReturn.ReturnObjectToPool); }
private void AddPoolReference(GameObject newObject, ref ReturnToPool[] conditions) { conditions = new ReturnToPool[1]; conditions[0] = newObject.AddComponent <ReturnToPool>(); }