public GameObject CreateObject(bool createInPool) // true when creating an item in the pool without spawing 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.parent = transform; } poolBlock.size++; } return(obj); }
public static bool Despawn(AP_Reference script, float time) { if (script == null) { return(false); } return(script.Despawn(time)); }
void Awake() { myRigidbody = gameObject.GetComponent <Rigidbody>(); refScript = gameObject.GetComponent <AP_Reference>(); if (refScript == null) { Debug.Log(gameObject.name + ": No AP_Reference script found. Object won't despawn."); } }
public void Despawn(GameObject obj, AP_Reference oprScript) // return an object back to this pool { if (obj.transform.parent == transform) { return; } // already in pool obj.SetActive(false); obj.transform.parent = transform; obj.transform.localPosition = Vector3.zero; obj.transform.localRotation = Quaternion.identity; oprScript.CancelInvoke(); pool.Push(new PoolItem(obj, oprScript)); }
public virtual void Awake() { MF_AbstractStats sScript = null; if (transform.parent) { sScript = transform.parent.GetComponentInParent <MF_AbstractStats>(); } if (sScript) { sScript.statsScript.Add(this); } poolRefScript = gameObject.GetComponent <AP_Reference>(); if (size == 0) // Find size of object if not already defined { size = UtilityMF.FindColliderBoundsSize(transform, true); } }
public PoolItem(GameObject obj, AP_Reference refScript) { this.obj = obj; this.refScript = refScript; }
public static bool Despawn(AP_Reference script) { return(Despawn(script, -1f)); }
void Start() { poolRefScript = GetComponent <AP_Reference>(); }
protected virtual void Awake() { poolRefScript = GetComponent <AP_Reference>(); damageID = GetInstanceID(); }