void ShowPresetGUI()
 {
     TerrainToolboxUtilities.DrawSeperatorLine();
     //--EditorGUI.indentLevel;
     EditorGUILayout.BeginHorizontal();
     EditorGUILayout.LabelField(Styles.Preset, EditorStyles.boldLabel);
     EditorGUI.BeginChangeCheck();
     m_SelectedPreset = (TerrainVisualizationSettings)EditorGUILayout.ObjectField(m_SelectedPreset, typeof(TerrainVisualizationSettings), false);
     if (EditorGUI.EndChangeCheck() && m_SelectedPreset != null)
     {
         if (EditorUtility.DisplayDialog("Confirm", "Load terrain creation settings from selected preset?", "OK", "Cancel"))
         {
             LoadVisualizationSettings();
         }
     }
     if (GUILayout.Button(Styles.SavePreset))
     {
         UpdateVisualizationSettings();
         AssetDatabase.SaveAssets();
     }
     if (GUILayout.Button(Styles.SaveAsPreset))
     {
         CreateNewPreset();
     }
     if (GUILayout.Button(Styles.RefreshPreset))
     {
         LoadVisualizationSettings();
     }
     EditorGUILayout.EndHorizontal();
 }
        public void OnGUI()
        {
            // scroll view of settings
            EditorGUIUtility.hierarchyMode = true;
            TerrainToolboxUtilities.DrawSeperatorLine();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(Styles.VisualizationSettings, EditorStyles.boldLabel);
            m_selectedMode = (VISUALIZERMODE)EditorGUILayout.EnumPopup(m_selectedMode);
            EditorGUILayout.EndHorizontal();
            switch (m_selectedMode)
            {
            case VISUALIZERMODE.AltitudeHeatmap:
                ShowHeatmapGUI();
                break;

            default:
                break;
            }

            if (m_Settings.ModeWarning)
            {
                EditorGUILayout.HelpBox(Styles.ModeWarningSettings, MessageType.Warning);
            }

            if (EditorGUI.EndChangeCheck())
            {
                EnableVisualization();
            }

            ShowPresetGUI();
        }
        public void OnGUI()
        {
            //Scroll view of settings
            EditorGUIUtility.hierarchyMode = true;
            TerrainToolboxUtilities.DrawSeperatorLine();

            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.LabelField(Styles.VisualizationSettings, EditorStyles.boldLabel);
            m_selectedMode = (VISUALIZERMODE)EditorGUILayout.EnumPopup(m_selectedMode);
            bool hadVisualModeChange = false;

            if (EditorGUI.EndChangeCheck())
            {
                ToggleVisualization();
                hadVisualModeChange = true;
            }
            EditorGUILayout.EndHorizontal();

            if (m_selectedMode == VISUALIZERMODE.AltitudeHeatmap)
            {
                ShowHeatmapGUI(hadVisualModeChange);
            }

            if (m_ModeWarning)
            {
                EditorGUILayout.HelpBox(Styles.ModeWarningSettings, MessageType.Warning);
            }

            ShowPresetGUI();
        }
        void ShowGizmoGUI()
        {
            TerrainToolboxUtilities.DrawSeperatorLine();
            bool gizmoToggle = m_Settings.EnableGizmo && ToolboxHelper.GizmoGO != null ? true : false;

            m_Settings.ShowGizmoSettings = TerrainToolGUIHelper.DrawToggleHeaderFoldout(Styles.Gizmo, m_Settings.ShowGizmoSettings, ref gizmoToggle, 0f);

            if (gizmoToggle && !ToolboxHelper.GizmoEnabled)
            {
                ToolboxHelper.ShowGizmo();
                ToolboxHelper.UpdateGizmos(m_Settings.TerrainWidth, m_Settings.TerrainHeight, m_Settings.TerrainLength, m_Settings.StartPosition, m_Settings.GroupID);
            }
            else if (!gizmoToggle && ToolboxHelper.GizmoEnabled)
            {
                ToolboxHelper.HideGizmo();
            }

            if (ToolboxHelper.GizmoEnabled && ToolboxHelper.GizmoGO != null)
            {
                if (GUI.changed)
                {
                    ToolboxHelper.UpdateGizmos(m_Settings.TerrainWidth, m_Settings.TerrainHeight, m_Settings.TerrainLength, m_Settings.StartPosition, m_Settings.GroupID);
                }
                else if (ToolboxHelper.GizmoGO.transform.hasChanged)
                {
                    Transform  gizmoTransform = ToolboxHelper.GizmoGO.transform;
                    Vector3Int gizmoScale     = Vector3Int.RoundToInt(gizmoTransform.localScale);
                    m_Settings.TerrainWidth  = gizmoScale.x;
                    m_Settings.TerrainLength = gizmoScale.z;
                    m_Settings.TerrainHeight = gizmoScale.y;
                    m_Settings.StartPosition = ToolboxHelper.GetGizmoPosition();
                }
            }



            // Update gizmo colors
            Color previousColor = m_Settings.GizmoCubeColor + m_Settings.GizmoWireColor;

            if (m_Settings.ShowGizmoSettings)
            {
                EditorGUI.BeginDisabledGroup(!m_Settings.EnableGizmo);
                EditorGUILayout.Space();
                m_Settings.GizmoCubeColor = EditorGUILayout.ColorField(Styles.CubeColor, m_Settings.GizmoCubeColor);
                m_Settings.GizmoWireColor = EditorGUILayout.ColorField(Styles.CubeWireColor, m_Settings.GizmoWireColor);
                EditorGUI.EndDisabledGroup();
            }
            m_Settings.EnableGizmo = gizmoToggle;

            if (previousColor != m_Settings.GizmoCubeColor + m_Settings.GizmoWireColor)
            {
                UnityEditor.SceneView.RepaintAll();
            }

            ToolboxHelper.SetGizmoColor(m_Settings.GizmoCubeColor, m_Settings.GizmoWireColor);
        }
 void ShowOptionsGUI()
 {
     TerrainToolboxUtilities.DrawSeperatorLine();
     m_Settings.ShowOptions = TerrainToolGUIHelper.DrawHeaderFoldout(Styles.Options, m_Settings.ShowOptions);
     ++EditorGUI.indentLevel;
     if (m_Settings.ShowOptions)
     {
         EditorGUILayout.BeginHorizontal();
         m_Settings.TerrainAssetDirectory = EditorGUILayout.TextField(Styles.TerrainDataFolderPath, m_Settings.TerrainAssetDirectory);
         if (GUILayout.Button("...", GUILayout.Width(25)))
         {
             m_Settings.TerrainAssetDirectory = EditorUtility.OpenFolderPanel("Select a folder...", m_Settings.TerrainAssetDirectory, "");
         }
         EditorGUILayout.EndHorizontal();
         m_Settings.EnableGuid = EditorGUILayout.Toggle(Styles.TerrainDataGuidEnable, m_Settings.EnableGuid);
         EditorGUILayout.BeginHorizontal();
         m_Settings.EnableClearExistingData = EditorGUILayout.Toggle(Styles.ClearExistingTerrainData, m_Settings.EnableClearExistingData);
         EditorGUILayout.LabelField(string.Format("Group ID: {0}", m_Settings.GroupID));
         EditorGUILayout.EndHorizontal();
         m_Settings.EnableLightingAutoBake = EditorGUILayout.Toggle(Styles.LightingAutobakeEnable, m_Settings.EnableLightingAutoBake);
     }
 }
        public void OnGUI()
        {
            // scroll view of settings
            EditorGUIUtility.hierarchyMode = true;
            TerrainToolboxUtilities.DrawSeperatorLine();
            m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Load Settings From: ");
            m_SettingsMode = (SettingsMode)GUILayout.Toolbar((int)m_SettingsMode, Styles.SettingsModeToggles, Styles.ToggleButtonStyle, GUI.ToolbarButtonSize.Fixed);

            if (GUILayout.Button("Load"))
            {
                if (m_SettingsMode == SettingsMode.Default)
                {
                    ResetToDefaultSettings();
                }

                if (m_SettingsMode == SettingsMode.SelectedTerrain)
                {
                    LoadSettingsFromSelectedTerrain();
                }

                if (m_SettingsMode == SettingsMode.Preset)
                {
                    LoadPresetToSettings();
                }
            }
            EditorGUILayout.EndHorizontal();

            // Presets
            TerrainToolboxUtilities.DrawSeperatorLine();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(Styles.Preset, EditorStyles.boldLabel);
            EditorGUI.BeginChangeCheck();
            m_SelectedPreset = (TerrainSettings)EditorGUILayout.ObjectField(m_SelectedPreset, typeof(TerrainSettings), false);
            if (EditorGUI.EndChangeCheck() && m_SelectedPreset != null)
            {
                if (EditorUtility.DisplayDialog("Confirm", "Load terrain settings from selected preset?", "OK", "Cancel"))
                {
                    m_Settings = m_SelectedPreset;
                }
            }
            if (GUILayout.Button(Styles.SavePreset))
            {
                if (m_SelectedPreset == null)
                {
                    if (EditorUtility.DisplayDialog("Confirm", "No preset selected. Create a new preset?", "Continue", "Cancel"))
                    {
                        CreateNewPreset();
                    }
                }
                else
                {
                    SavePresetSettings();
                }
            }
            if (GUILayout.Button(Styles.SaveAsPreset))
            {
                CreateNewPreset();
            }
            if (GUILayout.Button(Styles.RefreshPreset))
            {
                LoadPresetToSettings();
            }
            EditorGUILayout.EndHorizontal();

            // basic settings
            TerrainToolboxUtilities.DrawSeperatorLine();
            bool basicSettingToggled = m_Settings.EnableBasicSettings;

            m_Settings.ShowBasicTerrainSettings = TerrainToolGUIHelper.DrawToggleHeaderFoldout(Styles.BasicTerrainSettings, m_Settings.ShowBasicTerrainSettings, ref basicSettingToggled, 0f);
            ++EditorGUI.indentLevel;
            if (m_Settings.ShowBasicTerrainSettings)
            {
                EditorGUI.BeginDisabledGroup(!m_Settings.EnableBasicSettings);
                ShowBasicSettings();
                EditorGUI.EndDisabledGroup();
            }
            --EditorGUI.indentLevel;
            m_Settings.EnableBasicSettings = basicSettingToggled;

            // mesh resolution settings
            TerrainToolboxUtilities.DrawSeperatorLine();
            bool meshSettingToggled = m_Settings.EnableMeshResSettings;

            m_Settings.ShowMeshResolutionSettings = TerrainToolGUIHelper.DrawToggleHeaderFoldout(Styles.MeshResolutionSettings, m_Settings.ShowMeshResolutionSettings, ref meshSettingToggled, 0f);
            ++EditorGUI.indentLevel;
            if (m_Settings.ShowMeshResolutionSettings)
            {
                EditorGUI.BeginDisabledGroup(!m_Settings.EnableMeshResSettings);
                ShowMeshResolutionSettings();
                EditorGUI.EndDisabledGroup();
            }
            --EditorGUI.indentLevel;
            m_Settings.EnableMeshResSettings = meshSettingToggled;

            // texture resolution settings
            TerrainToolboxUtilities.DrawSeperatorLine();
            bool textureSettingToggled = m_Settings.EnableTextureResSettings;

            m_Settings.ShowTextureResolutionSettings = TerrainToolGUIHelper.DrawToggleHeaderFoldout(Styles.TextureResolutionSettings, m_Settings.ShowTextureResolutionSettings, ref textureSettingToggled, 0f);
            ++EditorGUI.indentLevel;
            if (m_Settings.ShowTextureResolutionSettings)
            {
                EditorGUI.BeginDisabledGroup(!m_Settings.EnableTextureResSettings);
                ShowTextureResolutionSettings();
                EditorGUI.EndDisabledGroup();
            }
            --EditorGUI.indentLevel;
            m_Settings.EnableTextureResSettings = textureSettingToggled;

            // trees and details
            TerrainToolboxUtilities.DrawSeperatorLine();
            bool treeSettingToggled = m_Settings.EnableTreeSettings;

            m_Settings.ShowTreeAndDetailSettings = TerrainToolGUIHelper.DrawToggleHeaderFoldout(Styles.TreeAndDetailSettings, m_Settings.ShowTreeAndDetailSettings, ref treeSettingToggled, 0f);
            ++EditorGUI.indentLevel;
            if (m_Settings.ShowTreeAndDetailSettings)
            {
                EditorGUI.BeginDisabledGroup(!m_Settings.EnableTreeSettings);
                ShowTreeAndDetailSettings();
                EditorGUI.EndDisabledGroup();
            }
            --EditorGUI.indentLevel;
            m_Settings.EnableTreeSettings = treeSettingToggled;

            // grass wind
            TerrainToolboxUtilities.DrawSeperatorLine();
            bool grassSettingToggled = m_Settings.EnableWindSettings;

            m_Settings.ShowGrassWindSettings = TerrainToolGUIHelper.DrawToggleHeaderFoldout(Styles.GrassWindSettings, m_Settings.ShowGrassWindSettings, ref grassSettingToggled, 0f);
            ++EditorGUI.indentLevel;
            if (m_Settings.ShowGrassWindSettings)
            {
                EditorGUI.BeginDisabledGroup(!m_Settings.EnableWindSettings);
                ShowGrassWindSettings();
                EditorGUI.EndDisabledGroup();
            }
            --EditorGUI.indentLevel;
            m_Settings.EnableWindSettings = grassSettingToggled;

            --EditorGUI.indentLevel;
            EditorGUILayout.Space();
            EditorGUILayout.EndScrollView();

            // buttons
            TerrainToolboxUtilities.DrawSeperatorLine();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(Styles.ApplySettingsBtn, GUILayout.Height(40)))
            {
                ApplySettingsToSelectedTerrains();
            }
            if (GUILayout.Button(Styles.ApplySettingsToAllBtn, GUILayout.Height(40)))
            {
                if (EditorUtility.DisplayDialog("Confirm", "This operation will apply settings to all terrains in scene. Are you sure you want to continue?", "Continue", "Cancel"))
                {
                    ApplySettingsToAllTerrains();
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }
        public void OnGUI()
        {
            // scroll view of settings
            EditorGUIUtility.hierarchyMode = true;
            TerrainToolboxUtilities.DrawSeperatorLine();
            m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);

            // General Settings
            ShowGeneralGUI();

            // Import Heightmap
            TerrainToolboxUtilities.DrawSeperatorLine();
            bool importHeightmapToggle = m_Settings.EnableHeightmapImport;

            m_Settings.ShowHeightmapSettings = TerrainToolGUIHelper.DrawToggleHeaderFoldout(Styles.ImportHeightmap, m_Settings.ShowHeightmapSettings, ref importHeightmapToggle, 0f);
            ++EditorGUI.indentLevel;
            if (m_Settings.ShowHeightmapSettings)
            {
                EditorGUI.BeginDisabledGroup(!m_Settings.EnableHeightmapImport);
                ShowImportHeightmapGUI();
                EditorGUI.EndDisabledGroup();
            }
            m_Settings.EnableHeightmapImport = importHeightmapToggle;
            --EditorGUI.indentLevel;

            // Gizmos
            ShowGizmoGUI();

            // Presets
            ++EditorGUI.indentLevel;
            ShowPresetGUI();
            EditorGUILayout.EndScrollView();

            // Options
            ShowOptionsGUI();

            // Terrain info box
            --EditorGUI.indentLevel;
            string sizeMsg     = string.Format("Terrain Size: {0}m x {1}m		", m_Settings.TerrainWidth, m_Settings.TerrainLength);
            string tileMsg     = string.Format("Number of Tiles: {0} x {1} \n", m_Settings.TilesX, m_Settings.TilesZ);
            string heightMsg   = string.Format("Terrain Height: {0}m		", m_Settings.TerrainHeight);
            string tileSizeMsg = string.Format("Tile Size: {0} x {1} ", (m_Settings.TerrainWidth / m_Settings.TilesX), (m_Settings.TerrainLength / m_Settings.TilesZ));

            m_TerrainMessage = sizeMsg + tileMsg + heightMsg + tileSizeMsg;
            EditorGUILayout.HelpBox(m_TerrainMessage, MessageType.Info);

            // Create
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(Styles.CreateBtn, GUILayout.Height(40)))
            {
                if (!RunCreateValidations())
                {
                    EditorUtility.DisplayDialog("Error", "There are incompatible terrain creation settings that need to be resolved to continue. Please check Console for details.", "OK");
                }
                else
                {
                    if (m_Settings.EnableHeightmapImport && m_Settings.HeightmapMode == Heightmap.Mode.Global &&
                        File.Exists(m_Settings.GlobalHeightmapPath))
                    {
                        m_Settings.UseGlobalHeightmap = true;
                    }
                    else
                    {
                        m_Settings.UseGlobalHeightmap = false;
                    }

                    Create();
                }
            }
            EditorGUILayout.EndHorizontal();
        }