// 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");
            }
        }
Пример #2
0
    public void CanNotSpawnWhenEmpty()
    {
        LeanClassPool <Object> .Clear();

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