Ejemplo n.º 1
0
    public bool DespawnPool(GameObject prefab)
    {
        if (prefab == null)
        {
            return(false);
        }                                               // object wasn't defined
        AP_Pool childScript = null;

        if (poolRef.ContainsKey(prefab) == true)               // reference already created
        {
            childScript = poolRef[prefab];
        }
        else                                   // ref not yet created
        {
            childScript = MakePoolRef(prefab); // create ref
        }
        if (childScript == null)               // pool not found
        {
            return(false);
        }
        else
        {
            for (int i = 0; i < childScript.masterPool.Count; i++)
            {
                childScript.Despawn(childScript.masterPool[i].obj, childScript.masterPool[i].refScript);
            }
            return(true);
        }
    }
Ejemplo n.º 2
0
    public bool RemovePool(GameObject prefab)
    {
        if (prefab == null)
        {
            return(false);
        }                                               // object wasn't defined
        bool    result      = false;
        AP_Pool childScript = null;

        if (poolRef.ContainsKey(prefab) == true)               // reference already created
        {
            childScript = poolRef[prefab];
        }
        else                                   // ref not yet created
        {
            childScript = MakePoolRef(prefab); // create ref
        }
        if (childScript == null)               // pool not found
        {
            return(false);
        }
        else
        {
            result = DespawnPool(prefab);
            Destroy(childScript.gameObject);
            poolRef.Remove(prefab);
            return(result);
        }
    }
Ejemplo n.º 3
0
    public int GetAvailableCount(GameObject prefab)
    {
        if (prefab == null)
        {
            return(0);
        }                                           // object wasn't defined
        AP_Pool childScript = null;

        if (poolRef.ContainsKey(prefab) == true)               // reference already created
        {
            childScript = poolRef[prefab];
        }
        else                                   // ref not yet created
        {
            childScript = MakePoolRef(prefab); // create ref
        }
        if (childScript == null)               // pool not found
        {
            return(0);
        }
        else
        {
            return(childScript.pool.Count);
        }
    }
Ejemplo n.º 4
0
    public GameObject Spawn(GameObject obj, int?child, Vector3 pos, Quaternion rot, bool usePosRot)
    {
        if (obj == null)
        {
            return(null);
        }                                           // object wasn't defined
        CheckDict();

        if (poolRef.ContainsKey(obj) == true)                           // reference already created
        {
            if (poolRef[obj] != null)                                   // make sure pool still exsists
            {
                return(poolRef[obj].Spawn(child, pos, rot, usePosRot)); // create spawn
            }
            else                                                        // pool no longer exsists
            {
                poolRef.Remove(obj);                                    // remove reference
                return(null);
            }
        }
        else                                        // ref not yet created
        {
            AP_Pool childScript = MakePoolRef(obj); // create ref
            if (childScript == null)                // ref not found
            {
                return(null);
            }
            else
            {
                return(childScript.Spawn(child, pos, rot, usePosRot));                  // create spawn
            }
        }
    }
Ejemplo n.º 5
0
    AP_Pool MakePoolRef(GameObject obj)          // attempt to create and return script reference
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            AP_Pool childScript = transform.GetChild(i).GetComponent <AP_Pool>();
            if (childScript && obj == childScript.poolBlock.prefab)
            {
                poolRef.Add(obj, childScript);
                return(childScript);
            }
        }
//		Debug.Log( obj.name + ": Tried to reference object pool, but no matching pool was found." );
        return(null);
    }
Ejemplo n.º 6
0
    public void CreatePool(GameObject prefab, int size, int maxSize, AP_enum.EmptyBehavior emptyBehavior, AP_enum.MaxEmptyBehavior maxEmptyBehavior)
    {
        GameObject obj = new GameObject("Object Pool");

        obj.transform.parent        = transform;
        obj.transform.localPosition = Vector3.zero;
        obj.transform.localRotation = Quaternion.identity;
        AP_Pool script = obj.AddComponent <AP_Pool>();

        if (Application.isPlaying == true)
        {
            obj.name = prefab.name + "_pools";
            script.poolBlock.size             = size;
            script.poolBlock.maxSize          = maxSize;
            script.poolBlock.emptyBehavior    = emptyBehavior;
            script.poolBlock.maxEmptyBehavior = maxEmptyBehavior;
            script.poolBlock.prefab           = prefab;
            if (prefab)
            {
                MakePoolRef(prefab);
            }
        }
    }