quantum-space-buddies/QSB/Animation/Player/Thrusters/JetpackAccelerationSync.cs

44 lines
1.1 KiB
C#
Raw Normal View History

2021-11-26 19:33:56 +00:00
using QSB.Utility.VariableSync;
using QuantumUNET;
2021-05-07 13:58:37 +00:00
using UnityEngine;
namespace QSB.Animation.Player.Thrusters
{
public class JetpackAccelerationSync : QNetworkBehaviour
{
2021-11-26 19:33:56 +00:00
public Vector3VariableSyncer AccelerationVariableSyncer;
public BoolVariableSyncer ThrustingVariableSyncer;
2021-11-26 22:31:52 +00:00
public Vector3 LocalAcceleration => AccelerationVariableSyncer.ValueToSync.Value;
public bool IsThrusting => ThrustingVariableSyncer.ValueToSync.Value;
2021-11-26 19:33:56 +00:00
2021-05-07 13:58:37 +00:00
private Vector3 _localAcceleration;
2021-05-07 18:17:09 +00:00
private bool _isThrusting;
2021-05-07 13:58:37 +00:00
private ThrusterModel _thrusterModel;
2021-06-19 10:26:05 +00:00
public void Init(ThrusterModel model)
2021-11-26 19:33:56 +00:00
{
_thrusterModel = model;
2021-11-26 22:31:52 +00:00
AccelerationVariableSyncer.Init(() => _localAcceleration, val => _localAcceleration = val);
ThrustingVariableSyncer.Init(() => _isThrusting, val => _isThrusting = val);
2021-11-26 19:33:56 +00:00
}
2021-05-07 13:58:37 +00:00
public void Update()
{
if (IsLocalPlayer)
{
SyncLocalAccel();
}
}
private void SyncLocalAccel()
{
if (_thrusterModel != null)
{
2021-11-26 22:31:52 +00:00
AccelerationVariableSyncer.ValueToSync.Value = _thrusterModel.GetLocalAcceleration();
ThrustingVariableSyncer.ValueToSync.Value = _thrusterModel.IsTranslationalThrusterFiring();
2021-05-07 13:58:37 +00:00
}
}
}
}