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

DebugDisplaySettingsPanel.cs 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. namespace UnityEngine.Rendering
  5. {
  6. /// <summary>
  7. /// The abstract common implementation of the <see cref="IDebugDisplaySettingsPanelDisposable"/>
  8. /// </summary>
  9. public abstract class DebugDisplaySettingsPanel : IDebugDisplaySettingsPanelDisposable
  10. {
  11. private readonly List<DebugUI.Widget> m_Widgets = new List<DebugUI.Widget>();
  12. private readonly DisplayInfoAttribute m_DisplayInfo;
  13. /// <summary>
  14. /// The Panel name
  15. /// </summary>
  16. public virtual string PanelName => m_DisplayInfo?.name ?? string.Empty;
  17. /// <summary>
  18. /// The order where this panel should be shown
  19. /// </summary>
  20. public virtual int Order => m_DisplayInfo?.order ?? 0;
  21. /// <summary>
  22. /// The collection of widgets that are in this panel
  23. /// </summary>
  24. public DebugUI.Widget[] Widgets => m_Widgets.ToArray();
  25. /// <summary>
  26. /// The <see cref="DebugUI.Flags"/> for this panel
  27. /// </summary>
  28. public virtual DebugUI.Flags Flags => DebugUI.Flags.None;
  29. /// <summary>
  30. /// Adds a widget to the panel
  31. /// </summary>
  32. /// <param name="widget">The <see cref="DebugUI.Widget"/> to be added.</param>
  33. protected void AddWidget(DebugUI.Widget widget)
  34. {
  35. if (widget == null)
  36. throw new ArgumentNullException(nameof(widget));
  37. m_Widgets.Add(widget);
  38. }
  39. /// <summary>
  40. /// Clears the widgets list
  41. /// </summary>
  42. protected void Clear()
  43. {
  44. m_Widgets.Clear();
  45. }
  46. /// <summary>
  47. /// Disposes the panel
  48. /// </summary>
  49. public virtual void Dispose()
  50. {
  51. Clear();
  52. }
  53. /// <summary>
  54. /// Default constructor
  55. /// </summary>
  56. protected DebugDisplaySettingsPanel()
  57. {
  58. m_DisplayInfo = GetType().GetCustomAttribute<DisplayInfoAttribute>();
  59. if (m_DisplayInfo == null)
  60. Debug.Log($"Type {GetType()} should specify the attribute {nameof(DisplayInfoAttribute)}");
  61. }
  62. }
  63. /// <summary>
  64. /// Class to help declare rendering debugger panels
  65. /// </summary>
  66. /// <typeparam name="T">The type of Debug Display Settings Data that a Rendering Debugger Panel is using.</typeparam>
  67. public abstract class DebugDisplaySettingsPanel<T> : DebugDisplaySettingsPanel
  68. where T : IDebugDisplaySettingsData
  69. {
  70. internal T m_Data;
  71. /// <summary>
  72. /// Access to the data stored
  73. /// </summary>
  74. public T data
  75. {
  76. get => m_Data;
  77. internal set => m_Data = value;
  78. }
  79. /// <summary>
  80. /// Default constructor
  81. /// </summary>
  82. /// <param name="data">The data that the panel holds</param>
  83. protected DebugDisplaySettingsPanel(T data)
  84. : base()
  85. {
  86. m_Data = data;
  87. }
  88. }
  89. }