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