No Description
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.

RenderPipelineGraphicsSettingsStripperFetcher.cs 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #if UNITY_EDITOR
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Reflection;
  5. using UnityEditor;
  6. namespace UnityEngine.Rendering
  7. {
  8. static partial class RenderPipelineGraphicsSettingsStripper
  9. {
  10. static class Fetcher
  11. {
  12. static readonly Type k_InterfaceType = typeof(IRenderPipelineGraphicsSettingsStripper<>);
  13. public static Dictionary<Type, List<IStripper>> ComputeStrippersMap()
  14. {
  15. var validStrippers = new Dictionary<Type, List<IStripper>>();
  16. foreach (var (stripperType, settingsType) in GetStrippersFromAssemblies())
  17. {
  18. var stripperInstance = Activator.CreateInstance(stripperType) as IStripper;
  19. if (stripperInstance is not { active: true })
  20. continue;
  21. if (!validStrippers.TryGetValue(settingsType, out var instances))
  22. {
  23. instances = new List<IStripper>();
  24. validStrippers[settingsType] = instances;
  25. }
  26. instances.Add(stripperInstance);
  27. }
  28. return validStrippers;
  29. }
  30. private static IEnumerable<(Type, Type)> GetStrippersFromAssemblies()
  31. {
  32. foreach (var stripperType in TypeCache.GetTypesDerivedFrom(typeof(IRenderPipelineGraphicsSettingsStripper<>)))
  33. {
  34. if (stripperType.IsAbstract)
  35. continue;
  36. // The ctor is private?
  37. if (stripperType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes,
  38. null) == null)
  39. {
  40. Debug.LogWarning($"{stripperType} has no public constructor, it will not be used to strip {nameof(IRenderPipelineGraphicsSettings)}.");
  41. continue;
  42. }
  43. foreach (var i in stripperType.GetInterfaces())
  44. {
  45. if (i.IsGenericType && i.GetGenericTypeDefinition() == k_InterfaceType)
  46. {
  47. yield return (stripperType, i.GetGenericArguments()[0]);
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }
  55. #endif