DebugDisplaySettingsUI.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. namespace UnityEngine.Rendering.Universal
  4. {
  5. public class DebugDisplaySettingsUI : IDebugData
  6. {
  7. private IEnumerable<IDebugDisplaySettingsPanelDisposable> m_DisposablePanels;
  8. private DebugDisplaySettings m_Settings;
  9. private void Reset()
  10. {
  11. if (m_Settings != null)
  12. {
  13. m_Settings.Reset();
  14. // TODO: Tear the UI down and re-create it for now - this is horrible, so reset it instead.
  15. UnregisterDebug();
  16. RegisterDebug(m_Settings);
  17. DebugManager.instance.RefreshEditor();
  18. }
  19. }
  20. public void RegisterDebug(DebugDisplaySettings settings)
  21. {
  22. DebugManager debugManager = DebugManager.instance;
  23. List<IDebugDisplaySettingsPanelDisposable> panels = new List<IDebugDisplaySettingsPanelDisposable>();
  24. debugManager.RegisterData(this);
  25. m_Settings = settings;
  26. m_DisposablePanels = panels;
  27. Action<IDebugDisplaySettingsData> onExecute = (data) =>
  28. {
  29. IDebugDisplaySettingsPanelDisposable disposableSettingsPanel = data.CreatePanel();
  30. DebugUI.Widget[] panelWidgets = disposableSettingsPanel.Widgets;
  31. string panelId = disposableSettingsPanel.PanelName;
  32. DebugUI.Panel panel = debugManager.GetPanel(panelId, true);
  33. ObservableList<DebugUI.Widget> panelChildren = panel.children;
  34. panels.Add(disposableSettingsPanel);
  35. panelChildren.Add(panelWidgets);
  36. };
  37. m_Settings.ForEach(onExecute);
  38. }
  39. public void UnregisterDebug()
  40. {
  41. DebugManager debugManager = DebugManager.instance;
  42. foreach (IDebugDisplaySettingsPanelDisposable disposableSettingsPanel in m_DisposablePanels)
  43. {
  44. DebugUI.Widget[] panelWidgets = disposableSettingsPanel.Widgets;
  45. string panelId = disposableSettingsPanel.PanelName;
  46. DebugUI.Panel panel = debugManager.GetPanel(panelId, true);
  47. ObservableList<DebugUI.Widget> panelChildren = panel.children;
  48. disposableSettingsPanel.Dispose();
  49. panelChildren.Remove(panelWidgets);
  50. }
  51. m_DisposablePanels = null;
  52. debugManager.UnregisterData(this);
  53. }
  54. #region IDebugData
  55. public Action GetReset()
  56. {
  57. return Reset;
  58. }
  59. #endregion
  60. }
  61. }