quantum-space-buddies/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs
2021-12-07 23:01:25 -08:00

42 lines
986 B
C#

using QSB.Utility.VariableSync;
using QuantumUNET;
using UnityEngine;
namespace QSB.Animation.Player.Thrusters
{
public class JetpackAccelerationSync : QNetworkBehaviour
{
public Vector3VariableSyncer AccelerationVariableSyncer;
public BoolVariableSyncer ThrustingVariableSyncer;
public Vector3 LocalAcceleration { get; private set; }
public bool IsThrusting { get; private set; }
private ThrusterModel _thrusterModel;
public void Init(ThrusterModel model)
{
_thrusterModel = model;
AccelerationVariableSyncer.Init(() => LocalAcceleration, val => LocalAcceleration = val);
ThrustingVariableSyncer.Init(() => IsThrusting, val => IsThrusting = val);
}
public void Update()
{
if (IsLocalPlayer)
{
SyncLocalAccel();
}
}
private void SyncLocalAccel()
{
if (_thrusterModel != null)
{
LocalAcceleration = _thrusterModel.GetLocalAcceleration();
IsThrusting = _thrusterModel.IsTranslationalThrusterFiring();
}
}
}
}