/// <summary> /// Returns the first inactive object in the pool. /// If this pool is allowed to grow, it will create a new object if no inactive ones are found. /// </summary> /// <returns>OSPObject.</returns> public OSPObject GetPooledObject() { for (int i = 0; i < Pool.Count; ++i) { if (!Pool[i].gameObject.activeInHierarchy) { return(Pool[i]); } } if (CanGrow) { OSPObject newObject = PooledObject.CreateNewInstance(true); TempPool.Add(newObject); return(newObject); } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="OSPPool"/> class. /// This initializes any lists and adds an amount equal to the InitialSize variable to the pool. /// </summary> /// <param name="pooledObject">The pooled object.</param> public OSPPool(OSPObject pooledObject) { PooledObject = pooledObject; ObjectID = pooledObject.ObjectID; InitialSize = pooledObject.PoolAmount; if (InitialSize < 1) { InitialSize = 1; } TempPool = new List <OSPObject>(); Pool = new List <OSPObject>(); Pool.Add(PooledObject); for (int i = 0; i < (InitialSize - 1); ++i) { OSPObject newObject = PooledObject.CreateNewInstance(false); Pool.Add(newObject); } }