Ejemplo n.º 1
0
    public void CanSpawnObjectByType()
    {
        LeanClassPool.Clear();
        var o = new TestLeanClassPool();

        LeanClassPool.Despawn(o);

        Assert.AreSame(LeanClassPool.Spawn <TestLeanClassPool>(), o);
    }
Ejemplo n.º 2
0
    public void CanSpawnLastObject()
    {
        LeanClassPool <Object> .Clear();

        var o = new Object();

        LeanClassPool <Object> .Despawn(o);

        Assert.AreSame(LeanClassPool <Object> .Spawn(), o);
    }
Ejemplo n.º 3
0
        static ChildFunc Create()
        {
            var f = LeanClassPool <ChildFunc> .Spawn();

            if (f == null)
            {
                f = new ChildFunc();
            }

            return(f);
        }
Ejemplo n.º 4
0
        /// <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));
        }
Ejemplo n.º 5
0
        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");
            }
        }
Ejemplo n.º 7
0
    public void CanNotSpawnWhenEmpty()
    {
        LeanClassPool <Object> .Clear();

        Assert.IsNull(LeanClassPool <Object> .Spawn());
    }