Beispiel #1
0
 private void GrowPool(PoolStruct a_Pool)
 {
     for (int i = 0; i < a_Pool.m_Size; i++)
     {
         CreatePooledObject(a_Pool.m_Prefab);
     }
 }
Beispiel #2
0
    //create other poolobject if the pool doesn't have any free ones.
    //This is just for safety of the runtime, but will require to change it in editor mode
    private GameObject DynamicGrowPool(PoolStruct a_Pool)
    {
        Debug.LogErrorFormat("Pool Too Small: The Pool {0} is not big enough, Creating {1} more PooledObject! Increments the pool size!", a_Pool.m_Prefab.name, a_Pool.m_Size);

        GrowPool(a_Pool);
        return(GetObjectFromPool(a_Pool.m_Prefab));
    }
Beispiel #3
0
 public Pooler(PoolStruct _object, Transform _parentTransform)
 {
     ID              = _object.ID;
     pooledData      = _object;
     parentTransform = _parentTransform;
     PopulatePool();
 }
    private void DrawPrefabField(PoolStruct _currentItem)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Prefab");

        _currentItem.Prefab = (PoolObjectBase)EditorGUILayout.ObjectField(_currentItem.Prefab, typeof(PoolObjectBase), false);
        EditorGUILayout.EndHorizontal();
    }
    private void DrawQuantityField(PoolStruct _currentItem)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Quantity");

        _currentItem.Quantity = EditorGUILayout.IntField(_currentItem.Quantity);

        EditorGUILayout.EndHorizontal();
    }
    private void DrawIDField(PoolStruct _currentItem)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("ID");

        _currentItem.ID = EditorGUILayout.TextField(_currentItem.ID);

        EditorGUILayout.EndHorizontal();
    }
    private void DrawObjectRetrieveStateField(PoolStruct _currentItem)
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Status on retrieve");

        _currentItem.ObjectStateOnRetrieve = EditorGUILayout.Toggle(_currentItem.ObjectStateOnRetrieve);

        EditorGUILayout.EndHorizontal();
    }
Beispiel #8
0
 private void CreatePools()
 {
     for (int i = 0; i < m_Pools.Count; i++)
     {
         PoolStruct pool = m_Pools[i];
         if (IsValidPoolStruct(pool))
         {
             m_PoolsObjects.Add(pool.m_Prefab, new List <GameObject>());
             m_PoolsActiveObjects.Add(pool.m_Prefab, new List <GameObject>());
             GrowPool(m_Pools[i]);
         }
     }
 }
Beispiel #9
0
    //Manually return a PooledObject.
    public void ReturnedPooledObject(PooledObject a_PooledObject, GameObject a_PoolOwner)
    {
        PoolStruct pool = GetPoolStruct(a_PooledObject.gameObject);

        if (m_PoolsActiveObjects.ContainsKey(a_PooledObject.PoolOwner))
        {
            List <GameObject> activeObjects = m_PoolsActiveObjects[a_PoolOwner];

            if (activeObjects.Count != 0)
            {
                activeObjects.Remove(a_PooledObject.gameObject);
            }
        }
    }
Beispiel #10
0
    //Get the oldest pooledobject to re-use it for a new one
    private GameObject UseFirstActivePooledObject(PoolStruct a_Pool)
    {
        List <GameObject> activeObjects = new List <GameObject>();

        m_PoolsActiveObjects.TryGetValue(a_Pool.m_Prefab, out activeObjects);

        if (activeObjects.Count != 0)
        {
            GameObject firstElement = activeObjects[0];
            activeObjects.RemoveAt(0);
            return(firstElement);
        }

        return(null);
    }
Beispiel #11
0
    //If there's no inactive poolObject -> Catch Action : Get oldest active pooledObject or DynamicSafeGrowPool
    private GameObject NotEnoughPooledObject(GameObject a_Prefab)
    {
        PoolStruct pool = GetPoolStruct(a_Prefab);

        if (IsValidPoolStruct(pool))
        {
            if (pool.m_LimitReachUseActiveObject)
            {
                return(UseFirstActivePooledObject(pool));
            }
            else
            {
                return(DynamicGrowPool(pool));
            }
        }

        return(null);
    }
    public override void OnInspectorGUI()
    {
        _target = (PoolManager)target;

        EditorGUILayout.ObjectField("Script", MonoScript.FromMonoBehaviour((PoolManager)target), typeof(PoolManager), false);

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        /// Creation of the list Details
        for (int i = 0; i < _target.ObjectsToPool.Count; i++)
        {
            PoolStruct _currentItem = _target.ObjectsToPool[i];

            //////////////////////////////////////////////
            // Start of the object, with ID and remove button

            EditorGUILayout.BeginVertical("Box");
            EditorGUILayout.BeginHorizontal();


            GUILayout.Label("", GUILayout.Width(20f));
            _currentItem.inspectorExplandeToggle = EditorGUILayout.Foldout(_currentItem.inspectorExplandeToggle, _currentItem.ID, _currentItem.inspectorExplandeToggle);


            if (GUILayout.Button("Remove", GUILayout.Width(100f)))
            {
                _target.ObjectsToPool.Remove(_currentItem);
                break;
            }
            GUILayout.Label("", GUILayout.Width(20f));

            EditorGUILayout.EndHorizontal();


            if (_currentItem.inspectorExplandeToggle)
            {
                EditorGUILayout.Space();
                /////////////////////////////////////////////////
                // Draw the details for each item of the list
                DrawIDField(_currentItem);
                DrawPrefabField(_currentItem);
                DrawQuantityField(_currentItem);
                DrawObjectRetrieveStateField(_currentItem);

                EditorGUILayout.Space();
            }
            EditorGUILayout.Space();

            EditorGUILayout.EndVertical();
            // Space to the next item of the list
            EditorGUILayout.Space();
        }

        ///////////////////////////////////

        if (GUILayout.Button("Add"))
        {
            PoolStruct newPoolStruct = new PoolStruct();
            newPoolStruct.inspectorExplandeToggle = true;
            _target.ObjectsToPool.Add(newPoolStruct);
        }

        EditorUtility.SetDirty(_target);
    }
Beispiel #13
0
 //Verify if the struct does have a prefab otherwise, it's a invalid struct
 private bool IsValidPoolStruct(PoolStruct a_Pool)
 {
     return(a_Pool.m_Prefab != null);
 }