diff --git a/Assets/OpenTerminal/Sample/RotateCube.cs b/Assets/OpenTerminal/Sample/RotateCube.cs index 1b456ca..2a64d24 100644 --- a/Assets/OpenTerminal/Sample/RotateCube.cs +++ b/Assets/OpenTerminal/Sample/RotateCube.cs @@ -12,20 +12,20 @@ void Update() } - [Command("stop-cube", "stops the cube from rotating")] + [TerminalCommand("stop-cube", "stops the cube from rotating")] public void StopCube() { stop = true; } - [Command("rotate-cube", "rotates the cube")] + [TerminalCommand("rotate-cube", "rotates the cube")] public void RotateTheCube() { stop = false; } - [Command("move-cube", "move-cube(x,y,z) Moves the cube")] + [TerminalCommand("move-cube", "move-cube(x,y,z) Moves the cube")] public void Move(float x, float y, float z) { transform.position = new Vector3(x, y, z); diff --git a/Assets/OpenTerminal/Scripts/BasicCommands.cs b/Assets/OpenTerminal/Scripts/BasicCommands.cs index b409ace..3dc5db6 100644 --- a/Assets/OpenTerminal/Scripts/BasicCommands.cs +++ b/Assets/OpenTerminal/Scripts/BasicCommands.cs @@ -3,13 +3,13 @@ public class BasicCommands { - [Command("clear", "clears the terminal screen")] + [TerminalCommand("clear", "clears the terminal screen")] public void ClearTerminal() { Terminal.instance.Clear(); } - [Command("help", "Shows list of available commands")] + [TerminalCommand("help", "Shows list of available commands")] public string Help() { string help_string = "List of available commands:"; @@ -17,9 +17,9 @@ public string Help() { foreach (var attribute in method.GetCustomAttributes(true)) { - if (attribute is CommandAttribute) //Does not pass + if (attribute is TerminalCommandAttribute) //Does not pass { - CommandAttribute attr = (CommandAttribute)attribute; + TerminalCommandAttribute attr = (TerminalCommandAttribute)attribute; help_string += "\n " + attr.commandName + " --> " + attr.commandDesc; } } @@ -27,7 +27,7 @@ public string Help() return help_string; } - [Command("hide", "Hides the terminal")] + [TerminalCommand("hide", "Hides the terminal")] public void Hide() { Terminal.instance.Hide(); diff --git a/Assets/OpenTerminal/Scripts/SampleCommand.cs b/Assets/OpenTerminal/Scripts/SampleCommand.cs index 14761de..6da3375 100644 --- a/Assets/OpenTerminal/Scripts/SampleCommand.cs +++ b/Assets/OpenTerminal/Scripts/SampleCommand.cs @@ -2,7 +2,7 @@ public class SampleCommand { - [Command("debug", "Debugs a sample line in Unity Console")] + [TerminalCommand("debug", "Debugs a sample line in Unity Console")] public void SampleDebug(string input) { Debug.Log(input); diff --git a/Assets/OpenTerminal/Scripts/Terminal.cs b/Assets/OpenTerminal/Scripts/Terminal.cs index d1b8a47..807da21 100644 --- a/Assets/OpenTerminal/Scripts/Terminal.cs +++ b/Assets/OpenTerminal/Scripts/Terminal.cs @@ -116,9 +116,9 @@ private string ExecuteCommand(string inputText) foreach (var method in terminalMethods.methods) { foreach (object attribute in method.GetCustomAttributes(true)) // Returns all 3 of my attributes. - if (attribute is CommandAttribute) + if (attribute is TerminalCommandAttribute) { - CommandAttribute attr = (CommandAttribute)attribute; + TerminalCommandAttribute attr = (TerminalCommandAttribute)attribute; if (attr.commandName == command) { if (registered) Debug.LogError(TerminalStrings.MULTIPLE_COMMAND_NAMES + command); diff --git a/Assets/OpenTerminal/Scripts/TerminalAttribute.cs b/Assets/OpenTerminal/Scripts/TerminalAttribute.cs index db2d7bb..f1c3e17 100644 --- a/Assets/OpenTerminal/Scripts/TerminalAttribute.cs +++ b/Assets/OpenTerminal/Scripts/TerminalAttribute.cs @@ -1,16 +1,16 @@ using System; using UnityEngine; [AttributeUsage(AttributeTargets.Method)] -public class CommandAttribute : Attribute +public class TerminalCommandAttribute : Attribute { public string commandName; public string commandDesc; - public CommandAttribute(string name) + public TerminalCommandAttribute(string name) { commandName = name; } - public CommandAttribute(string name, string desc) + public TerminalCommandAttribute(string name, string desc) { commandName = name; commandDesc = desc; diff --git a/Assets/OpenTerminal/Scripts/TerminalMethods.cs b/Assets/OpenTerminal/Scripts/TerminalMethods.cs index 108bb7d..2004f74 100644 --- a/Assets/OpenTerminal/Scripts/TerminalMethods.cs +++ b/Assets/OpenTerminal/Scripts/TerminalMethods.cs @@ -10,19 +10,19 @@ public class TerminalMethods public TerminalMethods() { methods = new List(); - var assembly = System.AppDomain.CurrentDomain.Load("Assembly-CSharp"); - methods = assembly - .GetTypes() - .SelectMany(x => x.GetMethods()) - .Where(y => y.GetCustomAttributes(true).OfType().Any()).ToList(); - foreach (var method in methods) + + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { - foreach (var attribute in method.GetCustomAttributes(true)) + foreach (var method in assembly.GetTypes().SelectMany(x => x.GetMethods()).Where(y => y.GetCustomAttributes(true).OfType().Any()).ToList()) { - if (attribute is CommandAttribute) //Does not pass + methods.Add(method) + foreach (var attribute in method.GetCustomAttributes(true)) { - CommandAttribute attr = (CommandAttribute)attribute; - methodNames.Add(attr.commandName); + if (attribute is TerminalCommandAttribute) //Does not pass + { + TerminalCommandAttribute attr = (TerminalCommandAttribute)attribute; + methodNames.Add(attr.commandName); + } } } } @@ -32,4 +32,4 @@ public string[] GetCommandsContaining(string input) { return methodNames.Where(k => k.Contains(input)).ToArray(); } -} \ No newline at end of file +}