コード例 #1
0
        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);
        }
コード例 #2
0
 public bool Despawn(AutoPool.AP_Reference script, float time)
 {
     if (script == null)
     {
         return(false);
     }
     return(script.Despawn(time));
 }
コード例 #3
0
        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();
            }
        }
コード例 #4
0
 public PoolItem(GameObject obj, AP_Reference refScript)
 {
     this.obj       = obj;
     this.refScript = refScript;
 }
コード例 #5
0
 public bool Despawn(AutoPool.AP_Reference script)
 {
     return(Despawn(script, -1f));
 }