MegaMeshPageEditor.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. using UnityEditor;
  3. [CanEditMultipleObjects, CustomEditor(typeof(MegaMeshPage))]
  4. public class MegaMeshPageEditor : Editor
  5. {
  6. [MenuItem("GameObject/Create Other/MegaShape/Page Mesh")]
  7. static void CreatePageMesh()
  8. {
  9. Vector3 pos = Vector3.zero;
  10. if ( UnityEditor.SceneView.lastActiveSceneView != null )
  11. pos = UnityEditor.SceneView.lastActiveSceneView.pivot;
  12. GameObject go = new GameObject("Page Mesh");
  13. MeshFilter mf = go.AddComponent<MeshFilter>();
  14. mf.sharedMesh = new Mesh();
  15. MeshRenderer mr = go.AddComponent<MeshRenderer>();
  16. Material[] mats = new Material[3];
  17. mr.sharedMaterials = mats;
  18. MegaMeshPage pm = go.AddComponent<MegaMeshPage>();
  19. go.transform.position = pos;
  20. Selection.activeObject = go;
  21. pm.Rebuild();
  22. }
  23. public override void OnInspectorGUI()
  24. {
  25. MegaMeshPage mod = (MegaMeshPage)target;
  26. //bool rebuild = DrawDefaultInspector();
  27. #if !UNITY_5 && !UNITY_2017 && !UNITY_2018 && !UNITY_2019 && !UNITY_2020
  28. EditorGUIUtility.LookLikeControls();
  29. #endif
  30. mod.Width = EditorGUILayout.FloatField("Width", mod.Width);
  31. mod.Length = EditorGUILayout.FloatField("Length", mod.Length);
  32. mod.Height = EditorGUILayout.FloatField("Height", mod.Height);
  33. mod.WidthSegs = EditorGUILayout.IntField("Width Segs", mod.WidthSegs);
  34. mod.LengthSegs = EditorGUILayout.IntField("Length Segs", mod.LengthSegs);
  35. mod.HeightSegs = EditorGUILayout.IntField("Height Segs", mod.HeightSegs);
  36. mod.genUVs = EditorGUILayout.Toggle("Gen UVs", mod.genUVs);
  37. mod.rotate = EditorGUILayout.FloatField("Rotate", mod.rotate);
  38. mod.PivotBase = EditorGUILayout.Toggle("Pivot Base", mod.PivotBase);
  39. mod.PivotEdge = EditorGUILayout.Toggle("Pivot Edge", mod.PivotEdge);
  40. mod.tangents = EditorGUILayout.Toggle("Tangents", mod.tangents);
  41. #if UNITY_5_5 || UNITY_5_6 || UNITY_2017 || UNITY_2018 || UNITY_2019 || UNITY_2020
  42. #else
  43. mod.optimize = EditorGUILayout.Toggle("Optimize", mod.optimize);
  44. #endif
  45. if ( GUI.changed ) //rebuild )
  46. mod.Rebuild();
  47. }
  48. }