Aucune description
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DebugManager.UIState.cs 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Diagnostics;
  3. using UnityEngine.Rendering.UI;
  4. #if UNITY_EDITOR
  5. using UnityEditor;
  6. #endif
  7. #if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SWITCH
  8. using UnityEngine.UI;
  9. #endif
  10. namespace UnityEngine.Rendering
  11. {
  12. using UnityObject = UnityEngine.Object;
  13. public sealed partial class DebugManager
  14. {
  15. /// <summary>
  16. /// The modes of the UI of the Rendering Debugger
  17. /// </summary>
  18. public enum UIMode : int
  19. {
  20. /// <summary>
  21. /// Editor Window
  22. /// </summary>
  23. EditorMode,
  24. /// <summary>
  25. /// In Game view
  26. /// </summary>
  27. RuntimeMode
  28. }
  29. /// <summary>
  30. /// Event that is raised when a window state is changed
  31. /// </summary>
  32. public static event Action<UIMode, bool> windowStateChanged;
  33. class UIState
  34. {
  35. public UIMode mode;
  36. [SerializeField]
  37. private bool m_Open;
  38. public bool open
  39. {
  40. get => m_Open;
  41. set
  42. {
  43. if (m_Open == value)
  44. return;
  45. m_Open = value;
  46. windowStateChanged?.Invoke(mode, m_Open);
  47. }
  48. }
  49. }
  50. private UIState editorUIState = new UIState() { mode = UIMode.EditorMode };
  51. /// <summary>
  52. /// Is the debug editor window open.
  53. /// </summary>
  54. public bool displayEditorUI
  55. {
  56. get => editorUIState.open;
  57. set => editorUIState.open = value;
  58. }
  59. private bool m_EnableRuntimeUI = true;
  60. /// <summary>
  61. /// Controls whether runtime UI can be enabled. When this is set to false, there will be no overhead
  62. /// from debug GameObjects or runtime initialization.
  63. /// </summary>
  64. public bool enableRuntimeUI
  65. {
  66. get => m_EnableRuntimeUI;
  67. set
  68. {
  69. if (value != m_EnableRuntimeUI)
  70. {
  71. m_EnableRuntimeUI = value;
  72. DebugUpdater.SetEnabled(value);
  73. }
  74. }
  75. }
  76. private UIState runtimeUIState = new UIState() { mode = UIMode.RuntimeMode };
  77. /// <summary>
  78. /// Displays the runtime version of the debug window.
  79. /// </summary>
  80. public bool displayRuntimeUI
  81. {
  82. get => m_Root != null && m_Root.activeInHierarchy;
  83. set
  84. {
  85. if (value)
  86. {
  87. m_Root = UnityObject.Instantiate(Resources.Load<Transform>("DebugUICanvas")).gameObject;
  88. m_Root.name = "[Debug Canvas]";
  89. m_Root.transform.localPosition = Vector3.zero;
  90. m_RootUICanvas = m_Root.GetComponent<DebugUIHandlerCanvas>();
  91. #if UNITY_ANDROID || UNITY_IPHONE || UNITY_TVOS || UNITY_SWITCH
  92. var canvasScaler = m_Root.GetComponent<CanvasScaler>();
  93. canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
  94. #endif
  95. m_Root.SetActive(true);
  96. }
  97. else
  98. {
  99. CoreUtils.Destroy(m_Root);
  100. m_Root = null;
  101. m_RootUICanvas = null;
  102. }
  103. onDisplayRuntimeUIChanged(value);
  104. DebugUpdater.HandleInternalEventSystemComponents(value);
  105. runtimeUIState.open = m_Root != null && m_Root.activeInHierarchy;
  106. }
  107. }
  108. /// <summary>
  109. /// Displays the persistent runtime debug window.
  110. /// </summary>
  111. public bool displayPersistentRuntimeUI
  112. {
  113. get => m_RootUIPersistentCanvas != null && m_PersistentRoot.activeInHierarchy;
  114. set
  115. {
  116. if (value)
  117. {
  118. EnsurePersistentCanvas();
  119. }
  120. else
  121. {
  122. CoreUtils.Destroy(m_PersistentRoot);
  123. m_PersistentRoot = null;
  124. m_RootUIPersistentCanvas = null;
  125. }
  126. }
  127. }
  128. }
  129. }