BoxFaces.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace O3DWB
  6. {
  7. public static class BoxFaces
  8. {
  9. #region Private Static Variables
  10. private static readonly BoxFace[] _faces;
  11. private static readonly Vector3[] _faceNormals;
  12. private static readonly Vector3[] _faceRightAxes;
  13. private static readonly Vector3[] _faceLookAxes;
  14. private static readonly int _count;
  15. #endregion
  16. #region Constructors
  17. static BoxFaces()
  18. {
  19. _count = Enum.GetValues(typeof(BoxFace)).Length;
  20. _faces = new BoxFace[_count];
  21. _faces[(int)BoxFace.Back] = BoxFace.Back;
  22. _faces[(int)BoxFace.Front] = BoxFace.Front;
  23. _faces[(int)BoxFace.Left] = BoxFace.Left;
  24. _faces[(int)BoxFace.Right] = BoxFace.Right;
  25. _faces[(int)BoxFace.Top] = BoxFace.Top;
  26. _faces[(int)BoxFace.Bottom] = BoxFace.Bottom;
  27. _faceNormals = new Vector3[_count];
  28. _faceNormals[(int)BoxFace.Back] = Vector3.forward;
  29. _faceNormals[(int)BoxFace.Front] = Vector3.back;
  30. _faceNormals[(int)BoxFace.Left] = Vector3.left;
  31. _faceNormals[(int)BoxFace.Right] = Vector3.right;
  32. _faceNormals[(int)BoxFace.Top] = Vector3.up;
  33. _faceNormals[(int)BoxFace.Bottom] = Vector3.down;
  34. _faceRightAxes = new Vector3[_count];
  35. _faceRightAxes[(int)BoxFace.Back] = Vector3.left;
  36. _faceRightAxes[(int)BoxFace.Front] = Vector3.right;
  37. _faceRightAxes[(int)BoxFace.Left] = Vector3.back;
  38. _faceRightAxes[(int)BoxFace.Right] = Vector3.forward;
  39. _faceRightAxes[(int)BoxFace.Top] = Vector3.right;
  40. _faceRightAxes[(int)BoxFace.Bottom] = Vector3.right;
  41. _faceLookAxes = new Vector3[_count];
  42. _faceLookAxes[(int)BoxFace.Back] = Vector3.up;
  43. _faceLookAxes[(int)BoxFace.Front] = Vector3.up;
  44. _faceLookAxes[(int)BoxFace.Left] = Vector3.up;
  45. _faceLookAxes[(int)BoxFace.Right] = Vector3.up;
  46. _faceLookAxes[(int)BoxFace.Top] = Vector3.forward;
  47. _faceLookAxes[(int)BoxFace.Bottom] = Vector3.back;
  48. }
  49. #endregion
  50. #region Public Static Properties
  51. public static int Count { get { return _count; } }
  52. #endregion
  53. #region Public Static Functions
  54. public static List<BoxFace> GetAll()
  55. {
  56. return new List<BoxFace>(_faces);
  57. }
  58. public static BoxFace GetNext(BoxFace boxFace)
  59. {
  60. return (BoxFace)(((int)boxFace + 1) % _count);
  61. }
  62. public static List<Vector3> GetAllFaceNormals()
  63. {
  64. return new List<Vector3>(_faceNormals);
  65. }
  66. public static List<Vector3> GetAllFaceRightAxes()
  67. {
  68. return new List<Vector3>(_faceRightAxes);
  69. }
  70. public static List<Vector3> GetAllFaceLookAxes()
  71. {
  72. return new List<Vector3>(_faceLookAxes);
  73. }
  74. public static Vector3 GetFaceNormal(BoxFace boxFace)
  75. {
  76. return _faceNormals[(int)boxFace];
  77. }
  78. public static Vector3 GetFaceRightAxis(BoxFace boxFace)
  79. {
  80. return _faceRightAxes[(int)boxFace];
  81. }
  82. public static Vector3 GetFaceLookAxis(BoxFace boxFace)
  83. {
  84. return _faceLookAxes[(int)boxFace];
  85. }
  86. public static BoxFace GetOpposite(BoxFace boxFace)
  87. {
  88. if (boxFace == BoxFace.Back) return BoxFace.Front;
  89. if (boxFace == BoxFace.Front) return BoxFace.Back;
  90. if (boxFace == BoxFace.Left) return BoxFace.Right;
  91. if (boxFace == BoxFace.Right) return BoxFace.Left;
  92. if (boxFace == BoxFace.Bottom) return BoxFace.Top;
  93. return BoxFace.Bottom;
  94. }
  95. #endregion
  96. }
  97. }
  98. #endif