Pools
Pool GameObjects for Performance
PoolMonitor.cs
1 // With thanks to Jason Weimann -- jason@unity3d.college
2 
3 using UnityEngine;
4 
5 namespace Askowl {
6  /// <a href="http://bit.ly/2BQH2pA"></a> <inheritdoc />
7  public class PoolMonitor : MonoBehaviour {
8  /// <a href="http://bit.ly/2BScbco"></a>
9  public bool PoolOnDisable;
10 
11  /// <a href="http://bit.ly/2BQH2pA"></a>
12  public bool InPool;
13 
14  /// <a href="http://bit.ly/2BQH2pA"></a>
15  public bool OkToPool = true;
16 
17  /// <a href="http://bit.ly/2BQvdQi"></a>
18  public string MasterName;
19 
20  /// <a href="http://bit.ly/2E0ZmxS"></a>
21  public Transform PoolRoot;
22 
23  private void OnDisable() {
24  OkToPool = true;
25  if (PoolOnDisable && !InPool) Pool.Return(gameObject);
26  }
27 
28  private void OnEnable() {
29  if (InPool || !PoolOnDisable) return;
30 
31  OkToPool = false;
32  Log.Error($"Pooled '{gameObject.name}' should not be reused");
33  }
34  }
35 }
MonoBehaviour to provide pooling functionality for child GameObjects. To be eligible they must be cre...
Definition: Pool.cs:8
Definition: Pool.cs:6
Transform PoolRoot
Definition: PoolMonitor.cs:21
static void Return(GameObject clone)
Give an object created by Acquire in any pool, return it to the pool for reuse. Only needed if poolOn...
Definition: Pool.cs:87