public GameObject CreateObject(bool createInPool) { // true when creating an item in the pool without spawning it GameObject obj = null; if (poolBlock.prefab) { obj = (GameObject)Instantiate(poolBlock.prefab, transform.position, transform.rotation); AP_Reference oprScript = obj.GetComponent <AP_Reference>(); if (oprScript == null) { oprScript = obj.AddComponent <AP_Reference>(); } oprScript.poolScript = this; oprScript.timeSpawned = Time.time; masterPool.Add(new PoolItem(obj, oprScript)); if (createInPool == true) { pool.Push(new PoolItem(obj, oprScript)); obj.SetActive(false); obj.transform.SetParent(transform); } poolBlock.size++; } return(obj); }
public bool Despawn(AutoPool.AP_Reference script, float time) { if (script == null) { return(false); } return(script.Despawn(time)); }
public void Despawn(GameObject obj, AP_Reference oprScript) { // return an object back to this pool if (obj != null) { if (obj.transform.parent == transform) { return; } // already in pool obj.SetActive(false); obj.transform.SetParent(transform); obj.transform.localPosition = Vector3.zero; obj.transform.localRotation = Quaternion.identity; pool.Push(new PoolItem(obj, oprScript)); } if (oprScript != null) { oprScript.CancelInvoke(); } }
public PoolItem(GameObject obj, AP_Reference refScript) { this.obj = obj; this.refScript = refScript; }
public bool Despawn(AutoPool.AP_Reference script) { return(Despawn(script, -1f)); }