@@ -13,6 +13,7 @@ class LookDevVolumeProfileSettingsPropertyDrawer : PropertyDrawer
1313 {
1414 VisualElement m_Root ;
1515 Editor m_LookDevVolumeProfileEditor ;
16+ int m_LookDevVolumeProfileHash = - 1 ;
1617 SerializedObject m_SettingsSerializedObject ;
1718 SerializedProperty m_VolumeProfileSerializedProperty ;
1819 EditorPrefBool m_DefaultVolumeProfileFoldoutExpanded ;
@@ -51,6 +52,14 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property)
5152
5253 Editor GetLookDevDefaultVolumeProfileEditor ( VolumeProfile lookDevAsset )
5354 {
55+ int currentHash = ( lookDevAsset != null ) ? lookDevAsset . GetHashCode ( ) : - 1 ;
56+ if ( currentHash != m_LookDevVolumeProfileHash )
57+ {
58+ Editor . DestroyImmediate ( m_LookDevVolumeProfileEditor ) ;
59+ m_LookDevVolumeProfileEditor = null ;
60+ m_LookDevVolumeProfileHash = currentHash ;
61+ }
62+
5463 Editor . CreateCachedEditor ( lookDevAsset , typeof ( VolumeProfileEditor ) , ref m_LookDevVolumeProfileEditor ) ;
5564 return m_LookDevVolumeProfileEditor ;
5665 }
@@ -68,8 +77,12 @@ VisualElement CreateAssetFieldUI()
6877 {
6978 tooltip = k_LookDevVolumeProfileAssetLabel . tooltip ,
7079 objectType = typeof ( VolumeProfile ) ,
71- value = m_VolumeProfileSerializedProperty . objectReferenceValue as VolumeProfile ,
80+ style =
81+ {
82+ flexShrink = 1 ,
83+ }
7284 } ;
85+ field . BindProperty ( m_VolumeProfileSerializedProperty ) ;
7386 field . AddToClassList ( "unity-base-field__aligned" ) ; //Align with other BaseField<T>
7487 field . Q < Label > ( ) . RegisterCallback < ClickEvent > ( evt => toggle . value ^= true ) ;
7588
@@ -91,37 +104,15 @@ VisualElement CreateAssetFieldUI()
91104 if ( evt . newValue == evt . previousValue )
92105 return ;
93106
94- if ( evt . newValue == null )
107+ if ( GraphicsSettings . TryGetRenderPipelineSettings < LookDevVolumeProfileSettings > ( out var lookDevVolumeProfileSettings ) )
95108 {
96- if ( evt . previousValue != null )
97- {
98- field . SetValueWithoutNotify ( evt . previousValue ) ;
99- Debug . Log ( "This Volume Profile Asset cannot be null. Rolling back to previous value." ) ;
100- return ;
101- }
102- else
103- {
104- if ( RenderPipelineManager . currentPipeline is not HDRenderPipeline )
105- {
106- m_VolumeProfileSerializedProperty . objectReferenceValue = null ;
107- }
108- else
109- {
110- var lookDevVolumeProfileSettings = GraphicsSettings . GetRenderPipelineSettings < LookDevVolumeProfileSettings > ( ) ;
111- if ( lookDevVolumeProfileSettings . volumeProfile == null )
112- {
113- lookDevVolumeProfileSettings . volumeProfile = VolumeUtils . CopyVolumeProfileFromResourcesToAssets (
114- GraphicsSettings . GetRenderPipelineSettings < HDRenderPipelineEditorAssets > ( ) . lookDevVolumeProfile ) ;
115- }
116-
117- m_VolumeProfileSerializedProperty . objectReferenceValue = lookDevVolumeProfileSettings . volumeProfile ;
118- }
119- }
109+ lookDevVolumeProfileSettings . volumeProfile = evt . newValue as VolumeProfile ;
110+ m_VolumeProfileSerializedProperty . objectReferenceValue = lookDevVolumeProfileSettings . volumeProfile ;
111+ m_VolumeProfileSerializedProperty . serializedObject . ApplyModifiedProperties ( ) ;
112+ m_SettingsSerializedObject . Update ( ) ;
120113 }
121- else
122- m_VolumeProfileSerializedProperty . objectReferenceValue = evt . newValue ;
123114
124- m_VolumeProfileSerializedProperty . serializedObject . ApplyModifiedProperties ( ) ;
115+ m_LookDevVolumeProfileHash = - 1 ; // Invalidate the hash, to allow the IMGUI container recreate the editor
125116 } ) ;
126117
127118 return profileLine ;
@@ -154,6 +145,10 @@ VisualElement CreateVolumeProfileEditorUI()
154145 if ( lookDevAsset . Has < HDRISky > ( ) )
155146 EditorGUILayout . HelpBox ( "HDRISky is not modifiable and will be overridden by the LookDev" , MessageType . Warning ) ;
156147 }
148+ else
149+ {
150+ EditorGUILayout . HelpBox ( "No Look Dev Volume Profile assigned. A default profile will be created automatically when you open the Look Dev tool (Window > Rendering > Look Dev)." , MessageType . Info ) ;
151+ }
157152 } ) ;
158153 }
159154 }
0 commit comments