CustomSignalingSettingsEditor.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace Unity.RenderStreaming.Editor
  7. {
  8. /// <summary>
  9. ///
  10. /// </summary>
  11. public class CustomSignalingSettingsEditor : Attribute
  12. {
  13. private static readonly TypeCache.TypeCollection inspectorTypes =
  14. TypeCache.GetTypesWithAttribute<CustomSignalingSettingsEditor>();
  15. private readonly Type inspectedType;
  16. private readonly string label;
  17. /// <summary>
  18. ///
  19. /// </summary>
  20. /// <param name="inspectedType"></param>
  21. /// <param name="label"></param>
  22. public CustomSignalingSettingsEditor(Type inspectedType, string label)
  23. {
  24. if (inspectedType == null)
  25. Debug.LogError("Failed to load CustomEditor inspected type");
  26. this.inspectedType = inspectedType;
  27. this.label = label;
  28. }
  29. internal static Type FindInspectorTypeByInspectedType(Type inspectedType)
  30. {
  31. foreach (var type in inspectorTypes)
  32. {
  33. foreach (CustomSignalingSettingsEditor custom in
  34. type.GetCustomAttributes(typeof(CustomSignalingSettingsEditor), false))
  35. {
  36. if (custom.inspectedType == inspectedType)
  37. {
  38. return type;
  39. }
  40. }
  41. }
  42. return null;
  43. }
  44. internal static Type FindInspectedTypeByLabel(string label)
  45. {
  46. foreach (var type in inspectorTypes)
  47. {
  48. foreach (CustomSignalingSettingsEditor custom in
  49. type.GetCustomAttributes(typeof(CustomSignalingSettingsEditor), false))
  50. {
  51. if (custom.label == label)
  52. {
  53. return custom.inspectedType;
  54. }
  55. }
  56. }
  57. return null;
  58. }
  59. internal static string FindLabelByInspectedType(Type inspectedType)
  60. {
  61. foreach (var type in inspectorTypes)
  62. {
  63. foreach (CustomSignalingSettingsEditor custom in
  64. type.GetCustomAttributes(typeof(CustomSignalingSettingsEditor), false))
  65. {
  66. if (custom.inspectedType == inspectedType)
  67. {
  68. return custom.label;
  69. }
  70. }
  71. }
  72. return null;
  73. }
  74. internal static string FindLabelByInspectorType(Type inspectorType)
  75. {
  76. var attributes =
  77. inspectorType.GetCustomAttributes(typeof(CustomSignalingSettingsEditor), false);
  78. foreach (var attribute in attributes)
  79. {
  80. if (attribute is CustomSignalingSettingsEditor custom)
  81. return custom.label;
  82. }
  83. return null;
  84. }
  85. internal static IEnumerable<string> Labels()
  86. {
  87. return inspectorTypes.Select(FindLabelByInspectorType);
  88. }
  89. }
  90. }