123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
-
- using System;
- using System.Collections.Generic;
- namespace GameFramework.Debugger
- {
- internal partial class DebuggerManager
- {
-
-
-
- private sealed class DebuggerWindowGroup : IDebuggerWindowGroup
- {
- private readonly List<KeyValuePair<string, IDebuggerWindow>> m_DebuggerWindows;
- private int m_SelectedIndex;
- private string[] m_DebuggerWindowNames;
- public DebuggerWindowGroup()
- {
- m_DebuggerWindows = new List<KeyValuePair<string, IDebuggerWindow>>();
- 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<string, IDebuggerWindow> 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<string, IDebuggerWindow> 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<string, IDebuggerWindow>(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<string, IDebuggerWindow>(debuggerWindowGroupName, debuggerWindowGroup));
- RefreshDebuggerWindowNames();
- }
- debuggerWindowGroup.RegisterDebuggerWindow(leftPath, debuggerWindow);
- }
- }
- private IDebuggerWindow InternalGetDebuggerWindow(string name)
- {
- foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
- {
- if (debuggerWindow.Key == name)
- {
- return debuggerWindow.Value;
- }
- }
- return null;
- }
- }
- }
- }
|