CoreRenderPipelinePreferences.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. namespace UnityEngine.Rendering
  2. {
  3. // This file can't be in the editor assembly as we need to access it in runtime-editor-specific
  4. // places like OnGizmo etc and we don't want to add the editor assembly as a dependency of the
  5. // runtime one
  6. // The UI layout/styling in this panel is broken and can't match the one from built-ins
  7. // preference panels as everything needed is internal/private (at the time of writing this
  8. // comment)
  9. #if UNITY_EDITOR
  10. using UnityEditor;
  11. public static class CoreRenderPipelinePreferences
  12. {
  13. static bool m_Loaded = false;
  14. static Color s_VolumeGizmoColor = new Color(0.2f, 0.8f, 0.1f, 0.5f);
  15. public static Color volumeGizmoColor
  16. {
  17. get => s_VolumeGizmoColor;
  18. set
  19. {
  20. if (s_VolumeGizmoColor == value) return;
  21. s_VolumeGizmoColor = value;
  22. EditorPrefs.SetInt(Keys.volumeGizmoColor, (int)ColorUtils.ToHex(value));
  23. }
  24. }
  25. static class Keys
  26. {
  27. internal const string volumeGizmoColor = "CoreRP.Volume.GizmoColor";
  28. }
  29. [SettingsProvider]
  30. static SettingsProvider PreferenceGUI()
  31. {
  32. return new SettingsProvider("Preferences/Core Render Pipeline", SettingsScope.User)
  33. {
  34. guiHandler = searchContext =>
  35. {
  36. if (!m_Loaded)
  37. Load();
  38. volumeGizmoColor = EditorGUILayout.ColorField("Volume Gizmo Color", volumeGizmoColor);
  39. }
  40. };
  41. }
  42. static CoreRenderPipelinePreferences()
  43. {
  44. Load();
  45. }
  46. static void Load()
  47. {
  48. s_VolumeGizmoColor = GetColor(Keys.volumeGizmoColor, new Color(0.2f, 0.8f, 0.1f, 0.5f));
  49. m_Loaded = true;
  50. }
  51. static Color GetColor(string key, Color defaultValue)
  52. {
  53. int value = EditorPrefs.GetInt(key, (int)ColorUtils.ToHex(defaultValue));
  54. return ColorUtils.ToRGBA((uint)value);
  55. }
  56. }
  57. #endif
  58. }