Merge branch 'dev' into steamworks

This commit is contained in:
JohnCorby 2022-01-18 10:07:14 -08:00
commit d55b029ce8
5 changed files with 25 additions and 40 deletions

View File

@ -22,7 +22,11 @@ namespace Mirror.Weaver
public static bool IsDerivedFrom(this TypeReference tr, Type baseClass)
{
if (tr == null)
return false;
TypeDefinition td = tr.Resolve();
if (td == null)
return false;
if (!td.IsClass)
return false;

View File

@ -1,7 +1,20 @@
namespace QSB.Utility.VariableSync
using Mirror;
using System;
using System.Collections.Generic;
namespace QSB.Utility.VariableSync
{
public abstract class BaseVariableSyncer : QSBNetworkBehaviour
public abstract class BaseVariableSyncer<T> : QSBNetworkBehaviour
{
protected override float SendInterval => 0.1f;
private T _prevValue;
[NonSerialized]
public T Value;
protected override bool HasChanged() => !EqualityComparer<T>.Default.Equals(_prevValue, Value);
protected override void UpdatePrevData() => _prevValue = Value;
protected override void Serialize(NetworkWriter writer, bool initialState) => writer.Write(Value);
protected override void Deserialize(NetworkReader reader, bool initialState) => Value = reader.Read<T>();
}
}

View File

@ -1,17 +1,6 @@
using Mirror;
using System;
namespace QSB.Utility.VariableSync
namespace QSB.Utility.VariableSync
{
public class BoolVariableSyncer : BaseVariableSyncer
public class BoolVariableSyncer : BaseVariableSyncer<bool>
{
private bool _prevValue;
[NonSerialized]
public bool Value;
protected override bool HasChanged() => Value != _prevValue;
protected override void UpdatePrevData() => _prevValue = Value;
protected override void Serialize(NetworkWriter writer, bool initialState) => writer.Write(Value);
protected override void Deserialize(NetworkReader reader, bool initialState) => Value = reader.Read<bool>();
}
}

View File

@ -1,17 +1,6 @@
using Mirror;
using System;
namespace QSB.Utility.VariableSync
namespace QSB.Utility.VariableSync
{
public class FloatVariableSyncer : BaseVariableSyncer
public class FloatVariableSyncer : BaseVariableSyncer<float>
{
private float _prevValue;
[NonSerialized]
public float Value;
protected override bool HasChanged() => Value != _prevValue;
protected override void UpdatePrevData() => _prevValue = Value;
protected override void Serialize(NetworkWriter writer, bool initialState) => writer.Write(Value);
protected override void Deserialize(NetworkReader reader, bool initialState) => Value = reader.Read<float>();
}
}

View File

@ -1,18 +1,8 @@
using Mirror;
using System;
using UnityEngine;
using UnityEngine;
namespace QSB.Utility.VariableSync
{
public class Vector3VariableSyncer : BaseVariableSyncer
public class Vector3VariableSyncer : BaseVariableSyncer<Vector3>
{
private Vector3 _prevValue;
[NonSerialized]
public Vector3 Value;
protected override bool HasChanged() => Value != _prevValue;
protected override void UpdatePrevData() => _prevValue = Value;
protected override void Serialize(NetworkWriter writer, bool initialState) => writer.Write(Value);
protected override void Deserialize(NetworkReader reader, bool initialState) => Value = reader.Read<Vector3>();
}
}