using System; using System.Collections.Generic; namespace UnityEngine.Rendering { /// /// The UI implementation for a debug settings panel /// public class DebugDisplaySettingsUI : IDebugData { private IEnumerable m_DisposablePanels; private IDebugDisplaySettings m_Settings; private void Reset() { if (m_Settings != null) { m_Settings.Reset(); // TODO: Tear the UI down and re-create it for now - this is horrible, so reset it instead. UnregisterDebug(); RegisterDebug(m_Settings); DebugManager.instance.RefreshEditor(); } } /// /// Register a display for the UI /// /// to be registered public void RegisterDebug(IDebugDisplaySettings settings) { DebugManager debugManager = DebugManager.instance; List panels = new List(); debugManager.RegisterData(this); m_Settings = settings; m_DisposablePanels = panels; Action onExecute = (data) => { IDebugDisplaySettingsPanelDisposable disposableSettingsPanel = data.CreatePanel(); DebugUI.Widget[] panelWidgets = disposableSettingsPanel.Widgets; DebugUI.Panel panel = debugManager.GetPanel( displayName: disposableSettingsPanel.PanelName, createIfNull: true, groupIndex: (disposableSettingsPanel is DebugDisplaySettingsPanel debugDisplaySettingsPanel) ? debugDisplaySettingsPanel.Order : 0); ObservableList panelChildren = panel.children; panel.flags = disposableSettingsPanel.Flags; panels.Add(disposableSettingsPanel); panelChildren.Add(panelWidgets); }; m_Settings.ForEach(onExecute); } /// /// Unregister the debug panels /// public void UnregisterDebug() { DebugManager debugManager = DebugManager.instance; foreach (IDebugDisplaySettingsPanelDisposable disposableSettingsPanel in m_DisposablePanels) { DebugUI.Widget[] panelWidgets = disposableSettingsPanel.Widgets; string panelId = disposableSettingsPanel.PanelName; DebugUI.Panel panel = debugManager.GetPanel(panelId, true); ObservableList panelChildren = panel.children; disposableSettingsPanel.Dispose(); panelChildren.Remove(panelWidgets); } m_DisposablePanels = null; debugManager.UnregisterData(this); } #region IDebugData /// /// The reset action to be executed when a Reset of the rendering debugger is need /// /// A with the restet callback public Action GetReset() { return Reset; } #endregion } }