Skip to content

Commit 5aa295e

Browse files
committed
Stats can now be in 3 forms: evaluated, reflected and lambda.
1 parent d492f8e commit 5aa295e

File tree

4 files changed

+258
-21
lines changed

4 files changed

+258
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ 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 user-defined developer console stats which are displayed on-screen (stats_ commands).
8+
- Added user-defined developer console stats which are displayed on-screen.
9+
- Changed preferences file to be deleted when unable to load correctly.
910
- Fixed exception not being caught when an issue occurs serialising or deserialising the preferences file.
11+
- Fixed exception not being caught when reading deserialising an object from the preferences file.
1012

1113
## [1.0.0] - 2021-08-22
1214
- Initial major release.

Runtime/DevConsole.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,26 @@ public static void ClearConsole()
381381
_console.ClearConsole();
382382
}
383383

384+
/// <summary>
385+
/// Set a tracked developer console stat that can be displayed on-screen.
386+
/// </summary>
387+
/// <param name="name"></param>
388+
/// <param name="func"></param>
389+
public static void SetTrackedStat(string name, Func<object> func)
390+
{
391+
_console.SetTrackedStat(name, func);
392+
}
393+
394+
/// <summary>
395+
/// Remove a tracked developer console stat.
396+
/// </summary>
397+
/// <param name="name"></param>
398+
/// <returns></returns>
399+
public static bool RemoveTrackedStat(string name)
400+
{
401+
return _console.RemoveTrackedStat(name);
402+
}
403+
384404
/// <summary>
385405
/// Invoke an enumerator as a Unity coroutine. Useful for commands that may not have a reference to a MonoBehaviour.
386406
/// </summary>

Runtime/DevConsoleData.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ public static void SetObject(string key, object value)
4343

4444
public static T GetObject<T>(string key, T defaultValue)
4545
{
46-
return !_data.ContainsKey(key) ? defaultValue : (T)_data[key];
46+
try
47+
{
48+
return !_data.ContainsKey(key) ? defaultValue : (T)_data[key];
49+
}
50+
catch (Exception)
51+
{
52+
return defaultValue;
53+
}
4754
}
4855

4956
public static void Save()
@@ -75,20 +82,26 @@ public static void Load()
7582

7683
FileStream fs = new FileStream(FilePath, FileMode.Open);
7784
BinaryFormatter bf = new BinaryFormatter();
85+
bool delete = false;
7886

7987
try
8088
{
8189
_data = (Dictionary<string, object>)bf.Deserialize(fs);
8290
}
8391
catch (Exception e)
8492
{
85-
DevConsole.LogException(e);
86-
DevConsole.LogError("Failed to load developer console preferences due an exception.");
93+
Debug.LogException(e);
94+
delete = true;
8795
}
8896
finally
8997
{
9098
fs.Close();
9199
}
100+
101+
if (delete)
102+
{
103+
File.Delete(FilePath);
104+
}
92105
}
93106

94107
public static void Clear()

0 commit comments

Comments
 (0)