Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Assets/UnityPooler/Scripts/GameObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class GameObjectPool
/// <param name="objToCreateFrom">The prefab or GameObject that we
/// want a duplicated object of.</param>
/// <returns>A GameObject from the object pool.</returns>
public static GameObject GetObj(GameObject objToCreateFrom)
public static GameObject GetObj(GameObject objToCreateFrom, bool gameObjectActiveState = true)
{
PoolableGameObject poolable = objToCreateFrom.GetComponent<PoolableGameObject>();

Expand All @@ -30,7 +30,7 @@ public static GameObject GetObj(GameObject objToCreateFrom)
return null;
}

return poolable.Get().gameObject;
return poolable.Get(gameObjectActiveState).gameObject;
}

/// <summary>
Expand Down Expand Up @@ -112,9 +112,9 @@ public static void IncrementPoolWithObj(GameObject objToInc)
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static GameObject Get(this GameObject obj)
public static GameObject Get(this GameObject obj, bool gameObjectActiveState = true)
{
return GetObj(obj);
return GetObj(obj, gameObjectActiveState);
}

/// <summary>
Expand Down
14 changes: 8 additions & 6 deletions Assets/UnityPooler/Scripts/PoolableGameObject.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.SceneManagement;

Expand Down Expand Up @@ -121,7 +121,7 @@ public void Release()
transform.SetParent(container, false);
gameObject.SetActive(false);
_originalObject._pooledObjs.Push(this);
_numOfActiveObjs--;
_originalObject._numOfActiveObjs--;
}

/// <summary>
Expand Down Expand Up @@ -234,8 +234,8 @@ public void ReleaseObjectsAndClearPool()
[System.NonSerialized]
private bool _initialized;

[System.NonSerialized]
private IGameObjectPoolable[] _poolables;
//[System.NonSerialized]
//private IGameObjectPoolable[] _poolables;

/// <summary>
/// The function that will be called for reuse on MonoBehaviours. Change this if it conflicts.
Expand Down Expand Up @@ -369,7 +369,7 @@ private void SendCreationMessage(PoolableGameObject newObj)
onObjectCreation(newObj.gameObject);
}

_poolables = GetComponentsInChildren<IGameObjectPoolable>(true);
var _poolables = newObj.GetComponentsInChildren<IGameObjectPoolable>(true);

for (int i = 0; i < _poolables.Length; i++)
{
Expand Down Expand Up @@ -397,6 +397,8 @@ private PoolableGameObject ReuseObject()
}
while (objToUse == null || objToUse.gameObject == null || !objToUse._isActive);

var _poolables = objToUse.GetComponentsInChildren<IGameObjectPoolable>(true);

for (int i = 0; i < _poolables.Length; i++)
{
_poolables[i].OnObjectReused();
Expand Down Expand Up @@ -472,4 +474,4 @@ private void OnDestroy()

#endregion
}
}
}