예제 #1
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;
        }
예제 #2
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;
        }
예제 #3
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;
            }
        }
예제 #4
0
        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.CopySettingsFrom(m_Settings);
                newPreset.CopyUISettingsFrom(m_Settings);
                AssetDatabase.CreateAsset(newPreset, filePath);
            }

            m_SelectedPreset = AssetDatabase.LoadAssetAtPath <TerrainSettings>(filePath);
            SavePresetSettings();
        }
예제 #5
0
        public void OnGUI()
        {
            // scroll view of settings
            EditorGUIUtility.hierarchyMode = true;
            TerrainToolboxUtilities.DrawSeperatorLine();
            m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Load Settings", EditorStyles.boldLabel);
            if (GUILayout.Button(Styles.LoadDefaultBtn))
            {
                ResetToDefaultSettings();
            }
            if (GUILayout.Button(Styles.LoadSelectedBtn))
            {
                LoadSettingsFromSelectedTerrain();
            }
            if (GUILayout.Button(Styles.LoadPresetBtn))
            {
                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"))
                {
                    LoadPresetToSettings();
                }
            }
            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)))
            {
                ApplySettingsToAllTerrains("This operation will apply settings to all terrains in scene.");
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }