mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-06 18:40:47 +00:00
50 lines
759 B
C#
50 lines
759 B
C#
using System;
|
|
|
|
namespace QSB.Utility.VariableSync
|
|
{
|
|
public class VariableReference<T>
|
|
{
|
|
private BaseVariableSyncer _owner;
|
|
|
|
public Func<T> Getter;
|
|
public Action<T> Setter;
|
|
|
|
public VariableReference(BaseVariableSyncer owner)
|
|
=> _owner = owner;
|
|
|
|
public T Value
|
|
{
|
|
get
|
|
{
|
|
if (Getter != null)
|
|
{
|
|
return Getter();
|
|
}
|
|
else
|
|
{
|
|
if (_owner.Ready)
|
|
{
|
|
DebugLog.ToConsole($"Warning - Getter is null!", OWML.Common.MessageType.Warning);
|
|
}
|
|
|
|
return default;
|
|
}
|
|
}
|
|
set
|
|
{
|
|
if (Setter != null)
|
|
{
|
|
Setter(value);
|
|
}
|
|
else
|
|
{
|
|
if (_owner.Ready)
|
|
{
|
|
DebugLog.ToConsole($"Warning - Setter is null!", OWML.Common.MessageType.Warning);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|