Ejemplo n.º 1
0
    private void SetPointerLocomotionTarget(Vector2 target, ObjectDirection moveDirection)
    {
        //Logger.Warning($"SetPointerLocomotionTarget to target {target.x}, {target.y} in the direction {moveDirection}");
        GridLocation targetGridLocation = GridLocation.FindClosestGridTile(target);

        if (!ValidateTarget(new TargetLocation(targetGridLocation, moveDirection)))
        {
            return;
        }

        Vector2 gridVectorTarget = GridLocation.GridToVector(targetGridLocation);

        if (CurrentGridLocation.X == targetGridLocation.X && CurrentGridLocation.Y == targetGridLocation.Y)
        {
            return;
        }

        if (!_animationHandler.InLocomotion)
        {
            _animationHandler.SetLocomotion(true);
        }

        IsCalculatingPath = true;

        PathToTarget = _pathfinding.FindNodePath(CurrentGridLocation, targetGridLocation);
        PathToTarget.RemoveAt(0);

        IsCalculatingPath = false;
        SetHasCalculatedTarget(true);
    }
Ejemplo n.º 2
0
    private void SelectTileWithMouse()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            // clicked on the UI
            return;
        }

        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (GameManager.Instance.CurrentEditorLevel.TilesByLocation.TryGetValue(GridLocation.FindClosestGridTile(mousePosition), out Tile selectedTile))
        {
            if (!IsValidGridLocationToSelect(selectedTile.GridLocation))
            {
                return;
            }
        }
        else
        {
            return;
        }

        CurrentlySelectedTile = selectedTile;
        UpdateEditorUIForSelectedLocation();
    }
Ejemplo n.º 3
0
    private void CheckPointerInput()
    {
        if (HasCalculatedTarget)
        {
            return;
        }

        Vector2      tempFingerPosition  = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        GridLocation closestGridLocation = GridLocation.FindClosestGridTile(tempFingerPosition);

        if (closestGridLocation.X == CurrentGridLocation.X && closestGridLocation.Y == CurrentGridLocation.Y)
        {
            return;
        }

        GridLocation newLocomotionTarget = CurrentGridLocation;
        Vector2      direction           = tempFingerPosition - (Vector2)transform.position;
        float        angle = Vector2.SignedAngle(Vector2.up, direction) * -1;

        new GridLocation(CurrentGridLocation.X, CurrentGridLocation.Y);
        ObjectDirection moveDirection = ObjectDirection.Right;

        if (angle <= -135)  // go down
        {
            newLocomotionTarget = new GridLocation(CurrentGridLocation.X, CurrentGridLocation.Y - 1);
            moveDirection       = ObjectDirection.Down;
        }
        else if (angle <= -45) // go left
        {
            newLocomotionTarget = new GridLocation(CurrentGridLocation.X - 1, CurrentGridLocation.Y);
            moveDirection       = ObjectDirection.Left;
        }
        else if (angle <= 45) // go up
        {
            newLocomotionTarget = new GridLocation(CurrentGridLocation.X, CurrentGridLocation.Y + 1);
            moveDirection       = ObjectDirection.Up;
        }
        else if (angle <= 135) // go right
        {
            newLocomotionTarget = new GridLocation(CurrentGridLocation.X + 1, CurrentGridLocation.Y);
            moveDirection       = ObjectDirection.Right;
        }
        else // go down
        {
            newLocomotionTarget = new GridLocation(CurrentGridLocation.X, CurrentGridLocation.Y - 1);
            moveDirection       = ObjectDirection.Down;
        }

        SetPointerLocomotionTarget(GridLocation.GridToVector(newLocomotionTarget), moveDirection);
    }