コード例 #1
0
    private static ObjectPool GetObjectPool(ObstacleRecycle item)
    {
        ObjectPool objectPool = null;

        if (objectPools.ContainsKey(item))
        {
            objectPool = objectPools[item];
        }
        else
        {
            var poolContainer = new GameObject(item.gameObject.name + "ObjectPool");
            objectPool = poolContainer.AddComponent <ObjectPool>();
            objectPool.objectPrefab = item;

            objectPools.Add(item, objectPool);
        }
        return(objectPool);
    }
コード例 #2
0
    public ObstacleRecycle GetNextObstacle(Vector3 pos)
    {
        ObstacleRecycle obstacle = null;

        foreach (var item in obstaclePool)
        {
            if (item.gameObject.activeSelf != true)
            {
                obstacle = item;
                obstacle.transform.position = pos;
            }
        }

        if (obstacle == null)
        {
            obstacle = CreateNewObstacle(pos);
        }

        obstacle.Revive();

        return(obstacle);
    }