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
4 changes: 2 additions & 2 deletions Assets/ObjectPool/Editor/PoolManagerEditor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using UnityEngine;
using System.Collections;
using ObjectPool.Scripts;
using UnityEditor;

namespace GameObjectPool
Expand All @@ -14,7 +14,7 @@ public override void OnInspectorGUI()

if (GUILayout.Button("Add Pool"))
{
poolManager.m_pool.Add(new PoolSettings());
poolManager.mPool.Add(new PoolSettings());
}

if (GUILayout.Button("Regenerate pools"))
Expand Down
7 changes: 3 additions & 4 deletions Assets/ObjectPool/Example/Scenes/Example.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2817,20 +2817,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0dda56d895cffe44dadc9670de012a1b, type: 3}
m_Name:
m_EditorClassIdentifier:
debug: 1
m_pool:
mPool:
- name: SpherePool
prefab: {fileID: 1019533563834558, guid: a190bad6138ae9444a900486a95d3d30, type: 3}
startingItemCount: 10
maxItemCount: 10
parent: {fileID: 1906366004}
parent: {fileID: 0}
allowUnrestrictedGrowth: 0
showAnalytics: 0
- name: CubePool
prefab: {fileID: 1512229642624436, guid: 7aa29bc7804e6b94bb43136a04e2f70e, type: 3}
startingItemCount: 10
maxItemCount: 10
parent: {fileID: 1906366004}
parent: {fileID: 0}
allowUnrestrictedGrowth: 1
showAnalytics: 0
showAnalytics: 0
Expand Down
49 changes: 49 additions & 0 deletions Assets/ObjectPool/Example/Scripts/BenchMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using UnityEngine;

namespace ObjectPool.Example.Scripts
{
internal class BenchMarker : MonoBehaviour
{
#region Fields
private int _maxRuns;
private string _report;
private float[] _results;
private bool _runDiagnostics;
protected float runStart;
private float _total;
private int _totalRuns;
#endregion

protected bool RunDiagnostics => _totalRuns < _maxRuns && _runDiagnostics;

private void OnGUI()
{
if (_report != null)
GUI.Label(
new Rect(10, 90, 600, 20),
_report
);
}

protected void StartDiagnostics(int maxRuns)
{
_maxRuns = maxRuns;
_runDiagnostics = true;
_results = new float[maxRuns];
_totalRuns = 0;
_total = 0;
}


protected void Run()
{
var t = Time.realtimeSinceStartup - runStart;
_results[_totalRuns] = t;
_total += _results[_totalRuns];
_report = "Average runtime (" + (_totalRuns + 1) + " iterations): " + _total / _totalRuns +
" with a total runtime of " + _total;
_totalRuns += 1;
if (_totalRuns >= _maxRuns) _runDiagnostics = false;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 0 additions & 49 deletions Assets/ObjectPool/Example/Scripts/Benchmarker.cs

This file was deleted.

24 changes: 13 additions & 11 deletions Assets/ObjectPool/Example/Scripts/PoolDiagnostics.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
using ObjectPool.Scripts;
using UnityEngine;

namespace GameObjectPool
namespace ObjectPool.Example.Scripts
{
class PoolDiagnostics : Benchmarker
internal class PoolDiagnostics : BenchMarker
{
public string poolName = "";

void Update()
private void Update()
{
if (Input.GetMouseButton(0)) StartDiagnostics(5000);
if (RunDiagnostics) Run();
}

new protected void Run()
private new void Run()
{
runstart = Time.realtimeSinceStartup;
runStart = Time.realtimeSinceStartup;
var obj = PoolManager.Get(poolName);
base.Run();
if (obj == null) return;
obj.transform.position = new Vector3(
Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
Camera.main.ScreenToWorldPoint(Input.mousePosition).y,
0
);
if (Camera.main != null)
obj.transform.position = new Vector3(
Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
Camera.main.ScreenToWorldPoint(Input.mousePosition).y,
0
);
}
}
}
}
20 changes: 10 additions & 10 deletions Assets/ObjectPool/Example/Scripts/Shape.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using UnityEngine;

namespace GameObjectPool
namespace ObjectPool.Example.Scripts
{
class Shape : MonoBehaviour
internal class Shape : MonoBehaviour
{
public float timeOutSpeed = 0.2f;
private float timeout = 0;
private float _timeout;

void Awake()
private void Awake()
{
timeout = 0;
_timeout = 0;
}

void Update()
private void Update()
{
timeout += Time.deltaTime * timeOutSpeed;
_timeout += Time.deltaTime * timeOutSpeed;

if (timeout >= 1f)
if (_timeout >= 1f)
{
timeout = 0;
_timeout = 0;
transform.gameObject.SetActive(false);
}
}
}
}
}
35 changes: 15 additions & 20 deletions Assets/ObjectPool/Example/Scripts/ShapeManager.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using ObjectPool.Scripts;
using UnityEngine;

namespace GameObjectPool
namespace ObjectPool.Example.Scripts
{
/// <summary>
/// This class is meant to demonstrate how to use an object pool.
/// Use the same techniques found in this class wherever you need to spawn a game object from the Object Pool.
/// This class is meant to demonstrate how to use an object pool.
/// Use the same techniques found in this class wherever you need to spawn a game object from the Object Pool.
/// </summary>
class ShapeManager : MonoBehaviour
internal class ShapeManager : MonoBehaviour
{
const string cubePool = "CubePool";
const string spherePool = "SpherePool";
private const string CubePool = "CubePool";
private const string SpherePool = "SpherePool";
public GameObject spherePrefab;

// Use the following code to add a pool at run-time (not recommended)
Expand All @@ -29,29 +30,23 @@ private void Awake()
*/

/// <summary>
/// Listen for mouse clicks and get an object from the appropriate PoolManager.
/// After an object is returned from the PoolManager, it is passed to the SetPosition method.
/// These same techniques could be used for things such as FPS bullet spawners in an FPS game.
/// Listen for mouse clicks and get an object from the appropriate PoolManager.
/// After an object is returned from the PoolManager, it is passed to the SetPosition method.
/// These same techniques could be used for things such as FPS bullet spawners in an FPS game.
/// </summary>
void Update()
private void Update()
{
Vector3 location = new Vector3(
var location = new Vector3(
Camera.main.ScreenToWorldPoint(Input.mousePosition).x,
Camera.main.ScreenToWorldPoint(Input.mousePosition).y,
0
);

// On left mouse click, spawn a cube object from the cube pool.
if (Input.GetMouseButton(0))
{
PoolManager.Get(cubePool, location, Random.rotation);
}
if (Input.GetMouseButton(0)) PoolManager.Get(CubePool, location, Random.rotation);

// On right mouse click, spawn a sphere object from the sphere pool.
if (Input.GetMouseButton(1))
{
PoolManager.Get(spherePool, location, Random.rotation);
}
if (Input.GetMouseButton(1)) PoolManager.Get(SpherePool, location, Random.rotation);
}
}
}
}
Loading