예제 #1
0
        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);
                }
            }
        }
예제 #2
0
        private IGameEntity GetGameEntity(TEntity entity)
        {
            var comp = GetOrAddGameEntityComponent(entity);

            if (comp.SelfAdapter == null)
            {
                comp.SelfAdapter = EntitasGameEntity <TEntity> .Allocate(entity, _indexLookUp);
            }

            return(comp.SelfAdapter);
        }
예제 #3
0
        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);
        }