forked from MinaPecheux/UnityTutorials-RTS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugCommand.cs
More file actions
78 lines (63 loc) · 1.77 KB
/
Copy pathDebugCommand.cs
File metadata and controls
78 lines (63 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Adapted from this video tutorial from Game Dev Guide:
* https://www.youtube.com/watch?v=VzOEM-4A2OM */
using System;
using System.Collections.Generic;
public class DebugCommandBase
{
public static Dictionary<string, DebugCommandBase> DebugCommands;
private string _id;
private string _description;
private string _format;
public DebugCommandBase(string id, string description, string format)
{
_id = id;
_description = description;
_format = format;
if (DebugCommands == null)
DebugCommands = new Dictionary<string, DebugCommandBase>();
string mainKeyword = format.Split(' ')[0];
DebugCommands[mainKeyword] = this;
}
public string Id => _id;
public string Description => _description;
public string Format => _format;
}
public class DebugCommand : DebugCommandBase
{
private Action _action;
public DebugCommand(string id, string description, string format, Action action)
: base(id, description, format)
{
_action = action;
}
public void Invoke()
{
_action.Invoke();
}
}
public class DebugCommand<T> : DebugCommandBase
{
private Action<T> _action;
public DebugCommand(string id, string description, string format, Action<T> action)
: base(id, description, format)
{
_action = action;
}
public void Invoke(T value)
{
_action.Invoke(value);
}
}
public class DebugCommand<T1, T2> : DebugCommandBase
{
private Action<T1, T2> _action;
public DebugCommand(string id, string description, string format, Action<T1, T2> action)
: base(id, description, format)
{
_action = action;
}
public void Invoke(T1 v1, T2 v2)
{
_action.Invoke(v1, v2);
}
}