Skip to content

Commit 30265ba

Browse files
committed
Stats font size command now changes fps display size too.
1 parent d7d3932 commit 30265ba

File tree

2 files changed

+43
-42
lines changed

2 files changed

+43
-42
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
- Added properties for accessing the current average fps and milliseconds per frame.
9+
- Changed stats_fontsize command to also affect the fps display.
810
- Fixed stats created via the custom attribute not restoring display status between sessions.
911
- Fixed font size issue in console input for commands with a long signature.
1012

Runtime/DevConsoleMono.cs

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ internal sealed class DevConsoleMono : MonoBehaviour
415415
private List<string> _persistStats = new List<string>();
416416
private float _statUpdateTime;
417417
private int _statFontSize = StatDefaultFontSize;
418-
private int _oldStatFontSize = StatDefaultFontSize;
419418

420419
#endregion
421420

@@ -1399,13 +1398,13 @@ private void OnGUI()
13991398

14001399
if (_isDisplayingFps)
14011400
{
1402-
if (_fpsStyle == null)
1401+
if (_fpsStyle == null || _statFontSize != _statStyle.fontSize)
14031402
{
14041403
// Create the style
14051404
_fpsStyle = new GUIStyle(GUI.skin.box)
14061405
{
14071406
alignment = TextAnchor.MiddleCenter,
1408-
fontSize = 20,
1407+
fontSize = _statFontSize,
14091408
normal = { textColor = Color.white, background = Texture2D.whiteTexture }
14101409
};
14111410

@@ -1421,7 +1420,7 @@ private void OnGUI()
14211420

14221421
// Create label
14231422
GUI.Box(
1424-
new Rect(10, 10, _fpsLabelSize.x + 10f, _fpsLabelSize.y + 10f),
1423+
new Rect(10f, 10f, _fpsLabelSize.x + 10f, _fpsLabelSize.y + 10f),
14251424
$"{_fpsMs:0.00} ms ({_fps:0.} fps)",
14261425
_fpsStyle);
14271426

@@ -1431,7 +1430,7 @@ private void OnGUI()
14311430

14321431
if (_isDisplayingStats && _stats.Any())
14331432
{
1434-
if (_statStyle == null || _statFontSize != _oldStatFontSize)
1433+
if (_statStyle == null || _statFontSize != _statStyle.fontSize)
14351434
{
14361435
// Create the style
14371436
_statStyle = new GUIStyle(GUI.skin.box)
@@ -1440,15 +1439,14 @@ private void OnGUI()
14401439
fontSize = _statFontSize,
14411440
normal = { textColor = Color.white, background = Texture2D.whiteTexture }
14421441
};
1443-
1444-
_oldStatFontSize = _statFontSize;
14451442
}
14461443

14471444
// Initialise
14481445
Color oldBackgroundColour = GUI.backgroundColor;
14491446
Color oldContentColour = GUI.contentColor;
14501447
GUI.backgroundColor = new Color(0f, 0f, 0f, 0.75f);
14511448
const float padding = 5f;
1449+
float startY = (padding * 2f) + (_isDisplayingFps ? (_fpsLabelSize.y + 10f) : 0f);
14521450
int num = 0;
14531451

14541452
// Check if should update the cached stats
@@ -1500,7 +1498,7 @@ private void OnGUI()
15001498

15011499
// Create the label
15021500
GUI.Box(
1503-
new Rect(10, 50 + ((num * (size.y + 10f + padding)) + padding), size.x + 10f, size.y + 10f),
1501+
new Rect(10, startY + ((num * (size.y + 10f + padding)) + padding), size.x + 10f, size.y + 10f),
15041502
content,
15051503
_statStyle);
15061504

@@ -1894,37 +1892,6 @@ private void InitBuiltInCommands()
18941892
() => LogVariable("Application path", AppDomain.CurrentDomain.BaseDirectory)
18951893
));
18961894

1897-
AddCommand(Command.Create<bool?>(
1898-
"showfps",
1899-
"displayfps",
1900-
"Query or set whether the fps is being displayed on-screen",
1901-
Parameter.Create("enabled", "Whether the fps is being displayed on-screen (use \"NULL\" to toggle)"),
1902-
b =>
1903-
{
1904-
if (!b.HasValue)
1905-
{
1906-
b = !_isDisplayingFps;
1907-
}
1908-
1909-
if (b != _isDisplayingFps)
1910-
{
1911-
_isDisplayingFps = !_isDisplayingFps;
1912-
1913-
if (_isDisplayingFps)
1914-
{
1915-
_fps = 0;
1916-
_fpsMs = 0f;
1917-
_fpsDeltaTime = 0f;
1918-
_fpsElapsed = 0f;
1919-
_fpsStyle = null;
1920-
}
1921-
}
1922-
1923-
LogSuccess($"{(b.Value ? "Enabled" : "Disabled")} the on-screen fps.");
1924-
},
1925-
() => LogVariable("Show fps", _isDisplayingFps)
1926-
));
1927-
19281895
#endregion
19291896

19301897
#region Screen commands
@@ -2562,6 +2529,37 @@ void logChildren(GameObject obj, int tabAmount)
25622529
}
25632530
));
25642531

2532+
AddCommand(Command.Create<bool?>(
2533+
"stats_showfps",
2534+
"stats_displayfps,showfps,displayfps",
2535+
"Query or set whether the fps is being displayed on-screen",
2536+
Parameter.Create("enabled", "Whether the fps is being displayed on-screen (use \"NULL\" to toggle)"),
2537+
b =>
2538+
{
2539+
if (!b.HasValue)
2540+
{
2541+
b = !_isDisplayingFps;
2542+
}
2543+
2544+
if (b != _isDisplayingFps)
2545+
{
2546+
_isDisplayingFps = !_isDisplayingFps;
2547+
2548+
if (_isDisplayingFps)
2549+
{
2550+
_fps = 0;
2551+
_fpsMs = 0f;
2552+
_fpsDeltaTime = 0f;
2553+
_fpsElapsed = 0f;
2554+
_fpsStyle = null;
2555+
}
2556+
}
2557+
2558+
LogSuccess($"{(b.Value ? "Enabled" : "Disabled")} the on-screen fps.");
2559+
},
2560+
() => LogVariable("Show fps", _isDisplayingFps)
2561+
));
2562+
25652563
AddCommand(Command.Create(
25662564
"stats_list",
25672565
"",
@@ -2701,7 +2699,7 @@ void logChildren(GameObject obj, int tabAmount)
27012699
AddCommand(Command.Create<int>(
27022700
"stats_fontsize",
27032701
"",
2704-
"Query or set the font size of the tracked developer console stats",
2702+
"Query or set the font size of the tracked developer console stats & fps display",
27052703
Parameter.Create("fontSize", $"Size of the font (default: {StatDefaultFontSize})"),
27062704
f =>
27072705
{
@@ -2711,8 +2709,9 @@ void logChildren(GameObject obj, int tabAmount)
27112709
return;
27122710
}
27132711

2712+
int oldStatFontSize = _statFontSize;
27142713
_statFontSize = f;
2715-
LogSuccess($"Set the stats font size to {_statFontSize} (was {_oldStatFontSize}).");
2714+
LogSuccess($"Set the stats font size to {_statFontSize} (was {oldStatFontSize}).");
27162715
},
27172716
() => LogVariable("Stats font size", _statFontSize)
27182717
));
@@ -3544,7 +3543,7 @@ private void LoadPreferences()
35443543
_stats.Add(stat.Key, new EvaluatedStat(stat.Value));
35453544
}
35463545
_hiddenStats = DevConsoleData.GetObject(PrefHiddenStats, new HashSet<string>());
3547-
_statFontSize = _oldStatFontSize = DevConsoleData.GetObject(PrefStatsFontSize, StatDefaultFontSize);
3546+
_statFontSize = DevConsoleData.GetObject(PrefStatsFontSize, StatDefaultFontSize);
35483547
_persistStats = DevConsoleData.GetObject(PrefPersistStats, new List<string>());
35493548

35503549
DevConsoleData.Clear();

0 commit comments

Comments
 (0)