private void ContextOnOnEntityDestroyed(IContext context, IEntity entity1) { var entity = (TEntity)entity1; entity.RemoveOnComponentAdded(_onOnComponentAddedCache); entity.RemoveOnComponentRemoved(_onOnComponentRemovedCache); entity.RemoveOnComponentReplaced(_onOnComponentReplacedCache); if (EntityRemoved != null) { var entityKeyComp = EntitasGameEntity <TEntity> .DoGetComponent(entity, _indexLookUp.GetComponentIndex <EntityKeyComponent>()); if (entityKeyComp != null) { EntityRemoved(GetGameEntity(entity)); } var posComp = EntitasGameEntity <TEntity> .DoGetComponent(entity, _indexLookUp.GetComponentIndex <PositionComponent>()); if (posComp != null) { NotifyComponentChanged(entity1, _positionIndex, posComp, null); } } }
private IGameEntity GetGameEntity(TEntity entity) { var comp = GetOrAddGameEntityComponent(entity); if (comp.SelfAdapter == null) { comp.SelfAdapter = EntitasGameEntity <TEntity> .Allocate(entity, _indexLookUp); } return(comp.SelfAdapter); }
private EntityAdapterComponent GetOrAddGameEntityComponent(TEntity entity) { int index = _indexLookUp.GetComponentIndex <EntityAdapterComponent>(); EntityAdapterComponent comp = (EntityAdapterComponent)EntitasGameEntity <TEntity> .DoGetComponent(entity, index); if (comp == null) { comp = EntitasGameEntity <TEntity> .DoAddComponent <EntityAdapterComponent>(entity, index); comp.SelfAdapter = null; } return(comp); }