暫無描述
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.

UniversalRenderPipelineVolumeComponentEditor.cs 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using UnityEngine;
  5. using UnityEngine.Rendering;
  6. using UnityEngine.Rendering.Universal;
  7. using StringBuilder = System.Text.StringBuilder;
  8. namespace UnityEditor.Rendering.Universal
  9. {
  10. /// <summary>
  11. /// The default <see cref="VolumeComponentEditor"/> implementation for URP
  12. /// </summary>
  13. [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))]
  14. [CustomEditor(typeof(VolumeComponent), true)]
  15. public class UniversalRenderPipelineVolumeComponentEditor : VolumeComponentEditor
  16. {
  17. private VolumeRequiresRendererFeatures m_FeatureAttribute;
  18. /// <inheritdoc/>
  19. public override void OnEnable()
  20. {
  21. base.OnEnable();
  22. // Caching the attribute as UI code can be called multiple times in the same editor frame
  23. if (m_FeatureAttribute == null)
  24. m_FeatureAttribute = target.GetType().GetCustomAttribute<VolumeRequiresRendererFeatures>();
  25. }
  26. private string GetFeatureTypeNames(in HashSet<Type> types)
  27. {
  28. var typeNameString = new StringBuilder();
  29. foreach (var type in types)
  30. typeNameString.AppendFormat("\"{0}\" ", type.Name);
  31. return typeNameString.ToString();
  32. }
  33. /// <inheritdoc/>
  34. protected override void OnBeforeInspectorGUI()
  35. {
  36. if(m_FeatureAttribute != null)
  37. {
  38. var rendererFeatures = (GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset urpAsset && urpAsset.scriptableRendererData != null)
  39. ? urpAsset.scriptableRendererData.rendererFeatures
  40. : null;
  41. using (HashSetPool<Type>.Get(out var missingFeatureTypes))
  42. {
  43. foreach (var elem in m_FeatureAttribute.TargetFeatureTypes)
  44. missingFeatureTypes.Add(elem);
  45. if (rendererFeatures != null)
  46. {
  47. foreach (var feature in rendererFeatures)
  48. {
  49. var featureType = feature.GetType();
  50. if (missingFeatureTypes.Contains(featureType))
  51. {
  52. missingFeatureTypes.Remove(featureType);
  53. if (missingFeatureTypes.Count == 0)
  54. break;
  55. }
  56. }
  57. }
  58. if (missingFeatureTypes.Count > 0)
  59. {
  60. CoreEditorUtils.DrawFixMeBox(string.Format("For this effect to work the {0}renderer feature(s) needs to be added and enabled on the active renderer asset",
  61. GetFeatureTypeNames(in missingFeatureTypes)), MessageType.Warning, "Open", () =>
  62. {
  63. Selection.activeObject = UniversalRenderPipeline.asset.scriptableRendererData;
  64. GUIUtility.ExitGUI();
  65. });
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }