using System; using UnityEngine; using UnityEngine.Rendering; namespace UnityEditor.Rendering { /// /// UI for global settings /// public static partial class RenderPipelineGlobalSettingsUI { /// /// Draw Volume Profile property field with a foldout scope that ensures that the target cannot become null. /// /// Target serialized property /// Label for the property field /// Callback that creates and returns a valid Volume Profile /// Reference parameter indicating whether the foldout is expanded /// The volume profile public static VolumeProfile DrawVolumeProfileAssetField( SerializedProperty volumeProfileSerializedProperty, GUIContent volumeProfileLabel, Func getOrCreateVolumeProfile, ref bool labelFoldoutExpanded) { VolumeProfile asset; using (new EditorGUILayout.HorizontalScope()) { var oldAssetValue = volumeProfileSerializedProperty.objectReferenceValue; EditorGUILayout.PropertyField(volumeProfileSerializedProperty, volumeProfileLabel); asset = volumeProfileSerializedProperty.objectReferenceValue as VolumeProfile; if (asset == null) { if (oldAssetValue != null) { Debug.Log("This Volume Profile Asset cannot be null. Rolling back to previous value."); volumeProfileSerializedProperty.objectReferenceValue = oldAssetValue; asset = oldAssetValue as VolumeProfile; } else { asset = getOrCreateVolumeProfile(); } } labelFoldoutExpanded = GUI.Toggle( GUILayoutUtility.GetLastRect(), labelFoldoutExpanded, GUIContent.none, EditorStyles.foldout); } return asset; } } }