DirectionUtils

Static class in ChivalrousGames.Common

Description

Helper class to facilitate usage of the Direction enumeration.

Static Methods

GetOppositeDirection
public static Direction GetOppositeDirection(Direction direction);
Parameters
direction Direction The direction to get the opposition direction from
Return
Direction A new instance of Direction
Description

Get the direction opposition to the one specified. When using “None”, will return “None”.

GetDirectionsAsList
public static List GetDirectionsAsList();
Return
List<Direction> A new instance of Direction
Description

Get a list of all the Directions in this order: Left, Right, Up, Down, Forward, Backward, None

GetDirectionsAsListWithoutNone
public static List GetDirectionsAsListWithoutNone();
Return
List<Direction> A new instance of Direction
Description

Get a list of all the Directions (except none) in this order: Left, Right, Up, Down, Forward, Backward

GetDirectionsAsListWithoutNone
public static List GetDirectionsAsListWithoutNone(ChivalrousGames.Common.Random random);
Parameters
random Random A Random object used to shuffle the directions in the list
Return
List<Direction> A new instance of Direction
Description

Get a list of all the Directions (except none) in a random order.

Rotate
public static Direction Rotate(Direction direction, PointRotation rotation);
Parameters
direction Direction The direction on which to apply a rotation
rotation PointRotation The rotation to apply to the direction
Return
Direction A new instance of Direction
Description

Rotates a direction clockwise when looking toward the negative values of the axis (like Unity does in the inspector).

Usage Example
Direction rotatedDirection = DirectionUtils.Rotate (Direction.Up, new PointRotation(0,	0,	90));
//In this example, the Up direction is rotated 90 degrees clockwise around the Z axis when looking toward negative Z values, which will result in a Left direction.
ReverseRotate
public static Direction ReverseRotate(Direction direction, PointRotation rotation);
Parameters
direction Direction The direction on which to apply a rotation
rotation PointRotation The rotation to apply to the direction
Return
Direction A new instance of Direction
Description

Rotates a direction counter-clockwise when looking toward the negative values of the axis (the opposite of what Unity does in the inspector).

Usage Example
Direction rotatedDirection = DirectionUtils.ReverseRotate (Direction.Up, new PointRotation(0,	0,	90));
//In this example, the Up direction is rotated 90 degrees clockwise around the Z axis when looking toward negative Z values, which will result in a Right direction.
GetStartDirection
public static Direction GetStartDirection(Direction endDirection, PointRotation rotation);
Parameters
endDirection Direction The resulting direction after a rotation
rotation PointRotation The rotation applied to a direction
Return
Direction A new instance of Direction
Description

Calculates what original direction is required to reach the specified end direction when the specified rotation is applied to it. Identical to ReverseRotate. Provided to simplify readability in code.

Rotate90AroundX
public static Direction Rotate90AroundX(Direction direction);
Parameters
direction Direction The direction on which to apply a rotation
Return
Direction A new instance of Direction
Description

Rotates a direction 90 degrees clockwise around the X axis when looking toward the negative values of the axis.

Rotate180AroundX
public static Direction Rotate180AroundX(Direction direction);
Parameters
direction Direction The direction on which to apply a rotation
Return
Direction A new instance of Direction
Description

Rotates a direction 180 degrees clockwise around the X axis when looking toward the negative values of the axis.

Rotate270AroundX
public static Direction Rotate270AroundX(Direction direction);
Parameters
direction Direction The direction on which to apply a rotation
Return
Direction A new instance of Direction
Description

Rotates a direction 270 degrees clockwise around the X axis when looking toward the negative values of the axis.

Rotate90AroundY
public static Direction Rotate90AroundY(Direction direction);
Parameters
direction Direction The direction on which to apply a rotation
Return
Direction A new instance of Direction
Description

Rotates a direction 90 degrees clockwise around the Y axis when looking toward the negative values of the axis.

Rotate180AroundY
public static Direction Rotate180AroundY(Direction direction);
Parameters
direction Direction The direction on which to apply a rotation
Return
Direction A new instance of Direction
Description

Rotates a direction 180 degrees clockwise around the Y axis when looking toward the negative values of the axis.

Rotate270AroundY
public static Direction Rotate270AroundY(Direction direction);
Parameters
direction Direction The direction on which to apply a rotation
Return
Direction A new instance of Direction
Description

Rotates a direction 270 degrees clockwise around the Y axis when looking toward the negative values of the axis.

Rotate90AroundZ
public static Direction Rotate90AroundZ(Direction direction);
Parameters
direction Direction The direction on which to apply a rotation
Return
Direction A new instance of Direction
Description

Rotates a direction 90 degrees clockwise around the Z axis when looking toward the negative values of the axis.

Rotate180AroundZ
public static Direction Rotate180AroundZ(Direction direction);
Parameters
direction Direction The direction on which to apply a rotation
Return
Direction A new instance of Direction
Description

Rotates a direction 180 degrees clockwise around the Z axis when looking toward the negative values of the axis.

Rotate270AroundZ
public static Direction Rotate270AroundZ(Direction direction);
Parameters
direction Direction The direction on which to apply a rotation
Return
Direction A new instance of Direction
Description

Rotates a direction 270 degrees clockwise around the Z axis when looking toward the negative values of the axis.