Esempio n. 1
0
    public static void DestroyEntity(Entity e, DestroyReason reason)
    {
        if (currentInstance.debugVomit)
        {
            currentInstance.Log("Destroy entity " + e + "[" + currentInstance.reverseWorldEntities[e] + "] at " + e.position + ":" + e.rotation);
        }
        currentInstance.deferredActions.Add(() => {
            if (!currentInstance.reverseWorldEntities.ContainsKey(e))
            {
                // It's possible for a thing to be destroyed twice in one tick.
                return;
            }
            e.DestroyAction(reason);

            int id = currentInstance.reverseWorldEntities[e];
            if (currentInstance.debugVomit)
            {
                currentInstance.Log("{" + currentInstance.tickID + "} Destroy entity " + e + "[" + id + "] at " + e.position + ":" + e.rotation);
            }
            currentInstance.worldEntities.Remove(id);
            currentInstance.reverseWorldEntities.Remove(e);
            currentInstance.worldEntityCache.Remove(e);
            currentInstance.worldEntityCollisionCache.Remove(e);

            if (e.GetComponent <PooledObject>() != null)
            {
                ObjectPool.For(e.GetComponent <PooledObject>().prototype).Uninstantiate(e.gameObject);
            }
            else
            {
                GameObject.Destroy(e.gameObject);
            }

            currentInstance.nDestroyedThisTick += 1;
        });
    }