Ejemplo n.º 1
0
        public Entity Create(UnitType type, Vector2 pos, float radius, MoveComponent move = null)
        {
            var unitObj = new GameObject("Unit");

            Entity entity = _entityPool.Create();

            entity.AddListener(_view.Add <PositionView>(unitObj))
            .AddListener(_view.Add <SpriteRendererView>(unitObj))
            .AddListener(_view.Add <SpriteRadiusView>(unitObj));

            entity.Add <UnitComponent>().type               = type;
            entity.Add <GameObjectComponent>().obj          = unitObj;
            entity.Add <PositionComponent>().Position       = pos;
            entity.Add <RadiusComponent>().Radius           = radius;
            entity.Add <BoardSqueezeBoundComponent>().bound = _gameConfig.GetBoardSqueezeRadius(radius);

            var spritePath = type == UnitType.Red ? ResourcesAssets.Sprites_unitRed : ResourcesAssets.Sprites_unitBlue;

            entity.Add <SpriteComponent>()
            .Set(_sprites[spritePath]);

            if (move != null)
            {
                entity.Add <MoveComponent>().Set(move.moveDirection, move.speed);
            }

            return(entity);
        }
Ejemplo n.º 2
0
        void IAttachContext.Attach(Context context)
        {
            _identityPool = context.services.pool.Provide <IdentityComponent>();

            _identityPool.Create();
        }