Skip to content

Commit 2bc38a5

Browse files
authored
Added Console UI
1 parent 5f27d36 commit 2bc38a5

14 files changed

+1258
-6
lines changed

Commander/Runtime/CommandManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ private void OnApplicationQuit()
3030

3131
#endregion
3232

33+
#region Command Registration
34+
3335
private void RegisterAllSceneCommands()
3436
{
3537
// Find all types deriving MonoBehaviour that have at least one [ConsoleCommand]
@@ -62,5 +64,7 @@ private void RegisterAllSceneCommands()
6264
}
6365
}
6466
}
67+
68+
#endregion
6569
}
6670
}

Commander/Runtime/CommandTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ private void TestCommandMethod(int a, string b)
77
{
88
Debug.Log($"Test command executed with parameters: a={a}, b={b}");
99
}
10-
}
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
3+
public static class CommandParser
4+
{
5+
public static void Parse(string rawInput, out string command, out string[] args)
6+
{
7+
if (string.IsNullOrWhiteSpace(rawInput))
8+
{
9+
command = "";
10+
args = Array.Empty<string>();
11+
return;
12+
}
13+
14+
int idx = rawInput.IndexOf(' ');
15+
if (idx < 0)
16+
{
17+
command = rawInput;
18+
args = Array.Empty<string>();
19+
}
20+
else
21+
{
22+
command = rawInput.Substring(0, idx);
23+
var rest = rawInput.Substring(idx + 1);
24+
25+
args = rest.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);
26+
}
27+
}
28+
}

Commander/Runtime/Core/CommandParser.cs.meta

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

Commander/Runtime/Core/CommandRegistry.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public static class CommandRegistry
2323

2424
#endregion
2525

26+
#region Methods
27+
2628
/// <summary>
2729
/// Register given MonoBehaviour's methods as commands.
2830
/// Scans all methods in the MonoBehaviour for the Command attribute.
@@ -68,7 +70,6 @@ public static void RegisterCommand(MonoBehaviour target)
6870
{
6971
// Log the registration of commands
7072
Debug.Log($"[CommandRegistry] Registered {target.GetType().Name} with {_commands.Count} methods.");
71-
ExecuteCommand("TestCommand", 1, "Hello World");
7273
}
7374
}
7475

@@ -80,7 +81,6 @@ public static void ExecuteCommand(string commandName, params object[] parameters
8081
{
8182
try
8283
{
83-
// Invoke the method with the provided parameters
8484
mi.Invoke(target, parameters);
8585
}
8686
catch (Exception ex)
@@ -94,7 +94,7 @@ public static void ExecuteCommand(string commandName, params object[] parameters
9494
Debug.LogWarning($"Command '{commandName}' not found.");
9595
}
9696
}
97-
97+
9898
public static void ClearCommands()
9999
{
100100
_commands.Clear();
@@ -103,5 +103,7 @@ public static void ClearCommands()
103103
Debug.Log("[CommandRegistry] Cleared all commands.");
104104
}
105105
}
106+
107+
#endregion
106108
}
107109
}

0 commit comments

Comments
 (0)