using System.Collections.Generic; using System.Linq.Expressions; using UnityEngine; using System.Reflection; using UnityEngine.Rendering.HighDefinition; using Object = UnityEngine.Object; using System; namespace UnityEditor.Rendering.HighDefinition { interface IHDProbeEditor { Object target { get; } HDProbe GetTarget(Object editorTarget); bool showChromeGizmo { get; set; } } abstract class HDProbeEditor : Editor, IHDProbeEditor, IDefaultFrameSettingsType where TProvider : struct, HDProbeUI.IProbeUISettingsProvider, InfluenceVolumeUI.IInfluenceUISettingsProvider where TSerialized : SerializedHDProbe { static Dictionary s_Editors = new Dictionary(); internal static Editor GetEditorFor(Component p) => s_Editors.TryGetValue(p, out Editor e) ? e : null; protected abstract TSerialized NewSerializedObject(SerializedObject so); internal abstract HDProbe GetTarget(Object editorTarget); HDProbe IHDProbeEditor.GetTarget(Object editorTarget) => GetTarget(editorTarget); TSerialized m_SerializedHDProbe; Dictionary m_SerializedHDProbePerTarget; protected HDProbe[] m_TypedTargets; public override void OnInspectorGUI() { if (HDEditorUtils.IsPresetEditor(this)) { EditorGUILayout.HelpBox(HDProbeUI.k_UnsupportedPresetPropertiesMessage, MessageType.Info); } else { m_SerializedHDProbe.Update(); EditorGUI.BeginChangeCheck(); Draw(m_SerializedHDProbe, this); if (EditorGUI.EndChangeCheck()) m_SerializedHDProbe.Apply(); } } const string k_ShowChromeGizmoKey = "HDRP:ReflectionProbe:ChromeGizmo"; static bool m_ShowChromeGizmo = true; public bool showChromeGizmo { get => m_ShowChromeGizmo; set { m_ShowChromeGizmo = value; EditorPrefs.SetBool(k_ShowChromeGizmoKey, value); } } protected virtual void OnEnable() { m_SerializedHDProbe = NewSerializedObject(serializedObject); if (EditorPrefs.HasKey(k_ShowChromeGizmoKey)) m_ShowChromeGizmo = EditorPrefs.GetBool(k_ShowChromeGizmoKey); m_SerializedHDProbePerTarget = new Dictionary(targets.Length); m_TypedTargets = new HDProbe[targets.Length]; for (var i = 0; i < m_TypedTargets.Length; i++) { m_TypedTargets[i] = GetTarget(targets[i]); var so = new SerializedObject(targets[i]); m_SerializedHDProbePerTarget[targets[i]] = NewSerializedObject(so); } foreach (var target in serializedObject.targetObjects) s_Editors[(Component)target] = this; HDProbeUI.RegisterEditor(this); Undo.undoRedoPerformed += ReconstructReferenceToAdditionalDataSO; } void ReconstructReferenceToAdditionalDataSO() { OnDisable(); OnEnable(); } protected virtual void OnDisable() { foreach (var target in serializedObject.targetObjects) { if (target != null && !target.Equals(null)) s_Editors.Remove((Component)target); } HDProbeUI.UnregisterEditor(this); Undo.undoRedoPerformed -= ReconstructReferenceToAdditionalDataSO; } protected virtual void Draw(TSerialized serialized, Editor owner) { HDProbeUI.Drawer.DrawToolbars(serialized, owner); HDProbeUI.Drawer.DrawPrimarySettings(serialized, owner); //note: cannot use 'using CED = something' due to templated type passed. CoreEditorDrawer.Group( CoreEditorDrawer.FoldoutGroup(HDProbeUI.k_ProxySettingsHeader, HDProbeUI.Expandable.Projection, HDProbeUI.k_ExpandedState, HDProbeUI.Drawer.DrawProjectionSettings), CoreEditorDrawer.FoldoutGroup(HDProbeUI.k_InfluenceVolumeHeader, HDProbeUI.Expandable.Influence, HDProbeUI.k_ExpandedState, HDProbeUI.Drawer.DrawInfluenceSettings, HDProbeUI.Drawer_DifferentShapeError ), CoreEditorDrawer.AdditionalPropertiesFoldoutGroup(HDProbeUI.k_CaptureSettingsHeader, HDProbeUI.Expandable.Capture, HDProbeUI.k_ExpandedState, HDProbeUI.AdditionalProperties.Capture, HDProbeUI.k_AdditionalPropertiesState, CoreEditorDrawer.Group( DrawAdditionalCaptureSettings, HDProbeUI.Drawer.DrawCaptureSettings ), HDProbeUI.Drawer.DrawCaptureSettingsAdditionalProperties ), CoreEditorDrawer.FoldoutGroup(HDProbeUI.k_CustomSettingsHeader, HDProbeUI.Expandable.Custom, HDProbeUI.k_ExpandedState, HDProbeUI.Drawer.DrawCustomSettings), CoreEditorDrawer.Group(HDProbeUI.Drawer.DrawBakeButton), CoreEditorDrawer.Group(HDProbeUI.Drawer.DrawSHNormalizationStatus) ).Draw(serialized, owner); } protected virtual void DrawHandles(TSerialized serialized, Editor owner) { } protected virtual void DrawAdditionalCaptureSettings(TSerialized serialiezed, Editor owner) { } protected void OnSceneGUI() { if (target == null) return; var soo = m_SerializedHDProbePerTarget[target]; if (soo == null) return; EditorGUI.BeginChangeCheck(); soo.Update(); HDProbeUI.DrawHandles(soo, this); HDProbeUI.Drawer.DoToolbarShortcutKey(this); DrawHandles(soo, this); if (EditorGUI.EndChangeCheck()) soo.Apply(); } static Func s_CapturePointPreviewSizeGetter = ComputeCapturePointPreviewSizeGetter(); static Func ComputeCapturePointPreviewSizeGetter() { var type = Type.GetType("UnityEditor.AnnotationUtility,UnityEditor"); var property = type.GetProperty("iconSize", BindingFlags.Static | BindingFlags.NonPublic); var lambda = Expression.Lambda>( Expression.Multiply( Expression.Property(null, property), Expression.Constant(30.0f) ) ); return lambda.Compile(); } internal static float capturePointPreviewSize { get { return s_CapturePointPreviewSizeGetter(); } } public FrameSettingsRenderType GetFrameSettingsType() => GetTarget(target).mode == ProbeSettings.Mode.Realtime ? FrameSettingsRenderType.RealtimeReflection : FrameSettingsRenderType.CustomOrBakedReflection; } }