@@ -42,7 +42,7 @@ internal sealed class DevConsoleMono : MonoBehaviour
42
42
#region Static fields and constants
43
43
44
44
private const string ErrorColour = "#E99497" ;
45
- private const string WarningColour = "#B3E283 " ;
45
+ private const string WarningColour = "#DEBF1F " ;
46
46
private const string SuccessColour = "#B3E283" ;
47
47
private const string ClearLogText = "Type <b>devconsole</b> for instructions on how to use the developer console." ;
48
48
private const int MaximumTextVertices = 64000 ;
@@ -56,6 +56,8 @@ internal sealed class DevConsoleMono : MonoBehaviour
56
56
private const int MaxCachedEnumTypes = 6 ;
57
57
private const float FpsUpdateRate = 4f ;
58
58
private const float StatUpdateRate = 0.1f ;
59
+ private const int StatDefaultFontSize = 18 ;
60
+ private const string MonoNotSupportedText = "C# expression evaluation is not supported on this platform." ;
59
61
60
62
#region Input constants
61
63
@@ -107,6 +109,7 @@ internal sealed class DevConsoleMono : MonoBehaviour
107
109
private const string PrefShowStats = "DevConsole.displayStats" ;
108
110
private const string PrefStats = "DevConsole.stats" ;
109
111
private const string PrefHiddenStats = "DevConsole.hiddenStats" ;
112
+ private const string PrefStatsFontSize = "DevConsole.statsFontSize" ;
110
113
111
114
#endregion
112
115
@@ -377,7 +380,7 @@ internal sealed class DevConsoleMono : MonoBehaviour
377
380
private readonly List < Type > _cacheEnumTypes = new List < Type > ( MaxCachedEnumTypes ) ;
378
381
379
382
/// <summary>
380
- /// Evaluator used by "cs_evaluate" and "cs_run" to execuet C# expressions or statements.
383
+ /// Evaluator used by "cs_evaluate" and "cs_run" to execute C# expressions or statements.
381
384
/// </summary>
382
385
private Evaluator _monoEvaluator = null ;
383
386
@@ -409,6 +412,8 @@ internal sealed class DevConsoleMono : MonoBehaviour
409
412
private HashSet < string > _hiddenStats = new HashSet < string > ( ) ;
410
413
private Dictionary < string , object > _cachedStats = new Dictionary < string , object > ( ) ;
411
414
private float _statUpdateTime ;
415
+ private int _statFontSize = StatDefaultFontSize ;
416
+ private int _oldStatFontSize = StatDefaultFontSize ;
412
417
413
418
#endregion
414
419
@@ -1175,6 +1180,11 @@ private void Awake()
1175
1180
ClearConsole ( ) ;
1176
1181
CloseConsole ( ) ;
1177
1182
1183
+ if ( _monoEvaluator == null )
1184
+ {
1185
+ LogWarning ( $ "Some features may not be available: { MonoNotSupportedText } ") ;
1186
+ }
1187
+
1178
1188
_init = false ;
1179
1189
}
1180
1190
@@ -1406,17 +1416,19 @@ private void OnGUI()
1406
1416
GUI . contentColor = oldContentColour ;
1407
1417
}
1408
1418
1409
- if ( _isDisplayingStats && _monoEvaluator != null && _stats . Any ( ) )
1419
+ if ( _isDisplayingStats && _stats . Any ( ) )
1410
1420
{
1411
- if ( _statStyle == null )
1421
+ if ( _statStyle == null || _statFontSize != _oldStatFontSize )
1412
1422
{
1413
1423
// Create the style
1414
1424
_statStyle = new GUIStyle ( GUI . skin . box )
1415
1425
{
1416
1426
alignment = TextAnchor . MiddleCenter ,
1417
- fontSize = 18 ,
1427
+ fontSize = _statFontSize ,
1418
1428
normal = { textColor = Color . white , background = Texture2D . whiteTexture }
1419
1429
} ;
1430
+
1431
+ _oldStatFontSize = _statFontSize ;
1420
1432
}
1421
1433
1422
1434
// Initialise
@@ -1468,7 +1480,7 @@ private void OnGUI()
1468
1480
1469
1481
// Set content
1470
1482
string content = $ "{ stat . Key } : { result ?? "NULL" } ";
1471
- GUI . contentColor = result == null ? Color . yellow : ( result . Equals ( "ERROR" ) ? Color . red : Color . white ) ;
1483
+ GUI . contentColor = result == null ? Color . yellow : ( ( result . Equals ( "ERROR" ) || result . Equals ( MonoNotSupportedText ) ) ? Color . red : Color . white ) ;
1472
1484
1473
1485
// Determine label size
1474
1486
Vector2 size = _statStyle . CalcSize ( new GUIContent ( content ) ) ;
@@ -2318,14 +2330,20 @@ void logChildren(GameObject obj, int tabAmount)
2318
2330
Parameter . Create ( "expression" , "The expression to evaluate" ) ,
2319
2331
input =>
2320
2332
{
2333
+ if ( _monoEvaluator == null )
2334
+ {
2335
+ DevConsole . LogError ( MonoNotSupportedText ) ;
2336
+ return ;
2337
+ }
2338
+
2321
2339
try
2322
2340
{
2323
2341
if ( ! input . EndsWith ( ";" ) )
2324
2342
{
2325
2343
input += ";" ;
2326
2344
}
2327
2345
2328
- object result = _monoEvaluator ? . Evaluate ( input ) ?? null ;
2346
+ object result = _monoEvaluator . Evaluate ( input ) ;
2329
2347
2330
2348
if ( result == null )
2331
2349
{
@@ -2355,14 +2373,20 @@ void logChildren(GameObject obj, int tabAmount)
2355
2373
Parameter . Create ( "statement" , "The statement to execute" ) ,
2356
2374
input =>
2357
2375
{
2376
+ if ( _monoEvaluator == null )
2377
+ {
2378
+ DevConsole . LogError ( MonoNotSupportedText ) ;
2379
+ return ;
2380
+ }
2381
+
2358
2382
try
2359
2383
{
2360
2384
if ( ! input . EndsWith ( ";" ) )
2361
2385
{
2362
2386
input += ";" ;
2363
2387
}
2364
2388
2365
- if ( _monoEvaluator ? . Run ( input ) ?? false )
2389
+ if ( _monoEvaluator . Run ( input ) )
2366
2390
{
2367
2391
LogSuccess ( "Successfully executed the C# expression or statement." ) ;
2368
2392
}
@@ -2384,6 +2408,12 @@ void logChildren(GameObject obj, int tabAmount)
2384
2408
"Display a list of all active using statements" ,
2385
2409
( ) =>
2386
2410
{
2411
+ if ( _monoEvaluator == null )
2412
+ {
2413
+ DevConsole . LogError ( MonoNotSupportedText ) ;
2414
+ return ;
2415
+ }
2416
+
2387
2417
string usings = _monoEvaluator . GetUsing ( ) ;
2388
2418
2389
2419
if ( string . IsNullOrEmpty ( usings ) )
@@ -2404,6 +2434,12 @@ void logChildren(GameObject obj, int tabAmount)
2404
2434
"Display a list of all local variables defined" ,
2405
2435
( ) =>
2406
2436
{
2437
+ if ( _monoEvaluator == null )
2438
+ {
2439
+ DevConsole . LogError ( MonoNotSupportedText ) ;
2440
+ return ;
2441
+ }
2442
+
2407
2443
string vars = _monoEvaluator . GetVars ( ) ;
2408
2444
2409
2445
if ( string . IsNullOrEmpty ( vars ) )
@@ -2516,16 +2552,18 @@ void logChildren(GameObject obj, int tabAmount)
2516
2552
AddCommand ( Command . Create (
2517
2553
"stats_list" ,
2518
2554
"" ,
2519
- "Display a list of the stored developer console stats that can be displayed on-screen" ,
2555
+ "Display a list of the tracked developer console stats that can be displayed on-screen" ,
2520
2556
( ) =>
2521
2557
{
2522
2558
if ( ! _stats . Any ( ) )
2523
2559
{
2524
- DevConsole . Log ( $ "There are no stored developer console stats. Use { GetCommand ( "stats_set" ) . GetFormattedName ( ) } to set one up.") ;
2560
+ DevConsole . Log ( $ "There are no tracked developer console stats. Use { GetCommand ( "stats_set" ) . GetFormattedName ( ) } to set one up.") ;
2525
2561
return ;
2526
2562
}
2527
2563
2528
- LogCollection ( _stats , x => $ "{ x . Key } : { x . Value } ({ x . Value . Desc } ){ ( _hiddenStats . Contains ( x . Key ) ? " [Disabled]" : "" ) } .") ;
2564
+ LogSeperator ( "Tracked developer console stats" ) ;
2565
+ LogCollection ( _stats , x => $ "<b>{ x . Key } :</b> { x . Value } ({ x . Value . Desc } ){ ( _hiddenStats . Contains ( x . Key ) ? " <i>[Disabled]</i>" : "" ) } .") ;
2566
+ LogSeperator ( ) ;
2529
2567
}
2530
2568
) ) ;
2531
2569
@@ -2647,6 +2685,25 @@ void logChildren(GameObject obj, int tabAmount)
2647
2685
}
2648
2686
) ) ;
2649
2687
2688
+ AddCommand ( Command . Create < int > (
2689
+ "stats_fontsize" ,
2690
+ "" ,
2691
+ "Query or set the font size of the tracked developer console stats" ,
2692
+ Parameter . Create ( "fontSize" , $ "Size of the font (default: { StatDefaultFontSize } )") ,
2693
+ f =>
2694
+ {
2695
+ if ( f <= 0 )
2696
+ {
2697
+ LogError ( "Font size must be non-zero and positive." ) ;
2698
+ return ;
2699
+ }
2700
+
2701
+ _statFontSize = f ;
2702
+ LogSuccess ( $ "Set the stats font size to { _statFontSize } (was { _oldStatFontSize } ).") ;
2703
+ } ,
2704
+ ( ) => LogVariable ( "Stats font size" , _statFontSize )
2705
+ ) ) ;
2706
+
2650
2707
#endregion
2651
2708
2652
2709
#region Misc commands
@@ -2866,7 +2923,7 @@ private void InitAttributes()
2866
2923
continue ;
2867
2924
}
2868
2925
2869
- string name = $ "var_ { field . Name } " ;
2926
+ string name = attribute . Name ?? field . Name ;
2870
2927
_stats [ name ] = new ReflectedStat ( field ) ;
2871
2928
if ( ! attribute . StartEnabled )
2872
2929
{
@@ -2882,7 +2939,7 @@ private void InitAttributes()
2882
2939
continue ;
2883
2940
}
2884
2941
2885
- string name = $ "var_ { property . Name } " ;
2942
+ string name = attribute . Name ?? property . Name ;
2886
2943
_stats [ name ] = new ReflectedStat ( property ) ;
2887
2944
if ( ! attribute . StartEnabled )
2888
2945
{
@@ -3443,6 +3500,7 @@ private void SavePreferences()
3443
3500
DevConsoleData . SetObject ( PrefShowStats , _isDisplayingStats ) ;
3444
3501
DevConsoleData . SetObject ( PrefStats , _stats . Where ( x => x . Value is EvaluatedStat ) . ToDictionary ( x => x . Key , x => ( ( EvaluatedStat ) x . Value ) . Expression ) ) ;
3445
3502
DevConsoleData . SetObject ( PrefHiddenStats , new HashSet < string > ( _hiddenStats . Where ( x => _stats . Keys . Contains ( x ) ) ) ) ;
3503
+ DevConsoleData . SetObject ( PrefStatsFontSize , _statFontSize ) ;
3446
3504
3447
3505
DevConsoleData . Save ( ) ;
3448
3506
}
@@ -3472,6 +3530,7 @@ private void LoadPreferences()
3472
3530
_stats . Add ( stat . Key , new EvaluatedStat ( stat . Value ) ) ;
3473
3531
}
3474
3532
_hiddenStats = DevConsoleData . GetObject ( PrefHiddenStats , new HashSet < string > ( ) ) ;
3533
+ _statFontSize = _oldStatFontSize = DevConsoleData . GetObject ( PrefStatsFontSize , StatDefaultFontSize ) ;
3475
3534
3476
3535
DevConsoleData . Clear ( ) ;
3477
3536
}
@@ -3490,26 +3549,33 @@ private void InitMonoEvaluator()
3490
3549
return ;
3491
3550
}
3492
3551
3493
- CompilerSettings settings = new CompilerSettings ( ) ;
3494
-
3495
- // Add assembly references to the settings
3496
- foreach ( Assembly assembly in AppDomain . CurrentDomain . GetAssemblies ( ) )
3552
+ try
3497
3553
{
3498
- if ( assembly == null )
3554
+ CompilerSettings settings = new CompilerSettings ( ) ;
3555
+
3556
+ // Add assembly references to the settings
3557
+ foreach ( Assembly assembly in AppDomain . CurrentDomain . GetAssemblies ( ) )
3499
3558
{
3500
- continue ;
3501
- }
3559
+ if ( assembly == null )
3560
+ {
3561
+ continue ;
3562
+ }
3502
3563
3503
- settings . AssemblyReferences . Add ( assembly . FullName ) ;
3504
- }
3564
+ settings . AssemblyReferences . Add ( assembly . FullName ) ;
3565
+ }
3505
3566
3506
- CompilerContext context = new CompilerContext ( settings , new ConsoleReportPrinter ( ) ) ;
3507
- _monoEvaluator = new Evaluator ( context ) ;
3567
+ CompilerContext context = new CompilerContext ( settings , new ConsoleReportPrinter ( ) ) ;
3568
+ _monoEvaluator = new Evaluator ( context ) ;
3508
3569
3509
- // Add the included using statements
3510
- foreach ( string includedUsing in _includedUsings )
3570
+ // Add the included using statements
3571
+ foreach ( string includedUsing in _includedUsings )
3572
+ {
3573
+ _monoEvaluator . Run ( $ "using { includedUsing } ;") ;
3574
+ }
3575
+ }
3576
+ catch ( Exception )
3511
3577
{
3512
- _monoEvaluator . Run ( $ "using { includedUsing } ;" ) ;
3578
+ _monoEvaluator = null ;
3513
3579
}
3514
3580
}
3515
3581
@@ -3627,6 +3693,11 @@ public EvaluatedStat(string expression)
3627
3693
3628
3694
public override object GetResult ( Evaluator evaluator )
3629
3695
{
3696
+ if ( evaluator == null )
3697
+ {
3698
+ return MonoNotSupportedText ;
3699
+ }
3700
+
3630
3701
return evaluator ? . Evaluate ( Expression ) ?? null ;
3631
3702
}
3632
3703
0 commit comments