quantum-space-buddies/QSB/ShipSync/ShipThrusterVariableSyncer.cs

58 lines
1.1 KiB
C#
Raw Normal View History

2022-05-19 13:34:49 +00:00
using Mirror;
using QSB.Player;
using QSB.Utility.VariableSync;
using UnityEngine;
namespace QSB.ShipSync;
public class ShipThrusterVariableSyncer : NetworkBehaviour
{
public Vector3VariableSyncer AccelerationSyncer;
private ShipThrusterModel _thrusterModel;
public void Init()
{
_thrusterModel = Locator.GetShipBody().GetComponent<ShipThrusterModel>();
}
public void Update()
{
if (QSBPlayerManager.LocalPlayer.FlyingShip)
{
GetFromShip();
return;
}
2022-06-07 18:40:06 +00:00
if (AccelerationSyncer.public_HasChanged())
2022-05-19 13:34:49 +00:00
{
if (AccelerationSyncer.Value == Vector3.zero)
{
foreach (var item in ShipThrusterManager.ShipFlameControllers)
{
item.OnStopTranslationalThrust();
}
2022-05-19 14:13:22 +00:00
ShipThrusterManager.ShipWashController.OnStopTranslationalThrust();
2022-05-19 13:34:49 +00:00
}
else
{
foreach (var item in ShipThrusterManager.ShipFlameControllers)
{
item.OnStartTranslationalThrust();
}
2022-05-19 14:13:22 +00:00
ShipThrusterManager.ShipWashController.OnStartTranslationalThrust();
2022-05-19 13:34:49 +00:00
}
}
}
2022-06-07 18:08:09 +00:00
private void GetFromShip()
{
if (_thrusterModel)
{
AccelerationSyncer.Value = _thrusterModel.GetLocalAcceleration();
}
}
2022-05-19 13:34:49 +00:00
}