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

ScriptableRendererFeatureProvider.cs 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Rendering.Universal;
  5. namespace UnityEditor.Rendering.Universal
  6. {
  7. class ScriptableRendererFeatureProvider : FilterWindow.IProvider
  8. {
  9. class FeatureElement : FilterWindow.Element
  10. {
  11. public Type type;
  12. }
  13. readonly ScriptableRendererDataEditor m_Editor;
  14. public Vector2 position { get; set; }
  15. public ScriptableRendererFeatureProvider(ScriptableRendererDataEditor editor)
  16. {
  17. m_Editor = editor;
  18. }
  19. internal bool RendererFeatureSupported(Type rendererFeatureType)
  20. {
  21. Type rendererType = m_Editor.target.GetType();
  22. SupportedOnRendererAttribute rendererFilterAttribute = Attribute.GetCustomAttribute(rendererFeatureType, typeof(SupportedOnRendererAttribute)) as SupportedOnRendererAttribute;
  23. if (rendererFilterAttribute != null)
  24. {
  25. bool foundEditor = false;
  26. for (int i = 0; i < rendererFilterAttribute.rendererTypes.Length && !foundEditor; i++)
  27. foundEditor = rendererFilterAttribute.rendererTypes[i] == rendererType;
  28. return foundEditor;
  29. }
  30. return true;
  31. }
  32. public void CreateComponentTree(List<FilterWindow.Element> tree)
  33. {
  34. tree.Add(new FilterWindow.GroupElement(0, "Renderer Features"));
  35. var types = TypeCache.GetTypesDerivedFrom<ScriptableRendererFeature>();
  36. var data = m_Editor.target as ScriptableRendererData;
  37. foreach (var type in types)
  38. {
  39. // Check to see if the current renderer feature can be used with the current renderer. If the attribute isn't found then its compatible with everything.
  40. if (!RendererFeatureSupported(type))
  41. continue;
  42. if (data.DuplicateFeatureCheck(type))
  43. {
  44. continue;
  45. }
  46. string path = GetMenuNameFromType(type);
  47. tree.Add(new FeatureElement
  48. {
  49. content = new GUIContent(path),
  50. level = 1,
  51. type = type
  52. });
  53. }
  54. }
  55. public bool GoToChild(FilterWindow.Element element, bool addIfComponent)
  56. {
  57. if (element is FeatureElement featureElement)
  58. {
  59. m_Editor.AddComponent(featureElement.type);
  60. return true;
  61. }
  62. return false;
  63. }
  64. string GetMenuNameFromType(Type type)
  65. {
  66. string path;
  67. if (!m_Editor.GetCustomTitle(type, out path))
  68. {
  69. path = ObjectNames.NicifyVariableName(type.Name);
  70. }
  71. if (type.Namespace != null)
  72. {
  73. if (type.Namespace.Contains("Experimental"))
  74. path += " (Experimental)";
  75. }
  76. return path;
  77. }
  78. }
  79. }