Skip to content

Commit fad1736

Browse files
init debugger code
1 parent e7c44d1 commit fad1736

File tree

111 files changed

+7852
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+7852
-0
lines changed

Assets/Debugger.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Debugger/Base.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
4+
namespace Debugger
5+
{
6+
/// <summary>
7+
/// 游戏框架异常类。
8+
/// </summary>
9+
[Serializable]
10+
public class DebuggerException : Exception
11+
{
12+
/// <summary>
13+
/// 初始化游戏框架异常类的新实例。
14+
/// </summary>
15+
public DebuggerException()
16+
: base()
17+
{
18+
}
19+
20+
/// <summary>
21+
/// 使用指定错误消息初始化游戏框架异常类的新实例。
22+
/// </summary>
23+
/// <param name="message">描述错误的消息。</param>
24+
public DebuggerException(string message)
25+
: base(message)
26+
{
27+
}
28+
29+
/// <summary>
30+
/// 使用指定错误消息和对作为此异常原因的内部异常的引用来初始化游戏框架异常类的新实例。
31+
/// </summary>
32+
/// <param name="message">解释异常原因的错误消息。</param>
33+
/// <param name="innerException">导致当前异常的异常。如果 innerException 参数不为空引用,则在处理内部异常的 catch 块中引发当前异常。</param>
34+
public DebuggerException(string message, Exception innerException)
35+
: base(message, innerException)
36+
{
37+
}
38+
39+
/// <summary>
40+
/// 用序列化数据初始化游戏框架异常类的新实例。
41+
/// </summary>
42+
/// <param name="info">存有有关所引发异常的序列化的对象数据。</param>
43+
/// <param name="context">包含有关源或目标的上下文信息。</param>
44+
protected DebuggerException(SerializationInfo info, StreamingContext context)
45+
: base(info, context)
46+
{
47+
}
48+
}
49+
}

Assets/Debugger/Base/DebuggerException.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
using System.Collections.Generic;
2+
3+
namespace Debugger
4+
{
5+
internal sealed partial class DebuggerManager : IDebuggerManager
6+
{
7+
/// <summary>
8+
/// 调试器窗口组。
9+
/// </summary>
10+
private sealed class DebuggerWindowGroup : IDebuggerWindowGroup
11+
{
12+
private readonly List<KeyValuePair<string, IDebuggerWindow>> m_DebuggerWindows;
13+
private int m_SelectedIndex;
14+
private string[] m_DebuggerWindowNames;
15+
16+
public DebuggerWindowGroup()
17+
{
18+
m_DebuggerWindows = new List<KeyValuePair<string, IDebuggerWindow>>();
19+
m_SelectedIndex = 0;
20+
m_DebuggerWindowNames = null;
21+
}
22+
23+
/// <summary>
24+
/// 获取调试器窗口数量。
25+
/// </summary>
26+
public int DebuggerWindowCount
27+
{
28+
get
29+
{
30+
return m_DebuggerWindows.Count;
31+
}
32+
}
33+
34+
/// <summary>
35+
/// 获取或设置当前选中的调试器窗口索引。
36+
/// </summary>
37+
public int SelectedIndex
38+
{
39+
get
40+
{
41+
return m_SelectedIndex;
42+
}
43+
set
44+
{
45+
m_SelectedIndex = value;
46+
}
47+
}
48+
49+
/// <summary>
50+
/// 获取当前选中的调试器窗口。
51+
/// </summary>
52+
public IDebuggerWindow SelectedWindow
53+
{
54+
get
55+
{
56+
if (m_SelectedIndex >= m_DebuggerWindows.Count)
57+
{
58+
return null;
59+
}
60+
61+
return m_DebuggerWindows[m_SelectedIndex].Value;
62+
}
63+
}
64+
65+
/// <summary>
66+
/// 初始化调试组。
67+
/// </summary>
68+
/// <param name="args">初始化调试组参数。</param>
69+
public void Initialize(params object[] args)
70+
{
71+
}
72+
73+
/// <summary>
74+
/// 关闭调试组。
75+
/// </summary>
76+
public void Shutdown()
77+
{
78+
foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
79+
{
80+
debuggerWindow.Value.Shutdown();
81+
}
82+
83+
m_DebuggerWindows.Clear();
84+
}
85+
86+
/// <summary>
87+
/// 进入调试器窗口。
88+
/// </summary>
89+
public void OnEnter()
90+
{
91+
SelectedWindow.OnEnter();
92+
}
93+
94+
/// <summary>
95+
/// 离开调试器窗口。
96+
/// </summary>
97+
public void OnLeave()
98+
{
99+
SelectedWindow.OnLeave();
100+
}
101+
102+
/// <summary>
103+
/// 调试组轮询。
104+
/// </summary>
105+
/// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param>
106+
/// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param>
107+
public void OnUpdate(float elapseSeconds, float realElapseSeconds)
108+
{
109+
SelectedWindow.OnUpdate(elapseSeconds, realElapseSeconds);
110+
}
111+
112+
/// <summary>
113+
/// 调试器窗口绘制。
114+
/// </summary>
115+
public void OnDraw()
116+
{
117+
}
118+
119+
private void RefreshDebuggerWindowNames()
120+
{
121+
int index = 0;
122+
m_DebuggerWindowNames = new string[m_DebuggerWindows.Count];
123+
foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
124+
{
125+
m_DebuggerWindowNames[index++] = debuggerWindow.Key;
126+
}
127+
}
128+
129+
/// <summary>
130+
/// 获取调试组的调试器窗口名称集合。
131+
/// </summary>
132+
public string[] GetDebuggerWindowNames()
133+
{
134+
return m_DebuggerWindowNames;
135+
}
136+
137+
/// <summary>
138+
/// 获取调试器窗口。
139+
/// </summary>
140+
/// <param name="path">调试器窗口路径。</param>
141+
/// <returns>要获取的调试器窗口。</returns>
142+
public IDebuggerWindow GetDebuggerWindow(string path)
143+
{
144+
if (string.IsNullOrEmpty(path))
145+
{
146+
return null;
147+
}
148+
149+
int pos = path.IndexOf('/');
150+
if (pos < 0 || pos >= path.Length - 1)
151+
{
152+
return InternalGetDebuggerWindow(path);
153+
}
154+
155+
string debuggerWindowGroupName = path.Substring(0, pos);
156+
string leftPath = path.Substring(pos + 1);
157+
DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
158+
if (debuggerWindowGroup == null)
159+
{
160+
return null;
161+
}
162+
163+
return debuggerWindowGroup.GetDebuggerWindow(leftPath);
164+
}
165+
166+
/// <summary>
167+
/// 选中调试器窗口。
168+
/// </summary>
169+
/// <param name="path">调试器窗口路径。</param>
170+
/// <returns>是否成功选中调试器窗口。</returns>
171+
public bool SelectDebuggerWindow(string path)
172+
{
173+
if (string.IsNullOrEmpty(path))
174+
{
175+
return false;
176+
}
177+
178+
int pos = path.IndexOf('/');
179+
if (pos < 0 || pos >= path.Length - 1)
180+
{
181+
return InternalSelectDebuggerWindow(path);
182+
}
183+
184+
string debuggerWindowGroupName = path.Substring(0, pos);
185+
string leftPath = path.Substring(pos + 1);
186+
DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
187+
if (debuggerWindowGroup == null || !InternalSelectDebuggerWindow(debuggerWindowGroupName))
188+
{
189+
return false;
190+
}
191+
192+
return debuggerWindowGroup.SelectDebuggerWindow(leftPath);
193+
}
194+
195+
/// <summary>
196+
/// 注册调试器窗口。
197+
/// </summary>
198+
/// <param name="path">调试器窗口路径。</param>
199+
/// <param name="debuggerWindow">要注册的调试器窗口。</param>
200+
public void RegisterDebuggerWindow(string path, IDebuggerWindow debuggerWindow)
201+
{
202+
if (string.IsNullOrEmpty(path))
203+
{
204+
throw new DebuggerException("Path is invalid.");
205+
}
206+
207+
int pos = path.IndexOf('/');
208+
if (pos < 0 || pos >= path.Length - 1)
209+
{
210+
if (InternalGetDebuggerWindow(path) != null)
211+
{
212+
throw new DebuggerException("Debugger window has been registered.");
213+
}
214+
215+
m_DebuggerWindows.Add(new KeyValuePair<string, IDebuggerWindow>(path, debuggerWindow));
216+
RefreshDebuggerWindowNames();
217+
}
218+
else
219+
{
220+
string debuggerWindowGroupName = path.Substring(0, pos);
221+
string leftPath = path.Substring(pos + 1);
222+
DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
223+
if (debuggerWindowGroup == null)
224+
{
225+
if (InternalGetDebuggerWindow(debuggerWindowGroupName) != null)
226+
{
227+
throw new DebuggerException("Debugger window has been registered, can not create debugger window group.");
228+
}
229+
230+
debuggerWindowGroup = new DebuggerWindowGroup();
231+
m_DebuggerWindows.Add(new KeyValuePair<string, IDebuggerWindow>(debuggerWindowGroupName, debuggerWindowGroup));
232+
RefreshDebuggerWindowNames();
233+
}
234+
235+
debuggerWindowGroup.RegisterDebuggerWindow(leftPath, debuggerWindow);
236+
}
237+
}
238+
239+
/// <summary>
240+
/// 解除注册调试器窗口。
241+
/// </summary>
242+
/// <param name="path">调试器窗口路径。</param>
243+
/// <returns>是否解除注册调试器窗口成功。</returns>
244+
public bool UnregisterDebuggerWindow(string path)
245+
{
246+
if (string.IsNullOrEmpty(path))
247+
{
248+
return false;
249+
}
250+
251+
int pos = path.IndexOf('/');
252+
if (pos < 0 || pos >= path.Length - 1)
253+
{
254+
IDebuggerWindow debuggerWindow = InternalGetDebuggerWindow(path);
255+
bool result = m_DebuggerWindows.Remove(new KeyValuePair<string, IDebuggerWindow>(path, debuggerWindow));
256+
debuggerWindow.Shutdown();
257+
RefreshDebuggerWindowNames();
258+
return result;
259+
}
260+
261+
string debuggerWindowGroupName = path.Substring(0, pos);
262+
string leftPath = path.Substring(pos + 1);
263+
DebuggerWindowGroup debuggerWindowGroup = (DebuggerWindowGroup)InternalGetDebuggerWindow(debuggerWindowGroupName);
264+
if (debuggerWindowGroup == null)
265+
{
266+
return false;
267+
}
268+
269+
return debuggerWindowGroup.UnregisterDebuggerWindow(leftPath);
270+
}
271+
272+
private IDebuggerWindow InternalGetDebuggerWindow(string name)
273+
{
274+
foreach (KeyValuePair<string, IDebuggerWindow> debuggerWindow in m_DebuggerWindows)
275+
{
276+
if (debuggerWindow.Key == name)
277+
{
278+
return debuggerWindow.Value;
279+
}
280+
}
281+
282+
return null;
283+
}
284+
285+
private bool InternalSelectDebuggerWindow(string name)
286+
{
287+
for (int i = 0; i < m_DebuggerWindows.Count; i++)
288+
{
289+
if (m_DebuggerWindows[i].Key == name)
290+
{
291+
m_SelectedIndex = i;
292+
return true;
293+
}
294+
}
295+
296+
return false;
297+
}
298+
}
299+
}
300+
}

Assets/Debugger/Base/DebuggerManager.DebuggerWindowGroup.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)