You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /// <summary>
  5. /// Class used to write extension methodes in
  6. /// </summary>
  7. public static class ExtensionMethods
  8. {
  9. /// <summary>
  10. /// Converts provided Direction to Global Vector3
  11. /// </summary>
  12. /// <param name="direction">Direction to convert</param>
  13. /// <returns>Global Vector3 direction</returns>
  14. public static Vector3 ToVector(this Direction direction)
  15. {
  16. switch (direction)
  17. {
  18. case Direction.Forward:
  19. return Vector3.forward;
  20. case Direction.Right:
  21. return Vector3.right;
  22. case Direction.Back:
  23. return Vector3.back;
  24. case Direction.Left:
  25. return Vector3.left;
  26. default:
  27. return Vector3.zero;
  28. }
  29. }
  30. /// <summary>
  31. /// Converts provided Direction to local Vector3
  32. /// </summary>
  33. /// <param name="direction">Direction to convert</param>
  34. /// <param name="transform">Transform to use as directions local space</param>
  35. /// <returns>Local Vector3 direction</returns>
  36. public static Vector3 ToVector(this Direction direction, Transform transform)
  37. {
  38. switch (direction)
  39. {
  40. case Direction.Forward:
  41. return transform.forward;
  42. case Direction.Right:
  43. return transform.right;
  44. case Direction.Back:
  45. return -transform.forward;
  46. case Direction.Left:
  47. return -transform.right;
  48. default:
  49. return Vector3.zero;
  50. }
  51. }
  52. }