public void Run() { foreach (var index in _filter) { EcsEntity cell = _filter.GetEntity(index); cell.Unset <ChargedToExplosion>(); cell.Set <EmptySpace>(); } }
public override void RemoveFromEntity(ref EcsEntity entity) { if (startValue != null) { value.Copy(startValue); value = startValue; } entity.Unset <T>(); connected = false; }
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>(); } }
public void Run() { if (!Input.GetMouseButtonUp(0)) { return; } foreach (int index in _filter) { EcsEntity cell = _filter.GetEntity(index); cell.Unset <Selected>(); cell.Set <DeselectCellAnimationRequest>(); } }
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>(); } }
private void OnSwapCompleate(EcsEntity entity, Transform view) { entity.Unset <ChangeFieldAnimating>(); entity.Set <ActivateBonusRequest>(); view.transform.position -= new Vector3(0, 0, view.transform.position.z); }
public void Run() { GhostDefinition ghostDefinition = _gameDefinitions.ghostDefinition; if (!_enableEvents.IsEmpty()) { foreach (int i in _ghosts) { GhostComponent ghost = _ghosts.Get1[i]; EcsEntity ghostEntity = _ghosts.Entities[i]; ghostEntity.Set <GhostInFearStateComponent>().EstimateTime = ghostDefinition.FearStateInSec; ghost.Renderer.material.color = ghostDefinition.FearState; } } foreach (int i in _fearStateGhosts) { GhostComponent ghostComponent = _fearStateGhosts.Get1[i]; GhostInFearStateComponent fearState = _fearStateGhosts.Get2[i]; EcsEntity ghostEntity = _fearStateGhosts.Entities[i]; fearState.EstimateTime -= Time.deltaTime; if (fearState.EstimateTime <= 0) { ghostEntity.Unset <GhostInFearStateComponent>(); switch (ghostComponent.GhostType) { case GhostTypes.Blinky: ghostComponent.Renderer.material.color = ghostDefinition.Blinky; break; case GhostTypes.Pinky: ghostComponent.Renderer.material.color = ghostDefinition.Pinky; break; case GhostTypes.Inky: ghostComponent.Renderer.material.color = ghostDefinition.Inky; break; case GhostTypes.Clyde: ghostComponent.Renderer.material.color = ghostDefinition.Clyde; break; default: throw new ArgumentOutOfRangeException(); } return; } Vector2Int currentPosition = ghostEntity.Set <PositionComponent>().Position; foreach (EcsEntity entity in _worldService.WorldField[currentPosition.x][currentPosition.y]) { var player = entity.Get <PlayerComponent>(); if (player == null) { continue; } player.Scores += ghostDefinition.ScoresPerGhost; ghostEntity.Set <DestroyedWorldObjectComponent>(); _ecsWorld.NewEntityWith(out UpdateScoreTableEvent _); } } }
public static void StopFollow(EcsEntity unit) { unit.Unset <FollowingComponent>(); }
private void OnFallenDown(EcsEntity entity, Transform view) { entity.Unset <ChangeFieldAnimating>(); view.transform.position -= new Vector3(0, 0, view.transform.position.z); }
public void Run() { foreach (int i in _moveEntities) { PositionComponent positionComponent = _moveEntities.Get1[i]; MoveComponent moveComponent = _moveEntities.Get2[i]; Transform transform = _moveEntities.Get3[i].Transform; EcsEntity movingEntity = _moveEntities.Entities[i]; Vector3 curPosition = transform.position; float height = curPosition.y; Vector3 desiredPosition = moveComponent.DesiredPosition.ToVector3(height); Vector3 estimatedVector = desiredPosition - curPosition; if (estimatedVector.magnitude > Epsilon) { transform.position = Vector3.Lerp( transform.position, desiredPosition, moveComponent.Speed / estimatedVector.magnitude * Time.deltaTime); continue; } Vector2Int oldPosition = positionComponent.Position; Vector2Int newPosition = moveComponent.DesiredPosition; if (!oldPosition.Equals(newPosition)) { movingEntity.Set <NewPositionEvent>().NewPosition = newPosition; } Vector2Int newDesiredPosition; Vector3 newDirection; switch (moveComponent.Heading) { case Directions.Up: newDesiredPosition = new Vector2Int(newPosition.x, newPosition.y + 1); newDirection = new Vector3(0, 0, 0); break; case Directions.Right: newDesiredPosition = new Vector2Int(newPosition.x + 1, newPosition.y); newDirection = new Vector3(0, 90, 0); break; case Directions.Down: newDesiredPosition = new Vector2Int(newPosition.x, newPosition.y - 1); newDirection = new Vector3(0, 180, 0); break; case Directions.Left: newDesiredPosition = new Vector2Int(newPosition.x - 1, newPosition.y); newDirection = new Vector3(0, -90, 0); break; default: throw new ArgumentOutOfRangeException(); } transform.rotation = Quaternion.Euler(newDirection); bool stuckToWall = false; foreach (EcsEntity entity in _worldService.WorldField[newDesiredPosition.x][newDesiredPosition.y]) { if (!entity.IsAlive()) { continue; } if (entity.Get <WallComponent>() == null) { continue; } stuckToWall = true; } if (stuckToWall) { movingEntity.Set <StoppedComponent>(); } else { moveComponent.DesiredPosition = newDesiredPosition; movingEntity.Unset <StoppedComponent>(); } } }
public static void Stop(EcsEntity unit) { unit.Unset <MovingComponent>(); }
public static void StopAttack(EcsEntity unit) { unit.Unset <AttackingComponent>(); }
private void OnSwapBackCompleate(EcsEntity entity, Transform view) { entity.Unset <ChangeFieldAnimating>(); view.transform.position -= new Vector3(0, 0, view.transform.position.z); }