Skip to content

Commit

Permalink
Slight simplifications to #97 + Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirkula committed Oct 27, 2024
1 parent fe646cf commit 6578689
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
24 changes: 23 additions & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 )`.
2 changes: 1 addition & 1 deletion Plugins/IngameDebugConsole/README.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ 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;
}

public override void Load()
{
DebugLogConsole.AddCustomParameterType(Method, type, readableName);
DebugLogConsole.AddCustomParameterType(type, (DebugLogConsole.ParseFunction)Delegate.CreateDelegate(typeof(DebugLogConsole.ParseFunction), Method), readableName);
}
}
}
9 changes: 1 addition & 8 deletions Plugins/IngameDebugConsole/Scripts/DebugLogConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 6578689

Please sign in to comment.