Skip to content

Commit 6578689

Browse files
committed
Slight simplifications to #97 + Updated README
1 parent fe646cf commit 6578689

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

.github/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ Use `DebugLogConsole.RemoveCommand( string command )` or one of the `DebugLogCon
196196

197197
### Extending Supported Parameter Types
198198

199+
- **Strongly Typed Functions**
200+
199201
Use `DebugLogConsole.AddCustomParameterType( Type type, ParseFunction parseFunction, string typeReadableName = null )`:
200202

201203
```csharp
@@ -251,4 +253,24 @@ public class TestScript : MonoBehaviour
251253
}
252254
```
253255

254-
To remove the custom parameter type, you can use `DebugLogConsole.RemoveCustomParameterType( Type type )`.
256+
- **ConsoleCustomTypeParser Attribute**
257+
258+
Simply add **IngameDebugConsole.ConsoleCustomTypeParser** attribute to your functions. These functions must have the following signature: `public static bool ParseFunction( string input, out object output );`
259+
260+
```csharp
261+
using UnityEngine;
262+
using IngameDebugConsole;
263+
264+
public class TestScript : MonoBehaviour
265+
{
266+
[ConsoleCustomTypeParser( typeof( Person ) )]
267+
public static bool ParsePerson( string input, out object output )
268+
{
269+
// Same as above...
270+
}
271+
}
272+
```
273+
274+
### Removing Supported Custom Parameter Types
275+
276+
Use `DebugLogConsole.RemoveCustomParameterType( Type type )`.

Plugins/IngameDebugConsole/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= In-game Debug Console (v1.6.8) =
1+
= In-game Debug Console (v1.6.9) =
22

33
Documentation: https://github.com/yasirkula/UnityIngameDebugConsole
44
FAQ: https://github.com/yasirkula/UnityIngameDebugConsole#faq

Plugins/IngameDebugConsole/Scripts/Attributes/ConsoleCustomTypeParserAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ public class ConsoleCustomTypeParserAttribute : ConsoleAttribute
1010

1111
public override int Order { get { return 0; } }
1212

13-
public ConsoleCustomTypeParserAttribute(Type type, string readableName)
13+
public ConsoleCustomTypeParserAttribute(Type type, string readableName = null)
1414
{
1515
this.type = type;
1616
this.readableName = readableName;
1717
}
1818

1919
public override void Load()
2020
{
21-
DebugLogConsole.AddCustomParameterType(Method, type, readableName);
21+
DebugLogConsole.AddCustomParameterType(type, (DebugLogConsole.ParseFunction)Delegate.CreateDelegate(typeof(DebugLogConsole.ParseFunction), Method), readableName);
2222
}
2323
}
2424
}

Plugins/IngameDebugConsole/Scripts/DebugLogConsole.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ public static void SearchAssemblyForConsoleMethods( Assembly assembly )
202202
{
203203
foreach( MethodInfo method in type.GetMethods( BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly ) )
204204
{
205-
foreach( object attribute in method.GetCustomAttributes( typeof(ConsoleAttribute), true ) )
205+
foreach( ConsoleAttribute consoleAttribute in method.GetCustomAttributes( typeof(ConsoleAttribute), false ) )
206206
{
207-
ConsoleAttribute consoleAttribute = (ConsoleAttribute)attribute;
208207
consoleAttribute.SetMethod(method);
209208
methods.Add(consoleAttribute);
210209
}
@@ -383,12 +382,6 @@ public static void AddCustomParameterType( Type type, ParseFunction parseFunctio
383382
typeReadableNames[type] = typeReadableName;
384383
}
385384

386-
internal static void AddCustomParameterType(MethodInfo method, Type type, string readableName)
387-
{
388-
ParseFunction function = (ParseFunction)Delegate.CreateDelegate(typeof(ParseFunction), method);
389-
AddCustomParameterType(type, function, readableName);
390-
}
391-
392385
// Remove a custom Type from the list of recognized command parameter Types
393386
public static void RemoveCustomParameterType( Type type )
394387
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.ingamedebugconsole",
33
"displayName": "In-game Debug Console",
4-
"version": "1.6.8",
4+
"version": "1.6.9",
55
"documentationUrl": "https://github.com/yasirkula/UnityIngameDebugConsole",
66
"changelogUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnityIngameDebugConsole/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)