File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed
Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414- Added command: "colour" - displays the provided colour in the developer console.
1515- Changed DevConsole.InvokeCoroutine method to return the Coroutine instance.
1616- Fixed Unity logs from other threads not showing in the developer console log.
17+ - Fixed generic or nullable parameter types not having their type displayed nicely.
1718
1819## [ 0.2.1-alpha] - 2021-08-09
1920- Added documentation.
Original file line number Diff line number Diff line change 99using System ;
1010using System . Collections ;
1111using System . Collections . Generic ;
12+ using System . Linq ;
1213using System . Runtime . CompilerServices ;
1314using UnityEngine ;
1415
@@ -356,6 +357,27 @@ IEnumerator Invoke()
356357 return _console . StartCoroutine ( Invoke ( ) ) ;
357358 }
358359
360+ /// <summary>
361+ /// Get the user-friendly name of the parameter type.
362+ /// </summary>
363+ /// <param name="type"></param>
364+ /// <returns></returns>
365+ internal static string GetFriendlyName ( Type type )
366+ {
367+ if ( type . IsGenericType )
368+ {
369+ Type nullable = Nullable . GetUnderlyingType ( type ) ;
370+ if ( nullable != null )
371+ {
372+ return $ "{ GetFriendlyName ( nullable ) } ?";
373+ }
374+
375+ return $ "{ type . Name . Split ( '`' ) [ 0 ] } <{ string . Join ( ", " , type . GetGenericArguments ( ) . Select ( x => GetFriendlyName ( x ) ) ) } >";
376+ }
377+
378+ return type . Name ;
379+ }
380+
359381 #region Invoke events
360382
361383 internal static void InvokeOnConsoleEnabled ( )
Original file line number Diff line number Diff line change 33// Created by: DavidFDev
44
55using System ;
6+ using System . Linq ;
67using System . Reflection ;
78
89namespace DavidFDev . DevConsole
@@ -50,6 +51,11 @@ private Parameter() { }
5051 /// </summary>
5152 internal Type Type { get ; private set ; }
5253
54+ /// <summary>
55+ /// User-friendly name of the parameter type.
56+ /// </summary>
57+ internal string FriendlyTypeName { get ; private set ; }
58+
5359 /// <summary>
5460 /// Name of the parameter.
5561 /// </summary>
@@ -66,7 +72,7 @@ private Parameter() { }
6672
6773 public override string ToString ( )
6874 {
69- return $ "({ Type . Name } ){ Name } ";
75+ return $ "({ FriendlyTypeName } ){ Name } ";
7076 }
7177
7278 /// <summary>
@@ -87,6 +93,7 @@ internal Parameter SetType<T>()
8793 internal Parameter SetType ( Type type )
8894 {
8995 Type = type ;
96+ FriendlyTypeName = DevConsole . GetFriendlyName ( type ) ;
9097
9198 // If the type is an enum, add special help text
9299 if ( type . IsEnum )
@@ -125,7 +132,7 @@ internal Parameter SetType(Type type)
125132 /// <returns></returns>
126133 internal string ToFormattedString ( )
127134 {
128- return $ "<i>({ Type . Name } )</i><b>{ Name } </b>";
135+ return $ "<i>({ FriendlyTypeName } )</i><b>{ Name } </b>";
129136 }
130137
131138 #endregion
You can’t perform that action at this time.
0 commit comments