Material Clustering Benchmark
ObjectPoolMaxAssert.cs
Go to the documentation of this file.
1using static Diagnostics;
2
3public class ObjectPoolMaxAssert<T> : UnityEngine.Pool.IObjectPool<T> where T : class
4{
5 private readonly UnityEngine.Pool.ObjectPool<T> pool;
6
7 public readonly int maxActive;
8
9 private string exceededNumObjectsMsg;
10
11 public ObjectPoolMaxAssert(System.Func<T> createFunc, int maxActive)
12 {
13 this.maxActive = maxActive;
14 this.pool = new UnityEngine.Pool.ObjectPool<T>(createFunc);
15 this.exceededNumObjectsMsg =
16 $"Exceeded maximum number of objects in the pool ({typeof(T)}).";
17 }
18
19 public T Get()
20 {
21 T obj = this.pool.Get();
22 Assert(this.pool.CountActive <= this.maxActive, exceededNumObjectsMsg);
23 return obj;
24 }
25
26 public UnityEngine.Pool.PooledObject<T> Get(out T obj)
27 {
28 UnityEngine.Pool.PooledObject<T> pooledObj = this.pool.Get(out obj);
29 Assert(this.pool.CountActive <= this.maxActive, exceededNumObjectsMsg);
30 return pooledObj;
31 }
32
33 public void Release(T obj)
34 {
35 this.pool.Release(obj);
36 }
37
38 public void Clear()
39 {
40 this.pool.Clear();
41 }
42
43 public int CountInactive => this.pool.CountInactive;
44}
UnityEngine.Pool.PooledObject< T > Get(out T obj)
ObjectPoolMaxAssert(System.Func< T > createFunc, int maxActive)