2022-01-18 10:06:15 -08:00
|
|
|
|
using Mirror;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Utility.VariableSync
|
2021-11-26 17:36:14 +00:00
|
|
|
|
{
|
2022-01-18 10:06:15 -08:00
|
|
|
|
public abstract class BaseVariableSyncer<T> : QSBNetworkBehaviour
|
2022-01-14 18:15:48 -08:00
|
|
|
|
{
|
2022-01-14 20:15:32 -08:00
|
|
|
|
protected override float SendInterval => 0.1f;
|
2022-01-18 10:06:15 -08:00
|
|
|
|
|
|
|
|
|
private T _prevValue;
|
|
|
|
|
[NonSerialized]
|
|
|
|
|
public T Value;
|
|
|
|
|
|
|
|
|
|
protected override bool HasChanged() => !EqualityComparer<T>.Default.Equals(_prevValue, Value);
|
|
|
|
|
protected override void UpdatePrevData() => _prevValue = Value;
|
2022-01-27 03:15:52 -08:00
|
|
|
|
protected override void Serialize(NetworkWriter writer) => writer.Write(Value);
|
|
|
|
|
protected override void Deserialize(NetworkReader reader) => Value = reader.Read<T>();
|
2022-01-14 18:15:48 -08:00
|
|
|
|
}
|
2021-11-26 17:36:14 +00:00
|
|
|
|
}
|