public void CanSpawnObjectByType() { LeanClassPool.Clear(); var o = new TestLeanClassPool(); LeanClassPool.Despawn(o); Assert.AreSame(LeanClassPool.Spawn <TestLeanClassPool>(), o); }
public void CanSpawnLastObject() { LeanClassPool <Object> .Clear(); var o = new Object(); LeanClassPool <Object> .Despawn(o); Assert.AreSame(LeanClassPool <Object> .Spawn(), o); }
static ChildFunc Create() { var f = LeanClassPool <ChildFunc> .Spawn(); if (f == null) { f = new ChildFunc(); } return(f); }
/// <summary> /// Applies a function to each item in coll, in sequence /// The functions are wrapped in ChildFunc objects since C# does not /// support conversion from method group to object /// The last parameter must be UAsyncFinalFunc /// </summary> /// <param name="args">Arguments.</param> public static UInt64 EachSeries <T> (params object[] args) { _Initialize(); AsyncTask asyncTask = LeanClassPool.Spawn <AsyncEachSeries <T> > (); if (asyncTask == null) { asyncTask = new AsyncEachSeries <T> (); } asyncTask.Execute(args); return(PushIAsyncTasks(asyncTask)); }
public static UAsyncFinalFunc Create(Action <object> action) { if (action == null) { throw new ArgumentException(); } var finalFunc = LeanClassPool <UAsyncFinalFunc> .Spawn(); if (finalFunc == null) { finalFunc = new UAsyncFinalFunc(); } finalFunc.action2 = action; return(finalFunc); }
// This will despawn a clone and add it to the cache public void FastDespawn(GameObject clone, float delay = 0.0f) { if (clone != null) { // Delay the despawn? if (delay > 0.0f) { // Make sure we only add it to the marked object list once if (delayedDestructions.Exists(m => m.Clone == clone) == false) { var delayedDestruction = LeanClassPool <DelayedDestruction> .Spawn() ?? new DelayedDestruction(); delayedDestruction.Clone = clone; delayedDestruction.Life = delay; delayedDestructions.Add(delayedDestruction); } } // Despawn now? else { // Add it to the cache cache.Add(clone); spawned.Remove(clone); // Messages? SendNotification(clone, "OnDespawn"); // Deactivate it clone.SetActive(false); clone.transform.SetParent(transform, false); } } else { Debug.LogWarning("Attempting to despawn a null clone"); } }
public void CanNotSpawnWhenEmpty() { LeanClassPool <Object> .Clear(); Assert.IsNull(LeanClassPool <Object> .Spawn()); }