//------------------------------------------------------------ // Game Framework v3.x // Copyright © 2013-2017 Jiang Yin. All rights reserved. // Homepage: http://gameframework.cn/ // Feedback: mailto:jiangyin@gameframework.cn //------------------------------------------------------------ using System; using System.Collections.Generic; namespace GameFramework.Debugger { internal partial class DebuggerManager { /// /// 调试窗口组。 /// private sealed class DebuggerWindowGroup : IDebuggerWindowGroup { private readonly List> m_DebuggerWindows; private int m_SelectedIndex; private string[] m_DebuggerWindowNames; public DebuggerWindowGroup() { m_DebuggerWindows = new List>(); m_SelectedIndex = 0; m_DebuggerWindowNames = null; } /// /// 获取调试窗口数量。 /// public int DebuggerWindowCount { get { return m_DebuggerWindows.Count; } } /// /// 获取或设置当前选中的调试窗口索引。 /// public int SelectedIndex { get { return m_SelectedIndex; } set { m_SelectedIndex = value; } } /// /// 获取当前选中的调试窗口。 /// public IDebuggerWindow SelectedWindow { get { if (m_SelectedIndex >= m_DebuggerWindows.Count) { return null; } return m_DebuggerWindows[m_SelectedIndex].Value; } } /// /// 初始化调试组。 /// /// 初始化调试组参数。 public void Initialize(params object[] args) { } /// /// 关闭调试组。 /// public void Shutdown() { foreach (KeyValuePair debuggerWindow in m_DebuggerWindows) { debuggerWindow.Value.Shutdown(); } m_DebuggerWindows.Clear(); } /// /// 进入调试窗口。 /// public void OnEnter() { SelectedWindow.OnEnter(); } /// /// 离开调试窗口。 /// public void OnLeave() { SelectedWindow.OnLeave(); } /// /// 调试组轮询。 /// /// 逻辑流逝时间,以秒为单位。 /// 真实流逝时间,以秒为单位。 public void OnUpdate(float elapseSeconds, float realElapseSeconds) { SelectedWindow.OnUpdate(elapseSeconds, realElapseSeconds); } /// /// 调试窗口绘制。 /// public void OnDraw() { } private void RefreshDebuggerWindowNames() { m_DebuggerWindowNames = new string[m_DebuggerWindows.Count]; int index = 0; foreach (KeyValuePair debuggerWindow in m_DebuggerWindows) { m_DebuggerWindowNames[index++] = debuggerWindow.Key; } } /// /// 获取调试组的调试窗口名称集合。 /// public string[] GetDebuggerWindowNames() { return m_DebuggerWindowNames; } /// /// 获取调试窗口。 /// /// 调试窗口路径。 /// 要获取的调试窗口。 public IDebuggerWindow GetDebuggerWindow(string path) { if (string.IsNullOrEmpty(path)) { return null; } int pos = path.IndexOf('/'); if (pos < 0 || pos >= path.Length - 1) { return InternalGetDebuggerWindow(path); } else { string debuggerWindowGroupName = path.Substring(0, pos); string leftPath = path.Substring(pos + 1); DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName); if (debuggerWindowGroup == null) { return null; } return debuggerWindowGroup.GetDebuggerWindow(leftPath); } } /// /// 注册调试窗口。 /// /// 调试窗口路径。 /// 要注册的调试窗口。 public void RegisterDebuggerWindow(string path, IDebuggerWindow debuggerWindow) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("Path is invalid."); } int pos = path.IndexOf('/'); if (pos < 0 || pos >= path.Length - 1) { if (InternalGetDebuggerWindow(path) != null) { throw new NotSupportedException("Debugger window has been registered."); } m_DebuggerWindows.Add(new KeyValuePair(path, debuggerWindow)); RefreshDebuggerWindowNames(); } else { string debuggerWindowGroupName = path.Substring(0, pos); string leftPath = path.Substring(pos + 1); DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName); if (debuggerWindowGroup == null) { if (InternalGetDebuggerWindow(debuggerWindowGroupName) != null) { throw new NotSupportedException("Debugger window has been registered, can not create debugger window group."); } debuggerWindowGroup = new DebuggerWindowGroup(); m_DebuggerWindows.Add(new KeyValuePair(debuggerWindowGroupName, debuggerWindowGroup)); RefreshDebuggerWindowNames(); } debuggerWindowGroup.RegisterDebuggerWindow(leftPath, debuggerWindow); } } private IDebuggerWindow InternalGetDebuggerWindow(string name) { foreach (KeyValuePair debuggerWindow in m_DebuggerWindows) { if (debuggerWindow.Key == name) { return debuggerWindow.Value; } } return null; } } } }