DebuggerManager.DebuggerWindowGroup.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //------------------------------------------------------------
  2. // Game Framework v3.x
  3. // Copyright © 2013-2017 Jiang Yin. All rights reserved.
  4. // Homepage: http://gameframework.cn/
  5. // Feedback: mailto:jiangyin@gameframework.cn
  6. //------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. namespace GameFramework.Debugger
  10. {
  11. internal partial class DebuggerManager
  12. {
  13. /// <summary>
  14. /// 调试窗口组。
  15. /// </summary>
  16. private sealed class DebuggerWindowGroup : IDebuggerWindowGroup
  17. {
  18. private readonly List<KeyValuePair<string, IDebuggerWindow>> m_DebuggerWindows;
  19. private int m_SelectedIndex;
  20. private string[] m_DebuggerWindowNames;
  21. public DebuggerWindowGroup()
  22. {
  23. m_DebuggerWindows = new List<KeyValuePair<string, IDebuggerWindow>>();
  24. m_SelectedIndex = 0;
  25. m_DebuggerWindowNames = null;
  26. }
  27. /// <summary>
  28. /// 获取调试窗口数量。
  29. /// </summary>
  30. public int DebuggerWindowCount
  31. {
  32. get
  33. {
  34. return m_DebuggerWindows.Count;
  35. }
  36. }
  37. /// <summary>
  38. /// 获取或设置当前选中的调试窗口索引。
  39. /// </summary>
  40. public int SelectedIndex
  41. {
  42. get
  43. {
  44. return m_SelectedIndex;
  45. }
  46. set
  47. {
  48. m_SelectedIndex = value;
  49. }
  50. }
  51. /// <summary>
  52. /// 获取当前选中的调试窗口。
  53. /// </summary>
  54. public IDebuggerWindow SelectedWindow
  55. {
  56. get
  57. {
  58. if (m_SelectedIndex >= m_DebuggerWindows.Count)
  59. {
  60. return null;
  61. }
  62. return m_DebuggerWindows[m_SelectedIndex].Value;
  63. }
  64. }
  65. /// <summary>
  66. /// 初始化调试组。
  67. /// </summary>
  68. /// <param name="args">初始化调试组参数。</param>
  69. public void Initialize(params object[] args)
  70. {
  71. }
  72. /// <summary>
  73. /// 关闭调试组。
  74. /// </summary>
  75. public void Shutdown()
  76. {
  77. foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
  78. {
  79. debuggerWindow.Value.Shutdown();
  80. }
  81. m_DebuggerWindows.Clear();
  82. }
  83. /// <summary>
  84. /// 进入调试窗口。
  85. /// </summary>
  86. public void OnEnter()
  87. {
  88. SelectedWindow.OnEnter();
  89. }
  90. /// <summary>
  91. /// 离开调试窗口。
  92. /// </summary>
  93. public void OnLeave()
  94. {
  95. SelectedWindow.OnLeave();
  96. }
  97. /// <summary>
  98. /// 调试组轮询。
  99. /// </summary>
  100. /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
  101. /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
  102. public void OnUpdate(float elapseSeconds, float realElapseSeconds)
  103. {
  104. SelectedWindow.OnUpdate(elapseSeconds, realElapseSeconds);
  105. }
  106. /// <summary>
  107. /// 调试窗口绘制。
  108. /// </summary>
  109. public void OnDraw()
  110. {
  111. }
  112. private void RefreshDebuggerWindowNames()
  113. {
  114. m_DebuggerWindowNames = new string[m_DebuggerWindows.Count];
  115. int index = 0;
  116. foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
  117. {
  118. m_DebuggerWindowNames[index++] = debuggerWindow.Key;
  119. }
  120. }
  121. /// <summary>
  122. /// 获取调试组的调试窗口名称集合。
  123. /// </summary>
  124. public string[] GetDebuggerWindowNames()
  125. {
  126. return m_DebuggerWindowNames;
  127. }
  128. /// <summary>
  129. /// 获取调试窗口。
  130. /// </summary>
  131. /// <param name="path">调试窗口路径。</param>
  132. /// <returns>要获取的调试窗口。</returns>
  133. public IDebuggerWindow GetDebuggerWindow(string path)
  134. {
  135. if (string.IsNullOrEmpty(path))
  136. {
  137. return null;
  138. }
  139. int pos = path.IndexOf('/');
  140. if (pos < 0 || pos >= path.Length - 1)
  141. {
  142. return InternalGetDebuggerWindow(path);
  143. }
  144. else
  145. {
  146. string debuggerWindowGroupName = path.Substring(0, pos);
  147. string leftPath = path.Substring(pos + 1);
  148. DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
  149. if (debuggerWindowGroup == null)
  150. {
  151. return null;
  152. }
  153. return debuggerWindowGroup.GetDebuggerWindow(leftPath);
  154. }
  155. }
  156. /// <summary>
  157. /// 注册调试窗口。
  158. /// </summary>
  159. /// <param name="path">调试窗口路径。</param>
  160. /// <param name="debuggerWindow">要注册的调试窗口。</param>
  161. public void RegisterDebuggerWindow(string path, IDebuggerWindow debuggerWindow)
  162. {
  163. if (string.IsNullOrEmpty(path))
  164. {
  165. throw new ArgumentNullException("Path is invalid.");
  166. }
  167. int pos = path.IndexOf('/');
  168. if (pos < 0 || pos >= path.Length - 1)
  169. {
  170. if (InternalGetDebuggerWindow(path) != null)
  171. {
  172. throw new NotSupportedException("Debugger window has been registered.");
  173. }
  174. m_DebuggerWindows.Add(new KeyValuePair<string, IDebuggerWindow>(path, debuggerWindow));
  175. RefreshDebuggerWindowNames();
  176. }
  177. else
  178. {
  179. string debuggerWindowGroupName = path.Substring(0, pos);
  180. string leftPath = path.Substring(pos + 1);
  181. DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
  182. if (debuggerWindowGroup == null)
  183. {
  184. if (InternalGetDebuggerWindow(debuggerWindowGroupName) != null)
  185. {
  186. throw new NotSupportedException("Debugger window has been registered, can not create debugger window group.");
  187. }
  188. debuggerWindowGroup = new DebuggerWindowGroup();
  189. m_DebuggerWindows.Add(new KeyValuePair<string, IDebuggerWindow>(debuggerWindowGroupName, debuggerWindowGroup));
  190. RefreshDebuggerWindowNames();
  191. }
  192. debuggerWindowGroup.RegisterDebuggerWindow(leftPath, debuggerWindow);
  193. }
  194. }
  195. private IDebuggerWindow InternalGetDebuggerWindow(string name)
  196. {
  197. foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
  198. {
  199. if (debuggerWindow.Key == name)
  200. {
  201. return debuggerWindow.Value;
  202. }
  203. }
  204. return null;
  205. }
  206. }
  207. }
  208. }