示例#1
0
    private IEnumerator InternalRotateObject(BoardObject bObject, int direction, float time)
    {
        // Get direction
        BoardObject.Direction currentDirection = bObject.GetDirection();
        BoardObject.Direction targetDirection  = (BoardObject.Direction)((((int)currentDirection + direction) + 8) % 8);

        // Froze direction
        bObject.SetDirection(BoardObject.Direction.PARTIAL, false);

        Vector3 fromAngles = bObject.transform.localEulerAngles;

        fromAngles.y = (int)currentDirection * 45.0f;
        Vector3 toAngles = bObject.transform.localEulerAngles;

        toAngles.y = ((int)currentDirection + direction) * 45.0f;

        // Interpolate movement
        float auxTimer = 0.0f;

        while (auxTimer < time)
        {
            Vector3 lerpAngles = Vector3.Lerp(fromAngles, toAngles, auxTimer / time);
            bObject.transform.localEulerAngles = lerpAngles;
            auxTimer += Time.deltaTime;
            yield return(null);
        }

        // Set final rotation (defensive code)
        bObject.SetDirection(targetDirection);
    }
示例#2
0
    public void SetBoardObjectDirection(Vector2Int position, BoardObject.Direction direction)
    {
        if (IsInBoardBounds(position))
        {
            BoardObject bObject = board[position.x, position.y].GetPlacedObject();
            if (bObject == null)
            {
                return;
            }

            bObject.SetDirection(direction);
        }
    }
示例#3
0
    public void SetDirection(BoardObject.Direction direction, bool rotate = true)
    {
        orientation = direction;

        if (!rotate)
        {
            return;
        }

        if (direction == BoardObject.Direction.PARTIAL)
        {
            direction = BoardObject.Direction.RIGHT; // Default
        }
        Vector3 lastRot = transform.localEulerAngles;

        lastRot.y = (int)direction * 45.0f;
        transform.localEulerAngles = lastRot;
    }
示例#4
0
 public void Rotate(int dir)
 {
     BoardObject.Direction newDir = (BoardObject.Direction)((((int)orientation + dir) + 8) % 8);
     SetDirection(newDir);
 }