Ejemplo n.º 1
0
        //单例获取IGameEntity =>comp.SelfAdapter
        private IGameEntity GetGameEntity(TEntity entity)
        {
            var comp = GetOrAddGameEntityComponent(entity);

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

            return(comp.SelfAdapter);
        }
Ejemplo n.º 2
0
        private EntityAdapterComponent GetOrAddGameEntityComponent(TEntity entity)
        {
            int index = indexLookUp.EntityAdapterComponentIndex;
            EntityAdapterComponent comp =
                (EntityAdapterComponent)EntitasGameEntity <TEntity> .DoGetComponent(entity, index);

            if (comp == null)
            {
                comp = EntitasGameEntity <TEntity> .DoAddComponent <EntityAdapterComponent>(entity, index);

                comp.SelfAdapter = null;
            }

            return(comp);
        }
Ejemplo n.º 3
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.EntityKeyComponentIndex);

                if (entityKeyComp != null)
                {
                    EntityRemoved(GetGameEntity(entity));
                }
                var posComp = EntitasGameEntity <TEntity> .DoGetComponent(entity, indexLookUp.PositionComponentIndex);

                if (posComp != null)
                {
                    NotifyComponentChanged(entity1, indexLookUp.PositionComponentIndex, posComp, null);
                }
            }
        }