暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

URPDefaultVolumeProfileSettingsPropertyDrawer.cs 4.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using UnityEditor.Rendering;
  3. using UnityEngine;
  4. using UnityEngine.Rendering;
  5. using UnityEngine.Rendering.Universal;
  6. using UnityEngine.UIElements;
  7. namespace UnityEditor.Rendering.Universal
  8. {
  9. [CustomPropertyDrawer(typeof(URPDefaultVolumeProfileSettings))]
  10. [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
  11. class URPDefaultVolumeProfileSettingsPropertyDrawer : DefaultVolumeProfileSettingsPropertyDrawer
  12. {
  13. GUIContent defaultVolumeProfileAssetLabel => EditorGUIUtility.TrTextContent("Default Profile",
  14. "Settings that will be applied project-wide to all Volumes by default when URP is active.");
  15. protected override GUIContent volumeInfoBoxLabel => EditorGUIUtility.TrTextContent(
  16. "The values in the Default Volume can be overridden by a Volume Profile assigned to URP asset and Volumes inside scenes.");
  17. protected override VisualElement CreateAssetFieldUI()
  18. {
  19. Action redraw = null;
  20. var container = new IMGUIContainer(() => redraw());
  21. redraw = () =>
  22. {
  23. using var indentLevelScope = new EditorGUI.IndentLevelScope();
  24. using var changeScope = new EditorGUI.ChangeCheckScope();
  25. /* values adapted to the ProjectSettings > Graphics */
  26. var minWidth = 91;
  27. var indent = 94;
  28. var ratio = 0.45f;
  29. EditorGUIUtility.labelWidth = Mathf.Max(minWidth, (int)((container.worldBound.width - indent) * ratio));
  30. bool expanded = m_DefaultVolumeProfileFoldoutExpanded.value;
  31. var previousDefaultVolumeProfileAsset = m_VolumeProfileSerializedProperty.objectReferenceValue;
  32. VolumeProfile defaultVolumeProfileAsset = RenderPipelineGlobalSettingsUI.DrawVolumeProfileAssetField(
  33. m_VolumeProfileSerializedProperty,
  34. defaultVolumeProfileAssetLabel,
  35. getOrCreateVolumeProfile: () =>
  36. {
  37. if (RenderPipelineManager.currentPipeline is not UniversalRenderPipeline)
  38. return null;
  39. // When the built-in Reset context action is used, the asset becomes null outside of this scope.
  40. // This is required to apply the new value to the serialized property.
  41. GUI.changed = true;
  42. return UniversalRenderPipelineGlobalSettings.GetOrCreateDefaultVolumeProfile(null);
  43. },
  44. ref expanded
  45. );
  46. m_DefaultVolumeProfileFoldoutExpanded.value = expanded;
  47. if (changeScope.changed && defaultVolumeProfileAsset != previousDefaultVolumeProfileAsset)
  48. {
  49. if (RenderPipelineManager.currentPipeline is not UniversalRenderPipeline)
  50. {
  51. Debug.Log("Cannot change Default Volume Profile when URP is not active. Rolling back to previous value.");
  52. m_VolumeProfileSerializedProperty.objectReferenceValue = previousDefaultVolumeProfileAsset;
  53. }
  54. else if (previousDefaultVolumeProfileAsset == null)
  55. {
  56. VolumeProfileUtils.UpdateGlobalDefaultVolumeProfile<UniversalRenderPipeline>(defaultVolumeProfileAsset);
  57. m_VolumeProfileSerializedProperty.objectReferenceValue = defaultVolumeProfileAsset;
  58. }
  59. else
  60. {
  61. bool confirmed = VolumeProfileUtils.UpdateGlobalDefaultVolumeProfileWithConfirmation<UniversalRenderPipeline>(defaultVolumeProfileAsset);
  62. if (!confirmed)
  63. m_VolumeProfileSerializedProperty.objectReferenceValue = previousDefaultVolumeProfileAsset;
  64. }
  65. m_SettingsSerializedObject.ApplyModifiedProperties();
  66. m_VolumeProfileSerializedProperty.serializedObject.Update();
  67. DestroyDefaultVolumeProfileEditor();
  68. CreateDefaultVolumeProfileEditor();
  69. }
  70. // Propagate foldout expander state from IMGUI to UITK
  71. m_EditorContainer.style.display = m_DefaultVolumeProfileFoldoutExpanded.value ? DisplayStyle.Flex : DisplayStyle.None;
  72. };
  73. return container;
  74. }
  75. public class URPDefaultVolumeProfileSettingsContextMenu : DefaultVolumeProfileSettingsContextMenu<URPDefaultVolumeProfileSettings, UniversalRenderPipeline>
  76. {
  77. protected override string defaultVolumeProfilePath => "Assets/VolumeProfile_Default.asset";
  78. }
  79. }
  80. }