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

77 lines
1.6 KiB
C#
Raw Normal View History

2022-05-19 13:34:49 +00:00
using Mirror;
using QSB.Player;
using QSB.Player.TransformSync;
2022-05-19 13:34:49 +00:00
using QSB.Utility.VariableSync;
using UnityEngine;
namespace QSB.ShipSync;
public class ShipThrusterVariableSyncer : NetworkBehaviour
{
public Vector3VariableSyncer AccelerationSyncer;
private ShipThrusterModel _thrusterModel;
2022-08-28 04:12:53 +00:00
private ShipThrusterAudio _thrusterAudio;
2022-05-19 13:34:49 +00:00
public void Init()
{
_thrusterModel = Locator.GetShipBody().GetComponent<ShipThrusterModel>();
2022-08-28 04:12:53 +00:00
_thrusterAudio = Locator.GetShipBody().GetComponentInChildren<ShipThrusterAudio>();
2022-05-19 13:34:49 +00:00
}
public void Update()
{
2023-01-13 22:13:11 +00:00
// bug : this doesn't account for autopilot
2023-04-26 23:08:16 +00:00
// fixes #590
2023-01-13 22:13:11 +00:00
if (ShipManager.Instance.CurrentFlyer == uint.MaxValue)
{
if (_thrusterModel)
{
AccelerationSyncer.Value = Vector3.zero;
}
return;
}
if (PlayerTransformSync.LocalInstance && QSBPlayerManager.LocalPlayer.FlyingShip)
2022-05-19 13:34:49 +00:00
{
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
2022-08-28 04:12:53 +00:00
_thrusterAudio.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
2022-08-28 04:12:53 +00:00
_thrusterAudio.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
}