mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-18 13:23:05 +00:00
44 lines
1.1 KiB
C#
44 lines
1.1 KiB
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 => AccelerationVariableSyncer.ValueToSync.Value;
|
|
public bool IsThrusting => ThrustingVariableSyncer.ValueToSync.Value;
|
|
|
|
private Vector3 _localAcceleration;
|
|
private bool _isThrusting;
|
|
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)
|
|
{
|
|
AccelerationVariableSyncer.ValueToSync.Value = _thrusterModel.GetLocalAcceleration();
|
|
ThrustingVariableSyncer.ValueToSync.Value = _thrusterModel.IsTranslationalThrusterFiring();
|
|
}
|
|
}
|
|
}
|
|
}
|