예제 #1
0
        public void Init()
        {
            for (int row = 0; row < _configuration.LevelHeight; row++)
            {
                for (int column = 0; column < _configuration.LevelWidth; column++)
                {
                    EcsEntity  cellEntity = _world.NewEntity();
                    Vector2Int position   = new Vector2Int(column, row);
                    cellEntity.Set <Vector2Int>() = position;

                    bool hasChain = true;
                    int  tryCount = 0;

                    _gameField.Cells.Add(position, cellEntity);

                    while (hasChain && tryCount < 100)
                    {
                        tryCount++;

                        float             random        = Random.Range(0f, 100f);
                        CellConfiguration configuration = _configuration.CellConfigurations.Where(c => c.CheckInSpawnRabge(random)).First();

                        cellEntity.Set <Cell>().Configuration = configuration;

                        hasChain = GameFieldAnalyst.CheckCellInChain(_gameField.Cells, _configuration, position);
                    }
                }
            }
        }
        public void Run()
        {
            if (_tag.IsEmpty())
            {
                return;
            }

            foreach (var i in _players)
            {
                if (_playerApi.PlayerData.TryGetValue(_players.Get1[i].Name, out Player p))
                {
                    _players.Get1[i].HP    = p.HP;
                    _players.Get1[i].Power = p.Power;
                    if (_players.Get1[i].Location != p.Location)
                    {
                        _players.Get1[i].Location = p.Location;
                        _players.Entities[i].Set <UpdatePlayerPointTag>();
                    }
                }
                else
                {
                    if (_players.Get1[i].Name.Equals(_playerApi.PlayerName))
                    {
                        UICoreECS.ShowScreenTag screen = _world.NewEntity().Set <UICoreECS.ShowScreenTag>();
                        screen.ID    = 2;
                        screen.Layer = 0;
                        UnityEngine.PlayerPrefs.DeleteKey("token");
                        UnityEngine.PlayerPrefs.DeleteKey("username");
                        UnityEngine.PlayerPrefs.Save();
                    }
                    EcsEntity explosionEntity = _world.NewEntity();

                    Positioning.Components.Position pos = explosionEntity.Set <Positioning.Components.Position>();
                    pos.Point = _players.Entities[i].Get <Positioning.Components.Position>().Point;
                    explosionEntity.Set <AllocateView>().id = "Explosion";
                    _players.Entities[i].Destroy();
                }
            }

            foreach (var i in _user)
            {
                if (_user.Get2[i].HP <= 0)
                {
                    EcsEntity explosionEntity = _world.NewEntity();

                    Positioning.Components.Position pos = explosionEntity.Set <Positioning.Components.Position>();
                    pos.Point = _user.Entities[i].Get <Positioning.Components.Position>().Point;
                    explosionEntity.Set <AllocateView>().id = "Explosion";

                    UICoreECS.ShowScreenTag screen = _world.NewEntity().Set <UICoreECS.ShowScreenTag>();
                    screen.ID    = 2;
                    screen.Layer = 0;
                    UnityEngine.PlayerPrefs.DeleteKey("token");
                    UnityEngine.PlayerPrefs.DeleteKey("username");
                    UnityEngine.PlayerPrefs.Save();
                    _user.Entities[i].Destroy();
                }
            }
        }
예제 #3
0
 public void Allocate(EcsEntity entity, EcsWorld world)
 {
     ParseMeshData(entity.Set <UMeshData>(), entity.Set <URenderMatrix>());
     foreach (var component in _viewComponents)
     {
         component.EntityInit(entity, world, false);
     }
 }
 public static void AddDefaultUnitComponents(this EcsEntity unitEntity, GameObject unitObject, int health)
 {
     unitEntity.Set <AttackComponent>().InitializeComponent(unitEntity.Get <UnitComponent>().Tag.ToString().ToUnitType());
     //unitEntity.Set<DefenseComponent>().InitializeComponent(UnitType.Warrior);
     unitEntity.Set <HealthComponent>().InitializeComponent(health);
     unitEntity.Set <HealthBarComponent>().InitializeComponent(unitObject);
     unitEntity.Set <MovementComponent>().InitializeComponent(unitObject);
     unitEntity.Set <NavMeshComponent>();
     unitEntity.Get <NavMeshComponent>().Agent = unitObject.GetComponent <NavMeshAgent>();
 }
예제 #5
0
        public void Run()
        {
            foreach (var index in _filter)
            {
                float             random        = Random.Range(0f, 100f);
                CellConfiguration configuration = _configuration.CellConfigurations.Where(c => c.CheckInSpawnRabge(random)).First();

                EcsEntity entity = _filter.GetEntity(index);
                entity.Unset <EmptySpace>();
                entity.Set <Cell>().Configuration = configuration;
                entity.Set <CreateCellViewRequest>();
            }
        }
예제 #6
0
        private void LoadBuildingsSwitches()
        {
            var switchesComponent = resoursesEntity.Set <BuildingSwitchesComponent>();

            switchesComponent.buildingsSwitch = new Dictionary <string, BuildingSwitch>();

            foreach (BuildingTag tag in Enum.GetValues(typeof(BuildingTag)))
            {
                var type          = tag.ToString();
                var currentSwitch = new BuildingSwitch();
                currentSwitch.instancedRedBuilding   = GameObject.Instantiate(Resources.Load <GameObject>(@"Prefabs/Buildings/" + type + "Red"), new Vector3(-200, 200, -200), Quaternion.Euler(0, 0, 0));
                currentSwitch.instancedGreenBuilding = GameObject.Instantiate(Resources.Load <GameObject>(@"Prefabs/Buildings/" + type + "Green"), new Vector3(-200, 200, -200), Quaternion.Euler(0, 0, 0));
                switchesComponent.buildingsSwitch.Add(type, currentSwitch);
            }
        }
예제 #7
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            var forget = Entity.Set <ForgetSkillComponent>();
            forget.SkillType = typeof(PaladinShield);

            var learn = Entity.Set <LearnSkillComponent>();

            learn.Skill = new PaladinShield
            {
                Level = _random.NextInt(3)
            };
        }
    }
예제 #8
0
    public void AddPlayer(EcsEntity playerEntity)
    {
        var stats = playerEntity.Set <PlayerComponent>().Stats;

        livePlayers.Add(playerEntity);
        playersInLastGame.Add(stats);
    }
예제 #9
0
        public static T SetAndReset <T>(this EcsEntity entity) where T : class, IStandardEntity
        {
            var c = entity.Set <T>();

            c.Reset();
            return(c);
        }
예제 #10
0
        public void Init()
        {
            if (!_gameDefinitions.foodDefinition)
            {
                throw new Exception($"{nameof(FoodDefinition)} doesn't exists!");
            }

            FoodDefinition foodDefinition = _gameDefinitions.foodDefinition;

            GameObject[] foodObjects = GameObject.FindGameObjectsWithTag("Food");
            foreach (GameObject foodObject in foodObjects)
            {
                EcsEntity entity = _ecsWorld.NewEntityWith(out FoodComponent foodComponent, out ItemComponent _);

                foodComponent.Scores       = foodDefinition.ScoresPerFood;
                foodComponent.SpeedPenalty = foodDefinition.SpeedPenalty;

                entity.Set <CreateWorldObjectEvent>().Transform = foodObject.transform;
            }

            GameObject[] energizers = GameObject.FindGameObjectsWithTag("Energizer");
            foreach (GameObject energizer in energizers)
            {
                EcsEntity entity = _ecsWorld.NewEntityWith(
                    out FoodComponent foodComponent,
                    out EnergizerComponent _,
                    out ItemComponent _);

                foodComponent.Scores       = foodDefinition.ScoresPerFood * foodDefinition.EnergizerMultiplier;
                foodComponent.SpeedPenalty = foodDefinition.SpeedPenalty * foodDefinition.EnergizerMultiplier;

                entity.Set <CreateWorldObjectEvent>().Transform = energizer.transform;
            }
        }
예제 #11
0
        public void Init()
        {
            if (!_gameDefinitions.playerDefinition)
            {
                throw new Exception($"{nameof(PlayerDefinition)} doesn't exists!");
            }

            int playerCount = 0;
            PlayerDefinition playerDefinition = _gameDefinitions.playerDefinition;

            GameObject[] playerObjects = GameObject.FindGameObjectsWithTag("Player");
            foreach (GameObject player in playerObjects)
            {
                EcsEntity playerEntity = _ecsWorld.NewEntityWith(
                    out PlayerComponent playerComponent,
                    out MoveComponent moveComponent);

                Vector2Int startPosition = player.transform.position.ToVector2Int();
                moveComponent.Heading = playerCount % 2 != 0
                    ? Directions.Right
                    : Directions.Left;

                moveComponent.DesiredPosition = startPosition;
                moveComponent.Speed           = playerDefinition.StartSpeed;

                playerComponent.Lives         = playerDefinition.StartLives;
                playerComponent.Num           = ++playerCount;
                playerComponent.SpawnPosition = startPosition;

                playerEntity.Set <CreateWorldObjectEvent>().Transform = player.transform;
            }
        }
예제 #12
0
        void IInputCommand.Execute(EcsEntity entity)
        {
            var c1 = entity.Get <GameObjectComponent>();

            if (vertical > 0)
            {
                goalPosition = new Vector2(c1.Transform.position.x, c1.Transform.position.y + 1);
            }

            if (vertical < 0)
            {
                goalPosition = new Vector2(c1.Transform.position.x, c1.Transform.position.y - 1);
            }

            if (horizontal > 0)
            {
                goalPosition = new Vector2(c1.Transform.position.x + 1, c1.Transform.position.y);
            }

            if (horizontal < 0)
            {
                goalPosition = new Vector2(c1.Transform.position.x - 1, c1.Transform.position.y);
            }

            var c = entity.Set <ActionMoveComponent>();

            c.GoalPosition = goalPosition.ToInt2();
        }
예제 #13
0
        void IInputCommand.Execute(EcsEntity entity)
        {
            var c = entity.Set <ActionAttackComponent>();

            c.Target                   = target;
            c.TargetPosition           = targetPosition;
            c.PrimaryOrSecondaryWeapon = true;
        }
 public override void EntityInit(EcsEntity ecsEntity, EcsWorld world, bool OnScene)
 {
     ecsEntity.Set <URotationRoot>().Transform = this._root;
     if (OnScene)
     {
         Destroy(this);
     }
 }
예제 #15
0
        public void Run()
        {
            if (_fieldChangers.GetEntitiesCount() > 0 || _chains.GetEntitiesCount() > 0 || _explosionAnimations.GetEntitiesCount() > 0)
            {
                return;
            }

            foreach (int index in _filter)
            {
                Vector2Int cellPosition   = _filter.Get2(index);
                Vector2Int targetPosition = _filter.Get3(index).To;

                EcsEntity swapCell   = _filter.GetEntity(index);
                EcsEntity secondCell = _gameField.Cells[targetPosition];

                swapCell.Set <Vector2Int>() = targetPosition;
                swapCell.Set <AnimateSwapRequest>().MainCell = true;

                secondCell.Set <Vector2Int>() = cellPosition;
                secondCell.Set <AnimateSwapRequest>().MainCell = false;

                _gameField.Cells[cellPosition]   = secondCell;
                _gameField.Cells[targetPosition] = swapCell;

                List <ChainEvent> chains = GameFieldAnalyst.GetChains(_gameField.Cells, _configuration);

                if (chains.Count == 0)
                {
                    _gameField.Cells[cellPosition]   = swapCell;
                    _gameField.Cells[targetPosition] = secondCell;

                    swapCell.Set <Vector2Int>() = cellPosition;

                    AnimateSwapBackRequest request = new AnimateSwapBackRequest();
                    request.TargetPosition = targetPosition;
                    swapCell.Set <AnimateSwapBackRequest>() = request;

                    secondCell.Set <Vector2Int>() = targetPosition;

                    AnimateSwapBackRequest secondRequest = new AnimateSwapBackRequest();
                    secondRequest.TargetPosition = cellPosition;
                    secondCell.Set <AnimateSwapBackRequest>() = secondRequest;
                }
            }
        }
 public void Run()
 {
     foreach (var index in _filter)
     {
         EcsEntity cell = _filter.GetEntity(index);
         cell.Unset <ChargedToExplosion>();
         cell.Set <EmptySpace>();
     }
 }
예제 #17
0
        public virtual void OnSpawn(EcsEntity entity)
        {
            entity.Set <UnityView>();
            UnityView view = entity.Get <UnityView>();

            view.GameObject = this.gameObject;
            view.id         = id;
            view.Transform  = transform;
        }
예제 #18
0
        public void Run()
        {
            Vector2 mousePosition = _sceneData.Camera.ScreenToWorldPoint(Input.mousePosition);

            foreach (int index in _filter)
            {
                Cell      cell         = _filter.Get1(index);
                Vector2   cellPosition = cell.View.transform.position;
                Vector2   mouseOffset  = mousePosition - cellPosition;
                EcsEntity cellEntity   = _filter.GetEntity(index);

                Vector2Int offset = Vector2Int.zero;

                if (Mathf.Abs(mouseOffset.x) > _configuration.SwapMinMouseOffset)
                {
                    int offsetX = mouseOffset.x > 0 ? 1 : -1;
                    offset = new Vector2Int(offsetX, 0);
                }
                else if (Mathf.Abs(mouseOffset.y) > _configuration.SwapMinMouseOffset)
                {
                    int offsetY = mouseOffset.y > 0 ? 1 : -1;
                    offset = new Vector2Int(0, offsetY);
                }

                Vector2Int fieldPosition  = _filter.Get2(index);
                Vector2Int targetPosition = fieldPosition + offset;

                if (offset.Equals(Vector2Int.zero) || !_gameField.Cells.ContainsKey(targetPosition))
                {
                    continue;
                }

                SwapRequest swap = new SwapRequest()
                {
                    From = fieldPosition,
                    To   = targetPosition
                };

                cellEntity.Set <SwapRequest>() = swap;
                cellEntity.Unset <Selected>();
                cellEntity.Set <DeselectCellAnimationRequest>();
            }
        }
예제 #19
0
        public void Init()
        {
            EcsEntity cameraEntity = _world.NewEntity();

            CameraComponent cameraComponent = cameraEntity.Set <CameraComponent>();

            cameraComponent.MainCamera = Camera.main;

            Positioning.Components.Position position = cameraEntity.Set <Positioning.Components.Position>();
            position.Point         = cameraComponent.MainCamera.transform.position;
            position.EulerRotation = cameraComponent.MainCamera.transform.eulerAngles;

            UnityView unityView = cameraEntity.Set <UnityView>();

            unityView.GameObject = cameraComponent.MainCamera.gameObject;
            unityView.Transform  = cameraComponent.MainCamera.transform;

            _camPosition = position;
        }
예제 #20
0
        public void Run()
        {
            foreach (int i in _deadPlayers)
            {
                PlayerComponent deadPlayer   = _deadPlayers.Get1[i];
                EcsEntity       playerEntity = _deadPlayers.Entities[i];

                Vector2Int spawnPosition = deadPlayer.SpawnPosition;
                if (--deadPlayer.Lives <= 0)
                {
                    deadPlayer.IsDead = true;
                    spawnPosition     = Vector2Int.zero;
                    playerEntity.Set <DestroyedWorldObjectComponent>();
                }

                playerEntity.Set <TeleportedComponent>().NewPosition = spawnPosition;
                _ecsWorld.NewEntityWith(out UpdateScoreTableEvent _);
            }
        }
예제 #21
0
        public static void MarkAsUpdated <T>(this EcsEntity entity) where T : class, new()
        {
                        #if DEBUG
            if (entity.Get <T>() == null)
            {
                throw new Exception($"Entity has no {typeof(T).Name} and can be marked as updated!");
            }
                        #endif

            entity.Set <Updated <T> >();
        }
예제 #22
0
        private void LoadUiAssets()
        {
            resoursesEntity   = world.NewEntityWith(out PlayerResourcesComponent playerAsset);
            playerAsset.Semki = 50;
            playerAsset.Cash  = 1000;
            playerAsset.ResoursesUiDisplay = GameObject.Instantiate(Resources.Load <Canvas>(@"Prefabs/GUI/PlayerInfo"));

            var assets = resoursesEntity.Set <BuildingAssetsComponent>();

            assets.InBuildingCanvasesAssets = GetInBuildingCanvasesAssets();
            assets.BuildingsAssets          = GetAllBuildingAssets();
        }
예제 #23
0
        public override void EntityInit(EcsEntity ecsEntity, EcsWorld world, bool OnScene)
        {
            MarkerRoot mRoot = ecsEntity.Set <MarkerRoot>();

            mRoot.FriendlyMarker = this._friendlyMarker;
            mRoot.EnemyMarker    = this._enemyMarker;

            if (OnScene)
            {
                Destroy(this);
            }
        }
        private void SwapCells(Vector2Int position, Vector2Int extenderPosition)
        {
            bool hasCellID = _gameField.Cells.ContainsKey(extenderPosition);

            if (!hasCellID)
            {
                return;
            }

            EcsEntity emptyEntity    = _gameField.Cells[position];
            EcsEntity extenderEntity = _gameField.Cells[extenderPosition];

            _gameField.Cells.Remove(position);
            _gameField.Cells.Remove(extenderPosition);
            _gameField.Cells.Add(position, extenderEntity);
            _gameField.Cells.Add(extenderPosition, emptyEntity);
            emptyEntity.Set <Vector2Int>()    = extenderPosition;
            extenderEntity.Set <Vector2Int>() = position;

            extenderEntity.Set <AnimateFallDownRequest>();
        }
예제 #25
0
        public override void AddToEntity(ref EcsEntity entity)
        {
            startValue = value;
            value      = entity.Set <T>();
            connected  = true;

            if (startValue != null)
            {
                startValue.Copy(value);
                MarkAsUpdated();
            }
        }
        public override void EntityInit(EcsEntity ecsEntity, EcsWorld world, bool OnScene)
        {
            ExplosionRoot eRoot = ecsEntity.Set <ExplosionRoot>();

            eRoot.Explosion = this._explosion;
            _explosion.Play();

            if (OnScene)
            {
                Destroy(this);
            }
        }
        public override void EntityInit(EcsEntity ecsEntity, EcsWorld world, bool OnScene)
        {
            var points = new Vector3[lengthOfLineRenderer];

            points[0] = ecsEntity.Get <LineConnection>().PositionA;
            points[1] = ecsEntity.Get <LineConnection>().PositionB;
            _root.SetPositions(points);

            ecsEntity.Set <LineRendererRoot>().LineRenderer = this._root;
            if (OnScene)
            {
                Destroy(this);
            }
        }
예제 #28
0
        public void Run()
        {
            if (!Input.GetMouseButtonUp(0))
            {
                return;
            }

            foreach (int index in _filter)
            {
                EcsEntity cell = _filter.GetEntity(index);
                cell.Unset <Selected>();
                cell.Set <DeselectCellAnimationRequest>();
            }
        }
예제 #29
0
        public void Run()
        {
            foreach (int i in _createEvents)
            {
                Transform newObject = _createEvents.Get1[i].Transform;
                EcsEntity entity    = _createEvents.Entities[i];

                Vector2Int position = newObject.position.ToVector2Int();
                _worldService.WorldField[position.x][position.y].Add(entity);
                entity.Set <PositionComponent>().Position     = position;
                entity.Set <WorldObjectComponent>().Transform = newObject;
            }

            foreach (int i in _movedObjects)
            {
                PositionComponent positionComponent = _movedObjects.Get1[i];
                Vector2Int        oldPosition       = positionComponent.Position;
                Vector2Int        newPosition       = _movedObjects.Get2[i].NewPosition;
                EcsEntity         entity            = _movedObjects.Entities[i];

                _worldService.WorldField[oldPosition.x][oldPosition.y].Remove(entity);
                _worldService.WorldField[newPosition.x][newPosition.y].Add(entity);

                positionComponent.Position = newPosition;
            }

            foreach (int i in _destroyedObjects)
            {
                Transform  objectToDestroy = _destroyedObjects.Get1[i].Transform;
                Vector2Int position        = _destroyedObjects.Get2[i].Position;
                EcsEntity  entity          = _destroyedObjects.Entities[i];

                _worldService.WorldField[position.x][position.y].Remove(entity);
                objectToDestroy.gameObject.SetActive(false);
                entity.Destroy();
            }
        }
예제 #30
0
        public void Run()
        {
            foreach (int i in _teleported)
            {
                MoveComponent moveComponent  = _teleported.Get1[i];
                Transform     transform      = _teleported.Get2[i].Transform;
                Vector2Int    targetPosition = _teleported.Get3[i].NewPosition;
                EcsEntity     entity         = _teleported.Entities[i];

                moveComponent.DesiredPosition = targetPosition;
                transform.position            = targetPosition.ToVector3(transform.position.y);

                entity.Set <NewPositionEvent>().NewPosition = targetPosition;
            }
        }