using System; using System.Collections.Generic; using UnityEngine; using RuntimeSRPPreferences = UnityEngine.Rendering.CoreRenderPipelinePreferences; namespace UnityEditor.Rendering { /// /// Preferences for Volumes /// public class VolumesPreferences : ICoreRenderPipelinePreferencesProvider { static class Keys { internal const string volumeGizmosVisibility = "General.VolumeGizmosVisibility"; } /// /// Enum for visibility of gizmos /// [Flags] public enum VolumeGizmoVisibility { /// /// Wireframe /// Wireframe = 1, /// /// Solid /// Solid = 2, /// /// Everything /// Everything = Wireframe | Solid } class Styles { public static readonly GUIContent volumeGizmosVisibilityLabel = EditorGUIUtility.TrTextContent("Gizmo Visibility", "Specifies how Gizmos for Volumes are being rendered"); } static VolumeGizmoVisibility s_VolumeGizmosVisibilityOption = VolumeGizmoVisibility.Solid; static VolumesPreferences() { GetColorPrefVolumeGizmoColor = RuntimeSRPPreferences.RegisterPreferenceColor("Scene/Volume Gizmo", s_VolumeGizmoColorDefault); if (EditorPrefs.HasKey(Keys.volumeGizmosVisibility)) s_VolumeGizmosVisibilityOption = (VolumeGizmoVisibility)EditorPrefs.GetInt(Keys.volumeGizmosVisibility); } /// /// The current option for the visibility /// public static VolumeGizmoVisibility volumeGizmosVisibilityOption { get => s_VolumeGizmosVisibilityOption; set { s_VolumeGizmosVisibilityOption = value; EditorPrefs.SetInt(Keys.volumeGizmosVisibility, (int)s_VolumeGizmosVisibilityOption); } } /// /// Returns if the Volume Gizmos should render the wireframe edges /// public static bool drawWireFrame => (volumeGizmosVisibilityOption & VolumeGizmoVisibility.Wireframe) == VolumeGizmoVisibility.Wireframe; /// /// Returns if the Volume Gizmos should render the solid faces /// public static bool drawSolid => (volumeGizmosVisibilityOption & VolumeGizmoVisibility.Solid) == VolumeGizmoVisibility.Solid; static Color s_VolumeGizmoColorDefault = new Color(0.2f, 0.8f, 0.1f, 0.125f); private static Func GetColorPrefVolumeGizmoColor; /// /// Returns the user defined color for rendering volume gizmos /// public static Color volumeGizmoColor => GetColorPrefVolumeGizmoColor(); static List s_SearchKeywords = new() { "Gizmo", "Wireframe", "Visibility" }; /// /// The keywords /// public List keywords => s_SearchKeywords; /// /// The header /// public GUIContent header { get; } = EditorGUIUtility.TrTextContent("Volumes"); /// /// The method that draws the UI /// public void PreferenceGUI() { EditorGUI.BeginChangeCheck(); var newValue = EditorGUILayout.EnumPopup(Styles.volumeGizmosVisibilityLabel, volumeGizmosVisibilityOption); if (EditorGUI.EndChangeCheck()) { volumeGizmosVisibilityOption = (VolumeGizmoVisibility)newValue; } } } }