diff --git a/.github/README.md b/.github/README.md index b5b9313..582011c 100644 --- a/.github/README.md +++ b/.github/README.md @@ -196,6 +196,8 @@ Use `DebugLogConsole.RemoveCommand( string command )` or one of the `DebugLogCon ### Extending Supported Parameter Types +- **Strongly Typed Functions** + Use `DebugLogConsole.AddCustomParameterType( Type type, ParseFunction parseFunction, string typeReadableName = null )`: ```csharp @@ -251,4 +253,24 @@ public class TestScript : MonoBehaviour } ``` -To remove the custom parameter type, you can use `DebugLogConsole.RemoveCustomParameterType( Type type )`. +- **ConsoleCustomTypeParser Attribute** + +Simply add **IngameDebugConsole.ConsoleCustomTypeParser** attribute to your functions. These functions must have the following signature: `public static bool ParseFunction( string input, out object output );` + +```csharp +using UnityEngine; +using IngameDebugConsole; + +public class TestScript : MonoBehaviour +{ + [ConsoleCustomTypeParser( typeof( Person ) )] + public static bool ParsePerson( string input, out object output ) + { + // Same as above... + } +} +``` + +### Removing Supported Custom Parameter Types + +Use `DebugLogConsole.RemoveCustomParameterType( Type type )`. diff --git a/Plugins/IngameDebugConsole/README.txt b/Plugins/IngameDebugConsole/README.txt index b4cb4f4..bc59ec2 100644 --- a/Plugins/IngameDebugConsole/README.txt +++ b/Plugins/IngameDebugConsole/README.txt @@ -1,4 +1,4 @@ -= In-game Debug Console (v1.6.8) = += In-game Debug Console (v1.6.9) = Documentation: https://github.com/yasirkula/UnityIngameDebugConsole FAQ: https://github.com/yasirkula/UnityIngameDebugConsole#faq diff --git a/Plugins/IngameDebugConsole/Scripts/Attributes/ConsoleCustomTypeParserAttribute.cs b/Plugins/IngameDebugConsole/Scripts/Attributes/ConsoleCustomTypeParserAttribute.cs index a7ba36d..412c65f 100644 --- a/Plugins/IngameDebugConsole/Scripts/Attributes/ConsoleCustomTypeParserAttribute.cs +++ b/Plugins/IngameDebugConsole/Scripts/Attributes/ConsoleCustomTypeParserAttribute.cs @@ -10,7 +10,7 @@ public class ConsoleCustomTypeParserAttribute : ConsoleAttribute public override int Order { get { return 0; } } - public ConsoleCustomTypeParserAttribute(Type type, string readableName) + public ConsoleCustomTypeParserAttribute(Type type, string readableName = null) { this.type = type; this.readableName = readableName; @@ -18,7 +18,7 @@ public ConsoleCustomTypeParserAttribute(Type type, string readableName) public override void Load() { - DebugLogConsole.AddCustomParameterType(Method, type, readableName); + DebugLogConsole.AddCustomParameterType(type, (DebugLogConsole.ParseFunction)Delegate.CreateDelegate(typeof(DebugLogConsole.ParseFunction), Method), readableName); } } } \ No newline at end of file diff --git a/Plugins/IngameDebugConsole/Scripts/DebugLogConsole.cs b/Plugins/IngameDebugConsole/Scripts/DebugLogConsole.cs index 86f743c..860d7b4 100644 --- a/Plugins/IngameDebugConsole/Scripts/DebugLogConsole.cs +++ b/Plugins/IngameDebugConsole/Scripts/DebugLogConsole.cs @@ -202,9 +202,8 @@ public static void SearchAssemblyForConsoleMethods( Assembly assembly ) { foreach( MethodInfo method in type.GetMethods( BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly ) ) { - foreach( object attribute in method.GetCustomAttributes( typeof(ConsoleAttribute), true ) ) + foreach( ConsoleAttribute consoleAttribute in method.GetCustomAttributes( typeof(ConsoleAttribute), false ) ) { - ConsoleAttribute consoleAttribute = (ConsoleAttribute)attribute; consoleAttribute.SetMethod(method); methods.Add(consoleAttribute); } @@ -383,12 +382,6 @@ public static void AddCustomParameterType( Type type, ParseFunction parseFunctio typeReadableNames[type] = typeReadableName; } - internal static void AddCustomParameterType(MethodInfo method, Type type, string readableName) - { - ParseFunction function = (ParseFunction)Delegate.CreateDelegate(typeof(ParseFunction), method); - AddCustomParameterType(type, function, readableName); - } - // Remove a custom Type from the list of recognized command parameter Types public static void RemoveCustomParameterType( Type type ) { diff --git a/package.json b/package.json index 406358b..eebd29e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.yasirkula.ingamedebugconsole", "displayName": "In-game Debug Console", - "version": "1.6.8", + "version": "1.6.9", "documentationUrl": "https://github.com/yasirkula/UnityIngameDebugConsole", "changelogUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/releases", "licensesUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/blob/master/LICENSE.txt",