Skip to content

Commit 1ba44f8

Browse files
committed
Fixed stats created via the custom attribute not restoring display status between sessions.
1 parent cb9d520 commit 1ba44f8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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+
- Fixed stats created via the custom attribute not restoring display status between sessions.
89

910
## [1.0.3] - 2021-10-31
1011
- Added notice in developer console when C# evaluation is not supported.

Runtime/DevConsoleMono.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ internal sealed class DevConsoleMono : MonoBehaviour
110110
private const string PrefStats = "DevConsole.stats";
111111
private const string PrefHiddenStats = "DevConsole.hiddenStats";
112112
private const string PrefStatsFontSize = "DevConsole.statsFontSize";
113+
private const string PrefPersistStats = "DevConsole.persistStats";
113114

114115
#endregion
115116

@@ -408,9 +409,10 @@ internal sealed class DevConsoleMono : MonoBehaviour
408409

409410
private bool _isDisplayingStats;
410411
private GUIStyle _statStyle;
411-
private Dictionary<string, StatBase> _stats = new Dictionary<string, StatBase>();
412+
private readonly Dictionary<string, StatBase> _stats = new Dictionary<string, StatBase>();
412413
private HashSet<string> _hiddenStats = new HashSet<string>();
413-
private Dictionary<string, object> _cachedStats = new Dictionary<string, object>();
414+
private readonly Dictionary<string, object> _cachedStats = new Dictionary<string, object>();
415+
private List<string> _persistStats = new List<string>();
414416
private float _statUpdateTime;
415417
private int _statFontSize = StatDefaultFontSize;
416418
private int _oldStatFontSize = StatDefaultFontSize;
@@ -1166,6 +1168,7 @@ private void Awake()
11661168
InitBuiltInParsers();
11671169
InitAttributes();
11681170
InitMonoEvaluator();
1171+
_persistStats.Clear();
11691172

11701173
// Enable the console by default if in editor or a development build
11711174
if (Debug.isDebugBuild)
@@ -2925,7 +2928,7 @@ private void InitAttributes()
29252928

29262929
string name = attribute.Name ?? field.Name;
29272930
_stats[name] = new ReflectedStat(field);
2928-
if (!attribute.StartEnabled)
2931+
if (!attribute.StartEnabled && !_persistStats.Contains(name))
29292932
{
29302933
_hiddenStats.Add(name);
29312934
}
@@ -2941,7 +2944,7 @@ private void InitAttributes()
29412944

29422945
string name = attribute.Name ?? property.Name;
29432946
_stats[name] = new ReflectedStat(property);
2944-
if (!attribute.StartEnabled)
2947+
if (!attribute.StartEnabled && !_persistStats.Contains(name))
29452948
{
29462949
_hiddenStats.Add(name);
29472950
}
@@ -3501,6 +3504,7 @@ private void SavePreferences()
35013504
DevConsoleData.SetObject(PrefStats, _stats.Where(x => x.Value is EvaluatedStat).ToDictionary(x => x.Key, x => ((EvaluatedStat)x.Value).Expression));
35023505
DevConsoleData.SetObject(PrefHiddenStats, new HashSet<string>(_hiddenStats.Where(x => _stats.Keys.Contains(x))));
35033506
DevConsoleData.SetObject(PrefStatsFontSize, _statFontSize);
3507+
DevConsoleData.SetObject(PrefPersistStats, _stats.Where(x => !(x.Value is EvaluatedStat) && !_hiddenStats.Contains(x.Key)).Select(x => x.Key).ToList());
35043508

35053509
DevConsoleData.Save();
35063510
}
@@ -3531,6 +3535,7 @@ private void LoadPreferences()
35313535
}
35323536
_hiddenStats = DevConsoleData.GetObject(PrefHiddenStats, new HashSet<string>());
35333537
_statFontSize = _oldStatFontSize = DevConsoleData.GetObject(PrefStatsFontSize, StatDefaultFontSize);
3538+
_persistStats = DevConsoleData.GetObject(PrefPersistStats, new List<string>());
35343539

35353540
DevConsoleData.Clear();
35363541
}

0 commit comments

Comments
 (0)