Skip to content

Save scene-view camera settings in Editor prefs #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
{
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<AntialiasingMode> s_SceneViewAntialiasing = new CachedEditorPref<AntialiasingMode>("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<bool> s_SceneViewStopNaNs = new CachedEditorPref<bool>("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()
Expand All @@ -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
Expand Down