JunctionExtras.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using JetBrains.Annotations;
  3. using Routes;
  4. using UnityEngine;
  5. namespace Roads
  6. {
  7. [Serializable]
  8. public struct JunctionData
  9. {
  10. [SerializeField]
  11. private Transform north;
  12. [SerializeField]
  13. private Transform east;
  14. [SerializeField]
  15. private Transform south;
  16. [CanBeNull]
  17. public Transform GetEast(float yRotation)
  18. {
  19. var rotation = (int) yRotation;
  20. switch (rotation)
  21. {
  22. case 0:
  23. return east;
  24. case 90:
  25. return north;
  26. case 270:
  27. return south;
  28. default:
  29. return null;
  30. }
  31. }
  32. [CanBeNull]
  33. public Transform GetNorth(float yRotation)
  34. {
  35. var rotation = (int) yRotation;
  36. switch (rotation)
  37. {
  38. case 0:
  39. return north;
  40. case 180:
  41. return south;
  42. case 270:
  43. return east;
  44. default:
  45. return null;
  46. }
  47. }
  48. [CanBeNull]
  49. public Transform GetSouth(float yRotation)
  50. {
  51. var rotation = (int) yRotation;
  52. switch (rotation)
  53. {
  54. case 0:
  55. return south;
  56. case 90:
  57. return east;
  58. case 180:
  59. return north;
  60. default:
  61. return null;
  62. }
  63. }
  64. [CanBeNull]
  65. public Transform GetWest(float yRotation)
  66. {
  67. var rotation = (int) yRotation;
  68. switch (rotation)
  69. {
  70. case 90:
  71. return south;
  72. case 180:
  73. return east;
  74. case 270:
  75. return north;
  76. default:
  77. return null;
  78. }
  79. }
  80. }
  81. public class JunctionExtras : Turn
  82. {
  83. public JunctionData junctionData;
  84. protected override Transform RoadDirectionToTransform(RoadDirection position)
  85. {
  86. var rotation = transform.rotation.eulerAngles.y;
  87. switch (position)
  88. {
  89. case RoadDirection.North:
  90. return junctionData.GetNorth(rotation);
  91. case RoadDirection.West:
  92. return junctionData.GetWest(rotation);
  93. case RoadDirection.East:
  94. return junctionData.GetEast(rotation);
  95. case RoadDirection.South:
  96. return junctionData.GetSouth(rotation);
  97. case RoadDirection.None:
  98. throw new ArgumentException("RoadDirection.None not allowed for adding arrows");
  99. default:
  100. throw new ArgumentOutOfRangeException(nameof(position), position, "Wrong Argument for AddArrows");
  101. }
  102. }
  103. }
  104. }