JunctionExtras.cs 3.0 KB

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