mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-19 15:51:52 +00:00
add way to track values and when they changed
This commit is contained in:
1 parent
30430dc95b
commit
5cb055f04d
2 files changed
+46
-5
No files matched your search
@@ -0,0 +1,37 @@
|
||||
namespace BetterAmongUs.Modules;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks a value and records the last time it was changed.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of value to track.</typeparam>
|
||||
internal sealed class ValueTracker<T>
|
||||
{
|
||||
private T? _currentValue;
|
||||
private T? _previousTrackedValue;
|
||||
private float _lastChangeTime;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current tracked value.
|
||||
/// </summary>
|
||||
public T? Value => _currentValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the time elapsed since the last value change.
|
||||
/// </summary>
|
||||
internal float TimeSinceLastChange => UnityEngine.Time.time - _lastChangeTime;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the tracked value if it differs from the current value.
|
||||
/// </summary>
|
||||
/// <param name="newValue">The new value to set.</param>
|
||||
internal void Update(T newValue)
|
||||
{
|
||||
_currentValue = newValue;
|
||||
|
||||
if (!Equals(newValue, _previousTrackedValue))
|
||||
{
|
||||
_previousTrackedValue = newValue;
|
||||
_lastChangeTime = UnityEngine.Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,15 +59,19 @@ internal sealed class ExtendedPlayerControl : MonoBehaviour, IMonoExtension<Play
|
||||
}
|
||||
}
|
||||
|
||||
internal readonly ValueTracker<bool> InVentTracker = new();
|
||||
private void Update()
|
||||
{
|
||||
if (_Player == null)
|
||||
return;
|
||||
|
||||
InVentTracker.Update(_Player.inVent);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
this.UnregisterExtension();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dictionary storing last name set for each player.
|
||||
/// </summary>
|
||||
internal readonly Dictionary<NetworkedPlayerInfo, string> NameSetLastFor = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user