ColliderTestEditor.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. using UnityEditor;
  4. using UnityEditorInternal;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. namespace VoxelImporter
  10. {
  11. [CustomEditor(typeof(ColliderTest))]
  12. public class ColliderTestEditor : Editor
  13. {
  14. public ColliderTest test { get; protected set; }
  15. void OnEnable()
  16. {
  17. test = target as ColliderTest;
  18. }
  19. public override void OnInspectorGUI()
  20. {
  21. serializedObject.Update();
  22. //GameObject
  23. {
  24. EditorGUI.BeginChangeCheck();
  25. var addObject = (GameObject)EditorGUILayout.ObjectField("GameObject", test.addObject, typeof(GameObject), false);
  26. if (EditorGUI.EndChangeCheck())
  27. {
  28. Undo.RecordObject(test, "Inspector");
  29. test.addObject = addObject;
  30. }
  31. }
  32. //Primitive
  33. if (test.addObject == null)
  34. {
  35. EditorGUI.BeginChangeCheck();
  36. var primitive = (ColliderTest.Primitive)EditorGUILayout.EnumPopup("Primitive", test.primitive);
  37. if (EditorGUI.EndChangeCheck())
  38. {
  39. Undo.RecordObject(test, "Inspector");
  40. test.primitive = primitive;
  41. }
  42. }
  43. //AutoBirth
  44. {
  45. EditorGUI.BeginChangeCheck();
  46. var autoBirth = EditorGUILayout.Toggle("Auto Birth", test.autoBirth);
  47. if (EditorGUI.EndChangeCheck())
  48. {
  49. Undo.RecordObject(test, "Inspector");
  50. test.autoBirth = autoBirth;
  51. }
  52. //Sepalate Time
  53. EditorGUI.indentLevel++;
  54. EditorGUI.BeginDisabledGroup(!test.autoBirth);
  55. EditorGUILayout.BeginHorizontal();
  56. {
  57. EditorGUI.BeginChangeCheck();
  58. var min = test.sepalateTimeMin;
  59. var max = test.sepalateTimeMax;
  60. EditorGUILayout.MinMaxSlider(new GUIContent("Sepalate Time"), ref min, ref max, 0, 10);
  61. if (EditorGUI.EndChangeCheck())
  62. {
  63. Undo.RecordObject(test, "Inspector");
  64. test.sepalateTimeMin = min;
  65. test.sepalateTimeMax = max;
  66. }
  67. }
  68. {
  69. EditorGUI.BeginChangeCheck();
  70. var sepalateTimeMin = EditorGUILayout.FloatField(test.sepalateTimeMin, GUILayout.Width(48));
  71. if (EditorGUI.EndChangeCheck())
  72. {
  73. Undo.RecordObject(test, "Inspector");
  74. test.sepalateTimeMin = sepalateTimeMin;
  75. }
  76. }
  77. {
  78. EditorGUI.BeginChangeCheck();
  79. var sepalateTimeMax = EditorGUILayout.FloatField(test.sepalateTimeMax, GUILayout.Width(48));
  80. if (EditorGUI.EndChangeCheck())
  81. {
  82. Undo.RecordObject(test, "Inspector");
  83. test.sepalateTimeMax = sepalateTimeMax;
  84. }
  85. }
  86. EditorGUILayout.EndHorizontal();
  87. EditorGUI.EndDisabledGroup();
  88. EditorGUI.indentLevel--;
  89. }
  90. //Random
  91. {
  92. EditorGUILayout.LabelField("Random");
  93. EditorGUI.indentLevel++;
  94. {
  95. EditorGUI.BeginChangeCheck();
  96. var randomRadius = EditorGUILayout.FloatField("Radius", test.randomRadius);
  97. if (EditorGUI.EndChangeCheck())
  98. {
  99. Undo.RecordObject(test, "Inspector");
  100. test.randomRadius = randomRadius;
  101. }
  102. }
  103. EditorGUILayout.BeginHorizontal();
  104. {
  105. EditorGUI.BeginChangeCheck();
  106. var min = test.randomScaleMin;
  107. var max = test.randomScaleMax;
  108. EditorGUILayout.MinMaxSlider(new GUIContent("Scale"), ref min, ref max, 1f, 3f);
  109. if (EditorGUI.EndChangeCheck())
  110. {
  111. Undo.RecordObject(test, "Inspector");
  112. test.randomScaleMin = min;
  113. test.randomScaleMax = max;
  114. }
  115. }
  116. {
  117. EditorGUI.BeginChangeCheck();
  118. var randomScaleMin = EditorGUILayout.FloatField(test.randomScaleMin, GUILayout.Width(48));
  119. if (EditorGUI.EndChangeCheck())
  120. {
  121. Undo.RecordObject(test, "Inspector");
  122. test.randomScaleMin = randomScaleMin;
  123. }
  124. }
  125. {
  126. EditorGUI.BeginChangeCheck();
  127. var randomScaleMax = EditorGUILayout.FloatField(test.randomScaleMax, GUILayout.Width(48));
  128. if (EditorGUI.EndChangeCheck())
  129. {
  130. Undo.RecordObject(test, "Inspector");
  131. test.randomScaleMax = randomScaleMax;
  132. }
  133. }
  134. EditorGUILayout.EndHorizontal();
  135. EditorGUI.indentLevel--;
  136. }
  137. //GroundY
  138. {
  139. EditorGUI.BeginChangeCheck();
  140. var groundY = EditorGUILayout.FloatField("GroundY", test.groundY);
  141. if (EditorGUI.EndChangeCheck())
  142. {
  143. Undo.RecordObject(test, "Inspector");
  144. test.groundY = groundY;
  145. }
  146. }
  147. //AddButton
  148. {
  149. EditorGUI.BeginDisabledGroup(!EditorApplication.isPlaying);
  150. if(GUILayout.Button("Add Object", GUILayout.Height(32)))
  151. {
  152. test.Add();
  153. }
  154. EditorGUI.EndDisabledGroup();
  155. }
  156. serializedObject.ApplyModifiedProperties();
  157. }
  158. }
  159. }