/// <summary> /// Shift the <see cref="Direction4Diagonal"/> clockwise. /// </summary> /// <param name="direction">The <see cref="Direction4Diagonal"/> to shift.</param> /// <param name="shiftBy">The number of times to shift.</param> /// <returns>A <see cref="Direction4Diagonal"/> shifted by <paramref name="shiftBy"/> amount of times, starting from <paramref name="direction"/>.</returns> public static Direction4Diagonal Shift(this Direction4Diagonal direction, int shiftBy) { var index = (int)direction; index += shiftBy; index %= DirectionEnumLength; if (index < 0) { index += DirectionEnumLength; } return((Direction4Diagonal)index); }
/// <summary> /// Returns a unit <see cref="Vector3"/> on a horizontal plane, representing this <see cref="Direction4Diagonal"/>. /// </summary> /// <param name="direction">The input <see cref="Direction4Diagonal"/>.</param> /// <returns>A unit <see cref="Vector3"/> representing <paramref name="direction"/>.</returns> /// <exception cref="InvalidEnumArgumentException"><paramref name="direction"/> has an invalid value.</exception> public static Vector3 AsVector3XZ(this Direction4Diagonal direction) { switch (direction) { case Direction4Diagonal.DownRight: return((Vector3.right + Vector3.back).normalized); case Direction4Diagonal.DownLeft: return((Vector3.left + Vector3.back).normalized); case Direction4Diagonal.UpLeft: return((Vector3.left + Vector3.forward).normalized); case Direction4Diagonal.UpRight: return((Vector3.right + Vector3.forward).normalized); default: throw new InvalidEnumArgumentException(nameof(direction), (int)direction, typeof(Direction4Diagonal)); } }
public static string GeographicName(this Direction4Diagonal direction4Diagonal) { switch (direction4Diagonal) { case Direction4Diagonal.UpRight: return("North East"); case Direction4Diagonal.DownRight: return("South East"); case Direction4Diagonal.DownLeft: return("South West"); case Direction4Diagonal.UpLeft: return("North West"); default: return(""); } }
public static float GetOuterCornerAngle(this Direction4Diagonal direction4Diagonal) { switch (direction4Diagonal) { case Direction4Diagonal.UpRight: return(90); case Direction4Diagonal.DownRight: return(180); case Direction4Diagonal.DownLeft: return(270); case Direction4Diagonal.UpLeft: return(0); default: throw new ArgumentOutOfRangeException(nameof(direction4Diagonal), direction4Diagonal, null); } }
/// <summary> /// Returns the opposite <see cref="Direction4Diagonal"/> of this <see cref="Direction4Diagonal"/>. /// </summary> /// <param name="direction">The <see cref="Direction4Diagonal"/> to invert.</param> /// <returns>The opposite <see cref="Direction4Diagonal"/> of <paramref name="direction"></paramref>.</returns> public static Direction4Diagonal Opposite(this Direction4Diagonal direction) { return(direction.Shift((DirectionEnumLength - 1) / 2)); }