void CreateNewPreset()
        {
            string filePath = EditorUtility.SaveFilePanelInProject("Save Terrain Setting Preset", "New Terrain Settings Preset.asset", "asset", "");

            m_SelectedPreset = ScriptableObject.CreateInstance <TerrainSettings>();
            m_SelectedPreset = m_Settings;
            AssetDatabase.CreateAsset(m_SelectedPreset, filePath);
            SavePresetSettings();
        }
예제 #2
0
        public void CopySettingsFrom(TerrainSettings other)
        {
            if (other == null)
            {
                return;
            }

            GroupingID           = other.GroupingID;
            AutoConnect          = other.AutoConnect;
            DrawHeightmap        = other.DrawHeightmap;
            DrawInstanced        = other.DrawInstanced;
            PixelError           = other.PixelError;
            BaseMapDistance      = other.BaseMapDistance;
            ShadowCastingMode    = other.ShadowCastingMode;
            MaterialTemplate     = other.MaterialTemplate;
            ReflectionProbeUsage = other.ReflectionProbeUsage;
#if UNITY_2019_2_OR_NEWER
#else
            MaterialType    = other.MaterialType;
            LegacySpecular  = other.LegacySpecular;
            LegacyShininess = other.LegacyShininess;
#endif

            // mesh resolution
            TerrainWidth             = other.TerrainWidth;
            TerrainHeight            = other.TerrainHeight;
            TerrainLength            = other.TerrainLength;
            DetailResolutaion        = other.DetailResolutaion;
            DetailResolutionPerPatch = other.DetailResolutionPerPatch;

            // texture resolution
            BaseTextureResolution = other.BaseTextureResolution;
            AlphaMapResolution    = other.AlphaMapResolution;
            HeightMapResolution   = other.HeightMapResolution;

            // tree and details
            DrawTreesAndFoliage         = other.DrawTreesAndFoliage;
            BakeLightProbesForTrees     = other.BakeLightProbesForTrees;
            DeringLightProbesForTrees   = other.DeringLightProbesForTrees;
            PreserveTreePrototypeLayers = other.PreserveTreePrototypeLayers;
            DetailObjectDistance        = other.DetailObjectDistance;
            CollectDetailPatches        = other.CollectDetailPatches;
            DetailObjectDensity         = other.DetailObjectDensity;
            TreeDistance            = other.TreeDistance;
            TreeBillboardDistance   = other.TreeBillboardDistance;
            TreeCrossFadeLength     = other.TreeCrossFadeLength;
            TreeMaximumFullLODCount = other.TreeMaximumFullLODCount;

            // grass wind
            WavingGrassStrength = other.WavingGrassStrength;
            WavingGrassSpeed    = other.WavingGrassSpeed;
            WavingGrassAmount   = other.WavingGrassAmount;
            WavingGrassTint     = other.WavingGrassTint;
        }
 void LoadPresetToSettings()
 {
     if (m_SelectedPreset == null)
     {
         EditorUtility.DisplayDialog("Error", "No selected preset found. Select one to continue.", "OK");
         return;
     }
     else
     {
         m_Settings = m_SelectedPreset;
     }
 }
        void ResetToDefaultSettings()
        {
            TerrainSettings defaultSettings = ScriptableObject.CreateInstance <TerrainSettings>();

            defaultSettings.ShowBasicTerrainSettings      = m_Settings.ShowBasicTerrainSettings;
            defaultSettings.ShowMeshResolutionSettings    = m_Settings.ShowMeshResolutionSettings;
            defaultSettings.ShowTextureResolutionSettings = m_Settings.ShowTextureResolutionSettings;
            defaultSettings.ShowTreeAndDetailSettings     = m_Settings.ShowTreeAndDetailSettings;
            defaultSettings.ShowGrassWindSettings         = m_Settings.ShowGrassWindSettings;
            defaultSettings.EnableBasicSettings           = m_Settings.EnableBasicSettings;
            defaultSettings.EnableMeshResSettings         = m_Settings.EnableMeshResSettings;
            defaultSettings.EnableTextureResSettings      = m_Settings.EnableTextureResSettings;
            defaultSettings.EnableTreeSettings            = m_Settings.EnableTreeSettings;
            defaultSettings.EnableWindSettings            = m_Settings.EnableWindSettings;
            m_Settings = defaultSettings;
        }
예제 #5
0
        public void CopyUISettingsFrom(TerrainSettings other)
        {
            if (other == null)
            {
                return;
            }

            ShowBasicTerrainSettings      = other.ShowBasicTerrainSettings;
            ShowMeshResolutionSettings    = other.ShowMeshResolutionSettings;
            ShowTextureResolutionSettings = other.ShowTextureResolutionSettings;
            ShowTreeAndDetailSettings     = other.ShowTreeAndDetailSettings;
            ShowGrassWindSettings         = other.ShowGrassWindSettings;
            EnableBasicSettings           = other.EnableBasicSettings;
            EnableMeshResSettings         = other.EnableMeshResSettings;
            EnableTextureResSettings      = other.EnableTextureResSettings;
            EnableTreeSettings            = other.EnableTreeSettings;
            EnableWindSettings            = other.EnableWindSettings;
        }
예제 #6
0
        public void LoadSettings()
        {
            string filePath = ToolboxHelper.GetPrefFilePath(ToolboxHelper.ToolboxPrefsSettings);

            if (File.Exists(filePath))
            {
                string settingsData = File.ReadAllText(filePath);
                JsonUtility.FromJsonOverwrite(settingsData, m_Settings);
            }

            if (m_Settings.PresetPath == string.Empty)
            {
                m_SelectedPreset = null;
            }
            else
            {
                m_SelectedPreset = AssetDatabase.LoadAssetAtPath(m_Settings.PresetPath, typeof(TerrainSettings)) as TerrainSettings;
            }
        }
        void CreateNewPreset()
        {
            string filePath = EditorUtility.SaveFilePanelInProject("Save Terrain Setting Preset", "New Terrain Settings Preset.asset", "asset", "");

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            if (!File.Exists(filePath))
            {
                m_SelectedPreset = null;
                var newPreset = ScriptableObject.CreateInstance <TerrainSettings>();
                newPreset = m_Settings;
                AssetDatabase.CreateAsset(newPreset, filePath);
            }

            m_SelectedPreset = AssetDatabase.LoadAssetAtPath <TerrainSettings>(filePath);
            SavePresetSettings();
        }
        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();
        }