diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 479815915dc..d47627490bd 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -589,6 +589,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed corrupted values on LayeredLit when using Vertex Color multiply mode to multiply and MSAA is activated. - Fix conflicts with Handles manipulation when performing a Reset in DecalComponent (case 1238833) - Fixed depth prepass and postpass being disabled after changing the shader in the material UI. +- Fixed issue with sceneview camera settings not being saved after Editor restart. ### Changed - Improve MIP selection for decals on Transparents diff --git a/com.unity.render-pipelines.high-definition/Runtime/Utilities/HDAdditionalSceneViewSettings.cs b/com.unity.render-pipelines.high-definition/Runtime/Utilities/HDAdditionalSceneViewSettings.cs index f70ffb78d71..6f629822036 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Utilities/HDAdditionalSceneViewSettings.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Utilities/HDAdditionalSceneViewSettings.cs @@ -11,23 +11,95 @@ static class Styles { public static readonly GUIContent AAMode = EditorGUIUtility.TrTextContent("Camera Anti-aliasing", "The anti-alising mode that will be used in the scene view camera."); public static readonly GUIContent StopNaNs = EditorGUIUtility.TrTextContent("Camera Stop NaNs", "When enabled, any NaNs in the color buffer of the scene view camera will be suppressed."); +#if UNITY_2020_2_OR_NEWER + public static readonly string HelpBox = "Temporal Anti - aliasing in the Scene View is only supported when Always Refresh is enabled."; +#else public static readonly string HelpBox = "Temporal Anti - aliasing in the Scene View is only supported when Animated Materials are enabled."; +#endif + } + + // Helper class to manage editor preferences with local caching. + // Only supports bools, floats and ints/enums, so we keep it local for now. + class CachedEditorPref + { + T m_Storage; + string m_Key; + + public T value + { + // We update the Editor prefs only when writing. Reading goes through the cached local var to ensure that reads have no overhead. + get => m_Storage; + set + { + m_Storage = value; + SetPref(value); + } + } + + // Creates a cached editor preference using the specified key and default value + public CachedEditorPref(string key, T dafaultValue) + { + m_Key = key; + m_Storage = GetOrCreatePref(dafaultValue); + } + + T GetOrCreatePref(T defaultValue) + { + if (EditorPrefs.HasKey(m_Key)) + { + if (typeof(T) == typeof(bool)) + { + return (T)(object)EditorPrefs.GetBool(m_Key); + } + else if (typeof(T) == typeof(float)) + { + return (T)(object)EditorPrefs.GetFloat(m_Key); + } + return (T)(object)EditorPrefs.GetInt(m_Key); + } + else + { + if (typeof(T) == typeof(bool)) + { + EditorPrefs.SetBool(m_Key, (bool)(object)defaultValue); + } + else if (typeof(T) == typeof(float)) + { + EditorPrefs.SetFloat(m_Key, (float)(object)defaultValue); + } + else + { + EditorPrefs.SetInt(m_Key, (int)(object)defaultValue); + } + return defaultValue; + } + } + + void SetPref(T value) + { + if (typeof(T) == typeof(bool)) + EditorPrefs.SetBool(m_Key, (bool)(object)value); + else if (typeof(T) == typeof(float)) + EditorPrefs.SetFloat(m_Key, (float)(object)value); + else + EditorPrefs.SetInt(m_Key, (int)(object)value); + } } - static AntialiasingMode s_SceneViewAntialiasing = AntialiasingMode.None; + static CachedEditorPref s_SceneViewAntialiasing = new CachedEditorPref("HDRP:SceneViewCamera:Antialiasing", AntialiasingMode.None); public static AntialiasingMode sceneViewAntialiasing { - get => s_SceneViewAntialiasing; - set => s_SceneViewAntialiasing = value; + get => s_SceneViewAntialiasing.value; + set => s_SceneViewAntialiasing.value = value; } - static bool s_SceneViewStopNaNs = false; + static CachedEditorPref s_SceneViewStopNaNs = new CachedEditorPref("HDRP:SceneViewCamera:StopNaNs", false); public static bool sceneViewStopNaNs { - get => s_SceneViewStopNaNs; - set => s_SceneViewStopNaNs = value; + get => s_SceneViewStopNaNs.value; + set => s_SceneViewStopNaNs.value = value; } static HDAdditionalSceneViewSettings() @@ -40,11 +112,11 @@ static void DoAdditionalSettings(SceneView sceneView) EditorGUILayout.Space(); EditorGUILayout.LabelField("HD Render Pipeline", EditorStyles.boldLabel); - s_SceneViewAntialiasing = (AntialiasingMode)EditorGUILayout.EnumPopup(Styles.AAMode, s_SceneViewAntialiasing); - if (s_SceneViewAntialiasing == AntialiasingMode.TemporalAntialiasing) + sceneViewAntialiasing = (AntialiasingMode)EditorGUILayout.EnumPopup(Styles.AAMode, sceneViewAntialiasing); + if (sceneViewAntialiasing == AntialiasingMode.TemporalAntialiasing) EditorGUILayout.HelpBox(Styles.HelpBox, MessageType.Info); - s_SceneViewStopNaNs = EditorGUILayout.Toggle(Styles.StopNaNs, s_SceneViewStopNaNs); + sceneViewStopNaNs = EditorGUILayout.Toggle(Styles.StopNaNs, sceneViewStopNaNs); } } #endif