Assignment for RMIT Mixed Reality in 2020
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.

140 lines
5.8 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System.Diagnostics;
  6. public static class OVREditorUtil {
  7. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  8. public static void SetupBoolField(Object target, string name, ref bool member, ref bool modified)
  9. {
  10. SetupBoolField(target, new GUIContent(name), ref member, ref modified);
  11. }
  12. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  13. public static void SetupBoolField(Object target, GUIContent name, ref bool member, ref bool modified)
  14. {
  15. EditorGUI.BeginChangeCheck();
  16. bool value = EditorGUILayout.Toggle(name, member);
  17. if (EditorGUI.EndChangeCheck())
  18. {
  19. Undo.RecordObject(target, "Changed " + name);
  20. member = value;
  21. modified = true;
  22. }
  23. }
  24. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  25. public static void SetupIntField(Object target, string name, ref int member, ref bool modified)
  26. {
  27. SetupIntField(target, new GUIContent(name), ref member, ref modified);
  28. }
  29. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  30. public static void SetupIntField(Object target, GUIContent name, ref int member, ref bool modified)
  31. {
  32. EditorGUI.BeginChangeCheck();
  33. int value = EditorGUILayout.IntField(name, member);
  34. if (EditorGUI.EndChangeCheck())
  35. {
  36. Undo.RecordObject(target, "Changed " + name);
  37. member = value;
  38. modified = true;
  39. }
  40. }
  41. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  42. public static void SetupFloatField(Object target, string name, ref float member, ref bool modified)
  43. {
  44. SetupFloatField(target, new GUIContent(name), ref member, ref modified);
  45. }
  46. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  47. public static void SetupFloatField(Object target, GUIContent name, ref float member, ref bool modified)
  48. {
  49. EditorGUI.BeginChangeCheck();
  50. float value = EditorGUILayout.FloatField(name, member);
  51. if (EditorGUI.EndChangeCheck())
  52. {
  53. Undo.RecordObject(target, "Changed " + name);
  54. member = value;
  55. modified = true;
  56. }
  57. }
  58. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  59. public static void SetupDoubleField(Object target, string name, ref double member, ref bool modified)
  60. {
  61. SetupDoubleField(target, new GUIContent(name), ref member, ref modified);
  62. }
  63. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  64. public static void SetupDoubleField(Object target, GUIContent name, ref double member, ref bool modified)
  65. {
  66. EditorGUI.BeginChangeCheck();
  67. double value = EditorGUILayout.DoubleField(name, member);
  68. if (EditorGUI.EndChangeCheck())
  69. {
  70. Undo.RecordObject(target, "Changed " + name);
  71. member = value;
  72. modified = true;
  73. }
  74. }
  75. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  76. public static void SetupColorField(Object target, string name, ref Color member, ref bool modified)
  77. {
  78. SetupColorField(target, new GUIContent(name), ref member, ref modified);
  79. }
  80. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  81. public static void SetupColorField(Object target, GUIContent name, ref Color member, ref bool modified)
  82. {
  83. EditorGUI.BeginChangeCheck();
  84. Color value = EditorGUILayout.ColorField(name, member);
  85. if (EditorGUI.EndChangeCheck())
  86. {
  87. Undo.RecordObject(target, "Changed " + name);
  88. member = value;
  89. modified = true;
  90. }
  91. }
  92. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  93. public static void SetupLayerMaskField(Object target, string name, ref LayerMask layerMask, string[] layerMaskOptions, ref bool modified)
  94. {
  95. SetupLayerMaskField(target, new GUIContent(name), ref layerMask, layerMaskOptions, ref modified);
  96. }
  97. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  98. public static void SetupLayerMaskField(Object target, GUIContent name, ref LayerMask layerMask, string[] layerMaskOptions, ref bool modified)
  99. {
  100. EditorGUI.BeginChangeCheck();
  101. int value = EditorGUILayout.MaskField(name, layerMask, layerMaskOptions);
  102. if (EditorGUI.EndChangeCheck())
  103. {
  104. Undo.RecordObject(target, "Changed " + name);
  105. layerMask = value;
  106. }
  107. }
  108. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  109. public static void SetupEnumField<T>(Object target, string name, ref T member, ref bool modified) where T : struct
  110. {
  111. SetupEnumField(target, new GUIContent(name), ref member, ref modified);
  112. }
  113. [Conditional("UNITY_EDITOR_WIN"), Conditional("UNITY_STANDALONE_WIN"), Conditional("UNITY_ANDROID")]
  114. public static void SetupEnumField<T>(Object target, GUIContent name, ref T member, ref bool modified) where T : struct
  115. {
  116. EditorGUI.BeginChangeCheck();
  117. T value = (T)(object)EditorGUILayout.EnumPopup(name, member as System.Enum);
  118. if (EditorGUI.EndChangeCheck())
  119. {
  120. Undo.RecordObject(target, "Changed " + name);
  121. member = value;
  122. modified = true;
  123. }
  124. }
  125. }