public override void OnEntityDestroy(Context f, Lockstep.UnsafeECS.Entity *entity) { if (_id2GameObject.TryGetValue(entity->LocalId, out var uEntity)) { _entityManager.DestroyEntity(uEntity); _id2GameObject.Remove(entity->LocalId); } }
public void OnEntityDestroy(Context f, Lockstep.UnsafeECS.Entity *pEntity) { if (_id2EntityView.TryGetValue(pEntity->LocalId, out var uView)) { // ReSharper disable once Unity.NoNullPropogation uView?.OnUnbindEntity(); uView?.UnbindEntity(); _id2EntityView.Remove(pEntity->LocalId); } if (_id2UnityEntity.TryGetValue(pEntity->LocalId, out var uEntity)) { _entityManager.DestroyEntity(uEntity); _id2UnityEntity.Remove(pEntity->LocalId); } }
public void DestroyEntity(NativeArray <Entity> entities) { m_Manager.DestroyEntity(entities); }
/// <summary> /// Play back all recorded operations against an entity manager. /// </summary> /// <param name="mgr">The entity manager that will receive the operations</param> public void Playback(EntityManager mgr) { if (mgr == null) { throw new NullReferenceException($"{nameof(mgr)} cannot be null"); } EnforceSingleThreadOwnership(); var head = m_Data->m_Head; var lastEntity = new Entity(); while (head != null) { var off = 0; var buf = ((byte *)head) + sizeof(Chunk); while (off < head->Used) { var header = (BasicCommand *)(buf + off); switch ((Command)header->CommandType) { case Command.DestroyEntityExplicit: mgr.DestroyEntity(((EntityCommand *)header)->Entity); break; case Command.AddComponentExplicit: { var cmd = (EntityComponentCommand *)header; var componentType = (ComponentType)TypeManager.GetType(cmd->ComponentTypeIndex); mgr.AddComponent(cmd->Header.Entity, componentType); mgr.SetComponentRaw(cmd->Header.Entity, cmd->ComponentTypeIndex, (cmd + 1), cmd->ComponentSize); } break; case Command.RemoveComponentExplicit: { var cmd = (EntityComponentCommand *)header; mgr.RemoveComponent(cmd->Header.Entity, TypeManager.GetType(cmd->ComponentTypeIndex)); } break; case Command.SetComponentExplicit: { var cmd = (EntityComponentCommand *)header; mgr.SetComponentRaw(cmd->Header.Entity, cmd->ComponentTypeIndex, (cmd + 1), cmd->ComponentSize); } break; case Command.CreateEntityImplicit: { var cmd = (CreateCommand *)header; if (cmd->Archetype.Valid) { lastEntity = mgr.CreateEntity(cmd->Archetype); } else { lastEntity = mgr.CreateEntity(); } break; } case Command.AddComponentImplicit: { var cmd = (EntityComponentCommand *)header; var componentType = (ComponentType)TypeManager.GetType(cmd->ComponentTypeIndex); mgr.AddComponent(lastEntity, componentType); mgr.SetComponentRaw(lastEntity, cmd->ComponentTypeIndex, (cmd + 1), cmd->ComponentSize); } break; case Command.SetComponentImplicit: { var cmd = (EntityComponentCommand *)header; //var componentType = (ComponentType)TypeManager.GetType(cmd->ComponentTypeIndex); mgr.SetComponentRaw(lastEntity, cmd->ComponentTypeIndex, (cmd + 1), cmd->ComponentSize); } break; } off += header->TotalSize; } head = head->Next; } }
protected override void OnUpdate() { EntityManager.DestroyEntity(onDestroyMessageQuery); }