TC_SettingsEditor.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace TerrainComposer2
  5. {
  6. [CustomEditor(typeof(TC_Settings))]
  7. public class TC_SettingsEditor : Editor
  8. {
  9. readonly int[] previewResolutions = new[] { 64, 128, 192, 256, 384, 512 };
  10. readonly string[] previewResolutionsDisplay = new[] { "64", "128", "192", "256", "384", "512" };
  11. // Local Settings
  12. SerializedProperty masterTerrain;
  13. SerializedProperty previewResolution;
  14. SerializedProperty hideTerrainGroup;
  15. SerializedProperty useTCRuntime;
  16. SerializedProperty defaultTerrainHeight;
  17. SerializedProperty generateOffset;
  18. // SerializedProperty scrollAdd;
  19. // Global Settings
  20. SerializedObject global;
  21. SerializedProperty tooltip;
  22. SerializedProperty previewColors;
  23. SerializedProperty colLayerGroup;
  24. SerializedProperty colLayer;
  25. SerializedProperty colMaskNodeGroup;
  26. SerializedProperty colMaskNode;
  27. SerializedProperty colSelectNodeGroup;
  28. SerializedProperty colSelectNode;
  29. SerializedProperty colSelectItemGroup;
  30. SerializedProperty colSelectItem;
  31. SerializedProperty keyZoomIn, keyZoomOut;
  32. SerializedProperty showResolutionWarnings;
  33. SerializedProperty linkScaleToMaskDefault;
  34. public void OnEnable()
  35. {
  36. masterTerrain = serializedObject.FindProperty("masterTerrain");
  37. previewResolution = serializedObject.FindProperty("previewResolution");
  38. hideTerrainGroup = serializedObject.FindProperty("hideTerrainGroup");
  39. useTCRuntime = serializedObject.FindProperty("useTCRuntime");
  40. defaultTerrainHeight = serializedObject.FindProperty("defaultTerrainHeight");
  41. generateOffset = serializedObject.FindProperty("generateOffset");
  42. // scrollAdd = serializedObject.FindProperty("scrollAdd");
  43. global = new SerializedObject(((TC_Settings)target).global);
  44. tooltip = global.FindProperty("tooltip");
  45. previewColors = global.FindProperty("previewColors");
  46. colLayerGroup = global.FindProperty("colLayerGroup");
  47. colLayer = global.FindProperty("colLayer");
  48. colMaskNodeGroup = global.FindProperty("colMaskNodeGroup");
  49. colMaskNode = global.FindProperty("colMaskNode");
  50. colSelectNodeGroup = global.FindProperty("colSelectNodeGroup");
  51. colSelectNode = global.FindProperty("colSelectNode");
  52. colSelectItemGroup = global.FindProperty("colSelectItemGroup");
  53. colSelectItem = global.FindProperty("colSelectItem");
  54. keyZoomIn = global.FindProperty("keyZoomIn");
  55. keyZoomOut = global.FindProperty("keyZoomOut");
  56. showResolutionWarnings = global.FindProperty("showResolutionWarnings");
  57. linkScaleToMaskDefault = global.FindProperty("linkScaleToMaskDefault");
  58. Transform t = ((MonoBehaviour)target).transform;
  59. t.hideFlags = HideFlags.NotEditable | HideFlags.HideInInspector;
  60. }
  61. public override void OnInspectorGUI()
  62. {
  63. if (TC_Settings.instance == null) return;
  64. TC_NodeWindow.Keys();
  65. if (TC_Settings.instance.debugMode) DrawDefaultInspector(); else DrawCustomInspector();
  66. }
  67. public void DrawCustomInspector()
  68. {
  69. TC_GlobalSettings globalSettings = TC_Settings.instance.global;
  70. serializedObject.Update();
  71. global.Update();
  72. TD.DrawSpacer();
  73. TD.DrawLabelWidthUnderline("Local Settings", 14);
  74. EditorGUILayout.BeginVertical("Box");
  75. GUILayout.Space(5);
  76. TD.DrawProperty(masterTerrain, new GUIContent("Master Terrain", globalSettings.tooltip ? "This terrain is used for selecting the splat textures, grass textures and trees in the nodes." : ""));
  77. EditorGUILayout.BeginHorizontal();
  78. EditorGUILayout.PrefixLabel(new GUIContent("Node Preview Image Resolution", globalSettings.tooltip ? "The resolution of the node preview images." : ""));
  79. previewResolution.intValue = EditorGUILayout.IntPopup(previewResolution.intValue, previewResolutionsDisplay, previewResolutions);
  80. EditorGUILayout.EndHorizontal();
  81. TD.DrawProperty(hideTerrainGroup, new GUIContent("Hide TerrainLayer GameObject"));
  82. if (GUI.changed)
  83. {
  84. serializedObject.ApplyModifiedProperties();
  85. TC_NodeWindow.DebugMode();
  86. }
  87. TD.DrawProperty(useTCRuntime);
  88. if (GUI.changed)
  89. {
  90. if (!useTCRuntime.boolValue) TC_Settings.instance.transform.parent.tag = "EditorOnly"; else TC_Settings.instance.transform.parent.tag = "Untagged";
  91. }
  92. TD.DrawProperty(defaultTerrainHeight);
  93. TD.DrawProperty(generateOffset);
  94. // TD.DrawProperty(scrollAdd);
  95. EditorGUILayout.EndVertical();
  96. GUILayout.Space(10);
  97. TD.DrawSpacer();
  98. GUILayout.Space(10);
  99. TD.DrawLabelWidthUnderline("Global Settings", 14);
  100. GUILayout.Space(5);
  101. EditorGUILayout.BeginVertical("Box");
  102. TD.DrawProperty(tooltip);
  103. TD.DrawProperty(showResolutionWarnings);
  104. GUI.changed = false;
  105. Vector3 defaultTerrainSize = globalSettings.defaultTerrainSize;
  106. defaultTerrainSize = EditorGUILayout.Vector3Field("Default Node Size", defaultTerrainSize);
  107. if (GUI.changed)
  108. {
  109. Undo.RecordObject(globalSettings, "Default Terrain Size");
  110. globalSettings.defaultTerrainSize = defaultTerrainSize;
  111. EditorUtility.SetDirty(globalSettings);
  112. }
  113. EditorGUILayout.EndVertical();
  114. GUILayout.Space(5);
  115. TD.DrawLabelWidthUnderline("Trees and Objects", 12);
  116. EditorGUILayout.BeginVertical("Box");
  117. TD.DrawProperty(linkScaleToMaskDefault, new GUIContent("Link Scale To Mask Default"));
  118. EditorGUILayout.EndVertical();
  119. GUILayout.Space(5);
  120. TD.DrawLabelWidthUnderline("Keys", 12);
  121. EditorGUILayout.BeginVertical("Box");
  122. TD.DrawProperty(keyZoomIn);
  123. TD.DrawProperty(keyZoomOut);
  124. EditorGUILayout.EndVertical();
  125. TD.DrawLabelWidthUnderline("Node Colors", 12);
  126. EditorGUILayout.BeginVertical("Box");
  127. TD.DrawProperty(colLayerGroup, new GUIContent("Color Layer Group"));
  128. TD.DrawProperty(colLayer, new GUIContent("Color Layer"));
  129. TD.DrawProperty(colMaskNodeGroup, new GUIContent("Color Mask Node Group"));
  130. TD.DrawProperty(colMaskNode, new GUIContent("Color Mask Node"));
  131. TD.DrawProperty(colSelectNodeGroup, new GUIContent("Color Select Node Group"));
  132. TD.DrawProperty(colSelectNode, new GUIContent("Color Select Node"));
  133. TD.DrawProperty(colSelectItemGroup, new GUIContent("Color Select Item Group"));
  134. TD.DrawProperty(colSelectItem, new GUIContent("Color Select Item"));
  135. EditorGUILayout.EndVertical();
  136. GUILayout.Space(5);
  137. TD.DrawPropertyArray(previewColors);
  138. TD.DrawSpacer();
  139. serializedObject.ApplyModifiedProperties();
  140. global.ApplyModifiedProperties();
  141. }
  142. }
  143. }