MegaModifyObjectEditor.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using UnityEngine;
  2. using UnityEditor;
  3. //using System.Reflection;
  4. [CanEditMultipleObjects, CustomEditor(typeof(MegaModifyObject))]
  5. public class MegaModifyObjectEditor : Editor
  6. {
  7. Texture image;
  8. //bool showhelp = false;
  9. bool showorder = false;
  10. bool showmulti = false;
  11. bool showgroups = false;
  12. public override void OnInspectorGUI()
  13. {
  14. MegaModifyObject mod = (MegaModifyObject)target;
  15. if ( !mod.readable ) //mod.mesh && !mod.mesh.isReadable )
  16. {
  17. EditorGUILayout.BeginVertical("box");
  18. EditorGUILayout.HelpBox("Mesh is not readable\nPlease change the Read/Write Import Setting for this Object.\n", MessageType.Warning);
  19. EditorGUILayout.EndVertical();
  20. }
  21. MegaModifiers.GlobalDisplay = EditorGUILayout.Toggle("GlobalDisplayGizmos", MegaModifiers.GlobalDisplay);
  22. mod.Enabled = EditorGUILayout.Toggle("Enabled", mod.Enabled);
  23. mod.recalcnorms = EditorGUILayout.Toggle("Recalc Normals", mod.recalcnorms);
  24. MegaNormalMethod method = mod.NormalMethod;
  25. mod.NormalMethod = (MegaNormalMethod)EditorGUILayout.EnumPopup("Normal Method", mod.NormalMethod);
  26. mod.recalcbounds = EditorGUILayout.Toggle("Recalc Bounds", mod.recalcbounds);
  27. mod.recalcCollider = EditorGUILayout.Toggle("Recalc Collider", mod.recalcCollider);
  28. mod.recalcTangents = EditorGUILayout.Toggle("Recalc Tangents", mod.recalcTangents);
  29. //mod.DoLateUpdate = EditorGUILayout.Toggle("Do Late Update", mod.DoLateUpdate);
  30. mod.UpdateMode = (MegaUpdateMode)EditorGUILayout.EnumPopup("Update Mode", mod.UpdateMode);
  31. mod.InvisibleUpdate = EditorGUILayout.Toggle("Invisible Update", mod.InvisibleUpdate);
  32. bool dynamicMesh = EditorGUILayout.Toggle("Dynamic Mesh", mod.dynamicMesh);
  33. if ( dynamicMesh != mod.dynamicMesh )
  34. {
  35. mod.dynamicMesh = dynamicMesh;
  36. mod.GetMesh(true);
  37. }
  38. //mod.GrabVerts = EditorGUILayout.Toggle("Grab Verts", mod.GrabVerts);
  39. mod.DrawGizmos = EditorGUILayout.Toggle("Draw Gizmos", mod.DrawGizmos);
  40. if ( mod.NormalMethod != method && mod.NormalMethod == MegaNormalMethod.Mega )
  41. {
  42. mod.BuildNormalMapping(mod.mesh, false);
  43. }
  44. //showmulti = EditorGUILayout.Foldout(showmulti, "Multi Core");
  45. #if !UNITY_FLASH && !UNITY_METRO && !UNITY_WP8
  46. EditorGUILayout.BeginHorizontal();
  47. if ( GUILayout.Button("Copy Object") )
  48. {
  49. GameObject obj = MegaCopyObject.DoCopyObjects(mod.gameObject);
  50. if ( obj )
  51. {
  52. obj.transform.position = mod.gameObject.transform.position;
  53. Selection.activeGameObject = obj;
  54. }
  55. }
  56. if ( GUILayout.Button("Copy Hierarchy") )
  57. {
  58. GameObject obj = MegaCopyObject.DoCopyObjectsChildren(mod.gameObject);
  59. Selection.activeGameObject = obj;
  60. }
  61. EditorGUILayout.EndHorizontal();
  62. #endif
  63. if ( GUILayout.Button("Threading Options") )
  64. showmulti = !showmulti;
  65. if ( showmulti )
  66. {
  67. MegaModifiers.ThreadingOn = EditorGUILayout.Toggle("Threading Enabled", MegaModifiers.ThreadingOn);
  68. mod.UseThreading = EditorGUILayout.Toggle("Thread This Object", mod.UseThreading);
  69. }
  70. #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019
  71. EditorGUIUtility.LookLikeControls();
  72. #endif
  73. if ( GUI.changed )
  74. {
  75. EditorUtility.SetDirty(target);
  76. }
  77. showorder = EditorGUILayout.Foldout(showorder, "Modifier Order");
  78. if ( showorder && mod.mods != null )
  79. {
  80. for ( int i = 0; i < mod.mods.Length; i++ )
  81. {
  82. EditorGUILayout.BeginHorizontal("box");
  83. EditorGUILayout.LabelField("", i.ToString() + " - " + mod.mods[i].ModName() + " " + mod.mods[i].Order + " MaxLOD: " + mod.mods[i].MaxLOD);
  84. if ( mod.mods[i].Label != "" )
  85. EditorGUILayout.LabelField("\t" + mod.mods[i].Label);
  86. #if false
  87. if ( i > 0 )
  88. {
  89. if ( GUILayout.Button("Up", GUILayout.Width(40)) )
  90. {
  91. MegaModifier m = mod.mods[i - 1];
  92. mod.mods[i - 1] = mod.mods[i];
  93. mod.mods[i] = m;
  94. }
  95. }
  96. if ( i < mod.mods.Length - 1 )
  97. {
  98. if ( GUILayout.Button("Down", GUILayout.Width(40)) )
  99. {
  100. MegaModifier m = mod.mods[i + 1];
  101. mod.mods[i + 1] = mod.mods[i];
  102. mod.mods[i] = m;
  103. }
  104. }
  105. #endif
  106. EditorGUILayout.EndHorizontal();
  107. }
  108. }
  109. // Group stuff
  110. if ( GUILayout.Button("Group Members") )
  111. showgroups = !showgroups;
  112. if ( showgroups )
  113. {
  114. //if ( GUILayout.Button("Add Object") )
  115. //{
  116. //MegaModifierTarget targ = new MegaModifierTarget();
  117. // mod.group.Add(targ);
  118. //}
  119. for ( int i = 0; i < mod.group.Count; i++ )
  120. {
  121. EditorGUILayout.BeginHorizontal();
  122. mod.group[i] = (GameObject)EditorGUILayout.ObjectField("Obj " + i, mod.group[i], typeof(GameObject), true);
  123. if ( GUILayout.Button("Del") )
  124. {
  125. mod.group.Remove(mod.group[i]);
  126. i--;
  127. }
  128. EditorGUILayout.EndHorizontal();
  129. }
  130. GameObject newobj = (GameObject)EditorGUILayout.ObjectField("Add", null, typeof(GameObject), true);
  131. if ( newobj )
  132. {
  133. mod.group.Add(newobj);
  134. }
  135. if ( GUILayout.Button("Update") )
  136. {
  137. // for each group member check if it has a modify object comp, if not add one and copy values over
  138. // calculate box for all meshes and set, and set the Offset for each one
  139. // then for each modifier attached find or add and set instance value
  140. // in theory each gizmo should overlap the others
  141. // Have a method to update box and offsets if we allow moving in the group
  142. }
  143. }
  144. //if ( GUILayout.Button("Create Copy") )
  145. //{
  146. // CloneObject();
  147. //}
  148. }
  149. #if false
  150. // Could do fields and just not do mesh jobs
  151. // I am going to need a copy method for each modifier
  152. // Make a new version of the object in the scene, should be a non editor method for this
  153. GameObject CloneObject()
  154. {
  155. MegaModifyObject modobj = (MegaModifyObject)target;
  156. GameObject obj = modobj.gameObject;
  157. MonoBehaviour[] comps = obj.GetComponents<MonoBehaviour>();
  158. Debug.Log("Comps " + comps.Length);
  159. GameObject newobj = new GameObject(obj.name + " Copy");
  160. for ( int i = 0; i < comps.Length; i++ )
  161. {
  162. MonoBehaviour newcomp = (MonoBehaviour)newobj.AddComponent(comps[i].GetType());
  163. //EditorUtility.CopySerialized(comps[i], newcomp);
  164. foreach ( FieldInfo f in comps[i].GetType().GetFields() )
  165. {
  166. Debug.Log("field " + f.Name);
  167. f.SetValue(newcomp, f.GetValue(comps[i]));
  168. }
  169. #if false
  170. foreach ( FieldInfo info in comps[i].GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.NonPublic) )
  171. {
  172. Debug.Log("field " + info.Name);
  173. if ( info.IsPublic || info.GetCustomAttributes(typeof(SerializeField), true).Length != 0 )
  174. {
  175. info.SetValue(newcomp, info.GetValue(comps[i]));
  176. }
  177. }
  178. #endif
  179. }
  180. return newobj;
  181. }
  182. // Build a prefab of the object
  183. void MakePrefab()
  184. {
  185. }
  186. #endif
  187. }