diff --git a/Packages/com.unity.render-pipelines.core/Editor/InternalBridge/AssemblyInfo.cs b/Packages/com.unity.render-pipelines.core/Editor/InternalBridge/AssemblyInfo.cs index 8ea160f1dec..0a04494f984 100644 --- a/Packages/com.unity.render-pipelines.core/Editor/InternalBridge/AssemblyInfo.cs +++ b/Packages/com.unity.render-pipelines.core/Editor/InternalBridge/AssemblyInfo.cs @@ -2,3 +2,4 @@ [assembly: InternalsVisibleTo("Unity.RenderPipelines.Core.Editor")] [assembly: InternalsVisibleTo("Unity.RenderPipelines.HighDefinition.Editor")] +[assembly: InternalsVisibleTo("Unity.RenderPipelines.Universal.Editor")] diff --git a/Packages/com.unity.render-pipelines.core/Editor/InternalBridge/ObjectSelector.cs b/Packages/com.unity.render-pipelines.core/Editor/InternalBridge/ObjectSelector.cs index 8c398439214..ea3b96a5f2b 100644 --- a/Packages/com.unity.render-pipelines.core/Editor/InternalBridge/ObjectSelector.cs +++ b/Packages/com.unity.render-pipelines.core/Editor/InternalBridge/ObjectSelector.cs @@ -10,5 +10,12 @@ public static void Show(UnityEngine.Object obj, Type requiredType, UnityEngine.O { UnityEditor.ObjectSelector.get.Show(obj, requiredType, objectBeingEdited, allowSceneObjects, allowedEntityIds, onObjectSelectorClosed, onObjectSelectedUpdated, showNoneItem); } + + public static void SetVisualSelection(EntityId entityId) + { + UnityEditor.ObjectSelector.get.SetVisualSelection(entityId); + } + + public static bool isVisible => UnityEditor.ObjectSelector.isVisible; } } diff --git a/Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs b/Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs index f2bcb0a0077..1ce93cfc1bd 100644 --- a/Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs +++ b/Packages/com.unity.render-pipelines.core/Editor/Lighting/ProbeVolume/ProbeGIBaking.cs @@ -892,6 +892,7 @@ static internal void Init() Lightmapping.bakeStarted += OnBakeStarted; Lightmapping.bakeCancelled += OnBakeCancelled; Lightmapping.inputExtraction += OnInputExtraction; + AssemblyReloadEvents.beforeAssemblyReload += CleanUp; } } diff --git a/Packages/com.unity.render-pipelines.core/Editor/Settings/PropertyDrawers/DefaultVolumeProfileSettingsPropertyDrawer.cs b/Packages/com.unity.render-pipelines.core/Editor/Settings/PropertyDrawers/DefaultVolumeProfileSettingsPropertyDrawer.cs index 3e1a845611b..4704543a9ac 100644 --- a/Packages/com.unity.render-pipelines.core/Editor/Settings/PropertyDrawers/DefaultVolumeProfileSettingsPropertyDrawer.cs +++ b/Packages/com.unity.render-pipelines.core/Editor/Settings/PropertyDrawers/DefaultVolumeProfileSettingsPropertyDrawer.cs @@ -1,7 +1,9 @@ using System; +using UnityEditor.UIElements; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UIElements; +using Object = UnityEngine.Object; namespace UnityEditor.Rendering { @@ -17,6 +19,7 @@ public abstract partial class DefaultVolumeProfileSettingsPropertyDrawer : Prope static DefaultVolumeProfileEditor s_DefaultVolumeProfileEditor; VisualElement m_Root; + ObjectField m_ObjectField; /// SerializedObject representing the settings object protected SerializedObject m_SettingsSerializedObject; @@ -31,6 +34,9 @@ public abstract partial class DefaultVolumeProfileSettingsPropertyDrawer : Prope /// Info box message protected abstract GUIContent volumeInfoBoxLabel { get; } + /// Label and tooltip used for the Default Volume Profile asset field. + protected abstract GUIContent defaultVolumeProfileAssetLabel { get; } + /// /// CreatePropertyGUI implementation. /// @@ -107,6 +113,142 @@ protected void DestroyDefaultVolumeProfileEditor() s_DefaultVolumeProfileSerializedProperty = null; } + /// + /// Show modal dialog to confirm update of selected volume if needed and apply new volume profile. + /// + /// Object Field used to display Default Volume profile + /// New Volume profile + /// Previous volume profile + /// Optionally provided default volume profile to extract default values + /// Render Pipeline type + void ShowGlobalDefaultVolumeDialog(ObjectField field, Object newValue, + Object previousValue, IDefaultVolumeProfileSettings defaultVolumeProfileSettings = null) + where TRenderPipeline : RenderPipeline + { + bool confirmed = VolumeProfileUtils.UpdateGlobalDefaultVolumeProfileWithConfirmation(newValue as VolumeProfile, defaultVolumeProfileSettings?.volumeProfile); + if (confirmed) + { + UpdateDefaultVolumeSerializedPropertyAndRecreate(field, newValue); + } + else + { + m_VolumeProfileSerializedProperty.objectReferenceValue = previousValue; + m_VolumeProfileSerializedProperty.serializedObject.ApplyModifiedProperties(); + field.SetValueWithoutNotify(previousValue); + // Update the ObjectSelector's visual selection if it's still open + if (previousValue != null && ObjectSelector.isVisible) + ObjectSelector.SetVisualSelection(previousValue.GetEntityId()); + } + } + + /// + /// Update serialized property for Default Volume profile and recreate related Editors + /// + /// Object Field used to display Default Volume profile + /// New Volume profile + void UpdateDefaultVolumeSerializedPropertyAndRecreate(ObjectField field, Object newValue) + { + m_VolumeProfileSerializedProperty.objectReferenceValue = newValue; + m_VolumeProfileSerializedProperty.serializedObject.ApplyModifiedProperties(); + field.SetValueWithoutNotify(newValue); + DestroyDefaultVolumeProfileEditor(); + CreateDefaultVolumeProfileEditor(); + } + + /// + /// Draw ObjectField for Default Volume. + /// + /// Default value source if available + /// Render Pipeline type for Default Volume + /// Default Volume settings container type + /// New Object Field + protected VisualElement DrawDefaultVolumeObjectField(TDefaultVolumeSettings defaultVolumeProfileSettings = null) + where TRenderPipeline: RenderPipeline + where TDefaultVolumeSettings : class, IDefaultVolumeProfileSettings + { + VisualElement profileLine = new(); + var toggle = new Toggle(); + toggle.AddToClassList(Foldout.toggleUssClassName); + var checkmark = toggle.Q(className: Toggle.checkmarkUssClassName); + checkmark.AddToClassList(Foldout.checkmarkUssClassName); + m_ObjectField = new ObjectField(defaultVolumeProfileAssetLabel.text) + { + tooltip = defaultVolumeProfileAssetLabel.tooltip, + objectType = typeof(VolumeProfile), + value = m_VolumeProfileSerializedProperty.objectReferenceValue as VolumeProfile, + style = + { + flexShrink = 1, + } + }; + m_ObjectField.AddToClassList("unity-base-field__aligned"); //Align with other BaseField + m_ObjectField.Q