public void release(GameObject releasedObject, PoolableTypes objectType)
    {
        if (activeGameObjects.Contains(releasedObject))
        {
            List <GameObject> instanciatedGameObjectsList;

            if (disabledGameObjects.TryGetValue(objectType, out instanciatedGameObjectsList))
            {
                instanciatedGameObjectsList.Add(releasedObject);
            }

            IPoolableObject ipo = releasedObject.GetComponent <IPoolableObject>();

            if (ipo == null)
            {
                ipo = releasedObject.GetComponentInChildren <IPoolableObject>();
            }

            ipo.OnRelease();

            activeGameObjects.Remove(releasedObject);
            if (objectType == PoolableTypes.Enemy)
            {
                enemyList.Remove(releasedObject);
            }
            else if (objectType == PoolableTypes.PlayerBot)
            {
                playerBotList.Remove(releasedObject);
            }

            releasedObject.SetActive(false);
        }
    }
Beispiel #2
0
    public void SpawnProjectile(PoolableTypes type)
    {
        // The object returned from the pool.
        GameObject obj;

        obj = PoolManager.Instance.GetFromPool(type);
    }
Beispiel #3
0
    // add this type of object into the pool.
    public void AddToPool(GameObject obj, PoolableTypes poolableType)
    {
        if (!poolDictionary.ContainsKey(poolableType))
        {
            Debug.LogError("Dictionary does not contain the given poolableType");
            return;
        }

        poolDictionary[poolableType].AddToPool(obj);
    }
Beispiel #4
0
    // bring this type of object from pool.
    public GameObject GetFromPool(PoolableTypes poolableType)
    {
        if (!poolDictionary.ContainsKey(poolableType))
        {
            Debug.LogError("Dictionary does not contain the given poolableType");
            return(null);
        }

        return(poolDictionary[poolableType].GetFromPool());
    }
    // bring this type of object from pool.
    public GameObject GetFromPool(PoolableTypes poolableType)
    {
        if (!poolDictionary.ContainsKey(poolableType))
        {
            Debug.LogError("Dictionary does not contain the given poolableType");
            return(null);
        }

        GameObject obj = poolDictionary[poolableType].GetFromPool();

        activeObjects[poolableType].Enqueue(obj);
        return(obj);
    }
Beispiel #6
0
    public bool areObjectsRemaining(PoolableTypes poolableType)
    {
        List <GameObject> instanciatedGameObjectsList;
        bool objectsRemaining = false;

        if (disabledGameObjects.TryGetValue(poolableType, out instanciatedGameObjectsList))
        {
            if (instanciatedGameObjectsList.Count > 0)
            {
                objectsRemaining = true;
            }
        }

        return(objectsRemaining);
    }
    public GameObject get(PoolableTypes objectType, Transform locationData = null, Guid parentGuid = new Guid())
    {
        List <GameObject> instanciatedGameObjectsList;

        if (disabledGameObjects.TryGetValue(objectType, out instanciatedGameObjectsList))
        {
            int lastIndex = instanciatedGameObjectsList.Count - 1;

            GameObject go = instanciatedGameObjectsList[lastIndex];
            instanciatedGameObjectsList.RemoveAt(lastIndex);
            activeGameObjects.Add(go);
            IPoolableObject ipo = go.GetComponent <IPoolableObject>();

            if (ipo == null)
            {
                ipo = go.GetComponentInChildren <IPoolableObject>();
            }

            if (locationData != null)
            {
                go.transform.position = locationData.position;
                go.transform.rotation = locationData.rotation;
                go.transform.forward  = locationData.forward;
            }

            ipo.OnPoolCreation();

            if (parentGuid != Guid.Empty)
            {
                Guid objectId = Guid.Empty;
                Guid getId;

                Bot botScript = go.GetComponent <Bot>();
                if (botScript != null)
                {
                    objectId = botScript.Id;
                }
                else
                {
                    SavableObject savableObjectScript = go.GetComponent <SavableObject>();
                    if (savableObjectScript != null)
                    {
                        objectId = savableObjectScript.Id;
                    }
                }

                if (objectId != Guid.Empty &&
                    !GameObjectStateManager.Instance.ParentIds.TryGetValue(objectId, out getId))
                {
                    GameObjectStateManager.Instance.ParentIds.Add(objectId, parentGuid);
                }
            }

            go.SetActive(true);

            if (objectType == PoolableTypes.Enemy)
            {
                enemyList.Add(go);
            }
            else if (objectType == PoolableTypes.PlayerBot)
            {
                playerBotList.Add(go);
            }

            return(go);
        }

        return(null);
    }