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.

101 lines
1.8 KiB

  1. #define PRO
  2. using UnityEngine;
  3. using System.Collections;
  4. namespace ProGrids
  5. {
  6. public enum Axis {
  7. None = 0x0,
  8. X = 0x1,
  9. Y = 0x2,
  10. Z = 0x4,
  11. NegX = 0x8,
  12. NegY = 0x16,
  13. NegZ = 0x32
  14. }
  15. public enum SnapUnit {
  16. Meter,
  17. #if PRO
  18. Centimeter,
  19. Millimeter,
  20. Inch,
  21. Foot,
  22. Yard,
  23. Parsec
  24. #endif
  25. }
  26. public static class pg_Enum
  27. {
  28. /**
  29. * Multiplies a Vector3 using the inverse value of an axis (eg, Axis.Y becomes Vector3(1, 0, 1) )
  30. */
  31. public static Vector3 InverseAxisMask(Vector3 v, Axis axis)
  32. {
  33. switch(axis)
  34. {
  35. case Axis.X:
  36. case Axis.NegX:
  37. return Vector3.Scale(v, new Vector3(0f, 1f, 1f));
  38. case Axis.Y:
  39. case Axis.NegY:
  40. return Vector3.Scale(v, new Vector3(1f, 0f, 1f));
  41. case Axis.Z:
  42. case Axis.NegZ:
  43. return Vector3.Scale(v, new Vector3(1f, 1f, 0f));
  44. default:
  45. return v;
  46. }
  47. }
  48. public static Vector3 AxisMask(Vector3 v, Axis axis)
  49. {
  50. switch(axis)
  51. {
  52. case Axis.X:
  53. case Axis.NegX:
  54. return Vector3.Scale(v, new Vector3(1f, 0f, 0f));
  55. case Axis.Y:
  56. case Axis.NegY:
  57. return Vector3.Scale(v, new Vector3(0f, 1f, 0f));
  58. case Axis.Z:
  59. case Axis.NegZ:
  60. return Vector3.Scale(v, new Vector3(0f, 0f, 1f));
  61. default:
  62. return v;
  63. }
  64. }
  65. public static float SnapUnitValue(SnapUnit su)
  66. {
  67. switch(su)
  68. {
  69. case SnapUnit.Meter:
  70. return pg_Constant.METER;
  71. #if PRO
  72. case SnapUnit.Centimeter:
  73. return pg_Constant.CENTIMETER;
  74. case SnapUnit.Millimeter:
  75. return pg_Constant.MILLIMETER;
  76. case SnapUnit.Inch:
  77. return pg_Constant.INCH;
  78. case SnapUnit.Foot:
  79. return pg_Constant.FOOT;
  80. case SnapUnit.Yard:
  81. return pg_Constant.YARD;
  82. case SnapUnit.Parsec:
  83. return pg_Constant.PARSEC;
  84. #endif
  85. default:
  86. return pg_Constant.METER;
  87. }
  88. }
  89. }
  90. }