/// Makes the inspector ready for the GUI of the editor. Returns false if something went wrong and the GUI /// can't be drawn. private bool PrepareInspector() { Terrain.EditorReference = this; // make sure styles are ready e2dStyles.Init(); // change the look of the elements to something more pretty then the default inspector EditorGUIUtility.LookLikeControls(); EditorGUILayout.Separator(); if (!e2dStyles.Inited) { EditorGUILayout.BeginVertical("HelpBox"); if (e2dStyles.ErrorText != null) { GUILayout.Label(e2dStrings.ERROR_CANT_FIND_ASSETS, e2dStyles.ErrorText); } else { GUILayout.Label(e2dStrings.ERROR_CANT_FIND_ASSETS); } EditorGUILayout.EndVertical(); return(false); } if (e2dEditorUtils.IsAnySceneToolSelected()) { // the user selected some other tools mTool = e2dTerrainTool.NONE; } return(true); }
/// Called when the inspector window is to be drawn. It manages all the GUI drawing and input. public override void OnInspectorGUI() { if (!PrepareInspector()) return; // tools GUI.changed = false; EditorGUILayout.BeginHorizontal(); string[] toolOptions = e2dStrings.EDITOR_TOOLS; mTool = (e2dTerrainTool)GUILayout.Toolbar((int)mTool, toolOptions, GUILayout.MinWidth(0)); EditorGUILayout.EndHorizontal(); if (GeneratorEditor && GeneratorEditor.Tool != e2dGeneratorTool.NONE && mTool == e2dTerrainTool.NONE && Terrain.CurveIntercrossing) { GUI.changed = true; mTool = e2dTerrainTool.EDIT_NODES; } if (GUI.changed && mTool != e2dTerrainTool.NONE) { e2dEditorUtils.DeselectSceneTools(); if (GeneratorEditor) GeneratorEditor.Tool = e2dGeneratorTool.NONE; SceneView.RepaintAll(); } // scene view checks if (mTool != e2dTerrainTool.NONE && mTool != e2dTerrainTool.EDIT_NODES && !Terrain.IsEditable) { mTool = e2dTerrainTool.NONE; DrawToolError(e2dStrings.ERROR_TERRAIN_NOT_CREATED); } else { DrawToolInfo(); switch (mTool) { case e2dTerrainTool.EDIT_NODES: DrawNodesTool(); break; case e2dTerrainTool.ADJUST_HEIGHT: DrawHeightTool(); break; case e2dTerrainTool.FILL_TEXTURE: DrawFillTextureTool(); break; case e2dTerrainTool.CURVE_TEXTURE: DrawCurveTextureTool(); break; case e2dTerrainTool.GRASS: DrawGrassTool(); break; } EditorGUILayout.Separator(); } EditorGUIUtility.LookLikeInspector(); if (e2dUtils.DEBUG_INSPECTOR) { EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(true)); EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Delete Subobjects", GUILayout.ExpandWidth(false))) Terrain.FillMesh.DeleteAllSubobjects(); EditorGUILayout.Separator(); DrawDefaultInspector(); } if (e2dUtils.DEBUG_DUMP_STYLES.Length > 0) { Debug.Log("---------------------"); foreach (GUIStyle style in GUI.skin.customStyles) { if (style.name.Contains(e2dUtils.DEBUG_DUMP_STYLES)) Debug.Log(style.name); } Debug.Log("--------------------"); } }
/// Called when the inspector window is to be drawn. It manages all the GUI drawing and input. public override void OnInspectorGUI() { if (!PrepareInspector()) { return; } // tools GUI.changed = false; EditorGUILayout.BeginHorizontal(); string[] toolOptions = e2dStrings.EDITOR_TOOLS; mTool = (e2dTerrainTool)GUILayout.Toolbar((int)mTool, toolOptions, GUILayout.MinWidth(0)); EditorGUILayout.EndHorizontal(); if (GeneratorEditor && GeneratorEditor.Tool != e2dGeneratorTool.NONE && mTool == e2dTerrainTool.NONE && Terrain.CurveIntercrossing) { GUI.changed = true; mTool = e2dTerrainTool.EDIT_NODES; } if (GUI.changed && mTool != e2dTerrainTool.NONE) { e2dEditorUtils.DeselectSceneTools(); if (GeneratorEditor) { GeneratorEditor.Tool = e2dGeneratorTool.NONE; } SceneView.RepaintAll(); } // scene view checks if (mTool != e2dTerrainTool.NONE && mTool != e2dTerrainTool.EDIT_NODES && !Terrain.IsEditable) { mTool = e2dTerrainTool.NONE; DrawToolError(e2dStrings.ERROR_TERRAIN_NOT_CREATED); } else { DrawToolInfo(); switch (mTool) { case e2dTerrainTool.EDIT_NODES: DrawNodesTool(); break; case e2dTerrainTool.ADJUST_HEIGHT: DrawHeightTool(); break; case e2dTerrainTool.FILL_TEXTURE: DrawFillTextureTool(); break; case e2dTerrainTool.CURVE_TEXTURE: DrawCurveTextureTool(); break; case e2dTerrainTool.GRASS: DrawGrassTool(); break; } EditorGUILayout.Separator(); } EditorGUIUtility.LookLikeInspector(); if (e2dUtils.DEBUG_INSPECTOR) { EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal("box", GUILayout.ExpandWidth(true)); EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Delete Subobjects", GUILayout.ExpandWidth(false))) { Terrain.FillMesh.DeleteAllSubobjects(); } EditorGUILayout.Separator(); DrawDefaultInspector(); } if (e2dUtils.DEBUG_DUMP_STYLES.Length > 0) { Debug.Log("---------------------"); foreach (GUIStyle style in GUI.skin.customStyles) { if (style.name.Contains(e2dUtils.DEBUG_DUMP_STYLES)) { Debug.Log(style.name); } } Debug.Log("--------------------"); } }
/// Makes the inspector ready for the GUI of the editor. Returns false if something went wrong and the GUI /// can't be drawn. private bool PrepareInspector() { Terrain.EditorReference = this; // make sure styles are ready e2dStyles.Init(); // change the look of the elements to something more pretty then the default inspector EditorGUIUtility.LookLikeControls(); EditorGUILayout.Separator(); if (!e2dStyles.Inited) { EditorGUILayout.BeginVertical("HelpBox"); if (e2dStyles.ErrorText != null) GUILayout.Label(e2dStrings.ERROR_CANT_FIND_ASSETS, e2dStyles.ErrorText); else GUILayout.Label(e2dStrings.ERROR_CANT_FIND_ASSETS); EditorGUILayout.EndVertical(); return false; } if (e2dEditorUtils.IsAnySceneToolSelected()) { // the user selected some other tools mTool = e2dTerrainTool.NONE; } return true; }