示例#1
0
    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);
    }
示例#2
0
 public static bool Despawn(AP_Reference script, float time)
 {
     if (script == null)
     {
         return(false);
     }
     return(script.Despawn(time));
 }
示例#3
0
 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.");
     }
 }
示例#4
0
 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));
 }
示例#5
0
    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);
        }
    }
示例#6
0
 public PoolItem(GameObject obj, AP_Reference refScript)
 {
     this.obj       = obj;
     this.refScript = refScript;
 }
示例#7
0
 public static bool Despawn(AP_Reference script)
 {
     return(Despawn(script, -1f));
 }
示例#8
0
 void Start()
 {
     poolRefScript = GetComponent <AP_Reference>();
 }
示例#9
0
 protected virtual void Awake()
 {
     poolRefScript = GetComponent <AP_Reference>();
     damageID      = GetInstanceID();
 }