public IEnumerator ObjectCountShrinksToTheNumberOfInstances() { var numberOfInstances = 3; var pool = CreatePool(numberOfInstances); yield return(pool.PreloadAsync().ToYieldInstruction()); yield return(pool.PreactivateAsync().ToYieldInstruction()); // create twice object var array = new PoolManagedBehaviour[numberOfInstances * 2]; for (int i = 0; i < numberOfInstances * 2; i++) { array[i] = pool.Rent(); } foreach (var t in array) { pool.Return(t); } pool.Count.Is(numberOfInstances * 2); pool.Shrink(); pool.Count.Is(numberOfInstances); }
IObjectPool <PoolManagedBehaviour> CreatePool(int numberOfInstances) { var go = new GameObject(); PoolManagedBehaviour prefab = go.AddComponent <TestBehaviour>(); var config = new ObjectPoolConfig(numberOfInstances, Mathf.Max(numberOfInstances, 1)); return(base.CreatePool(prefab, config)); }
public IEnumerator ObjectPoolCanShrink() { var numberOfInstances = 1; var pool = CreatePool(numberOfInstances: numberOfInstances); yield return(pool.PreloadAsync().ToYieldInstruction()); yield return(pool.PreactivateAsync().ToYieldInstruction()); // create twice objects var array = new PoolManagedBehaviour[numberOfInstances * 2]; for (var i = 0; i < array.Length; i++) { array[i] = pool.Rent(); } foreach (var o in array) { pool.Return(o); } pool.Shrink(); }