コード例 #1
0
    public void ReturnToPool(Enums.PoolType poolId, GameObject param)
    {
        // TODO: The list of object will get.
        List <GameObject> objectGet;

        // TODO: Disable the gameobject.
        param.SetActive(false);

        // TODO: Set the new parent.
        param.transform.SetParent(transform);

        // TODO: Get the id.
        int id = (int)poolId;

        if (poolArray.TryGetValue(id, out objectGet))
        {
            if (object.ReferenceEquals(objectGet, null))
            {
                // TODO: Create the new list will be saved.
                objectGet = new List <GameObject> ();
            }

            // TODO: Add the gameobject to the list.
            objectGet.Add(param);

            // TODO: Set the new value.
            poolArray [id] = objectGet;
        }
        else
        {
            // TODO: add the new object.
            poolArray.Add(id, new List <GameObject> ()
            {
                param
            });
        }
    }
コード例 #2
0
    public GameObject GetFromPool(Enums.PoolType poolId)
    {
        // TODO: The param will be returned.
        GameObject paramReturn = null;

        // TODO: The list of object will get.
        List <GameObject> objectGet;

        if (poolArray.TryGetValue((int)poolId, out objectGet))
        {
            if (!object.ReferenceEquals(objectGet, null) && objectGet.Count > 0)
            {
                // TODO: Set the param return;
                paramReturn = objectGet [0];

                // TODO: Remove the first value/
                objectGet.RemoveAt(0);
            }
        }

        if (object.ReferenceEquals(paramReturn, null))
        {
            for (int i = 0; i < poolItems.Length; i++)
            {
                if (poolItems [i].poolId == poolId)
                {
                    // TODO: Create the pool item.
                    paramReturn = Instantiate(poolItems [i].poolItem);

                    break;
                }
            }
        }

        return(paramReturn);
    }