quantum-space-buddies/QSB/ModelShip/ModelShipThrusterVariableSyncer.cs

78 lines
1.7 KiB
C#
Raw Normal View History

using QSB.Player;
using QSB.Player.TransformSync;
2022-08-28 05:44:40 +00:00
using QSB.Utility.VariableSync;
using UnityEngine;
namespace QSB.ModelShip;
2022-08-28 17:30:03 +00:00
public class ModelShipThrusterVariableSyncer : MonoBehaviour
2022-08-28 05:44:40 +00:00
{
public Vector3VariableSyncer AccelerationSyncer;
2022-08-28 17:46:14 +00:00
public ThrusterModel ThrusterModel { get; private set; }
2022-08-28 05:44:40 +00:00
private ThrusterAudio _thrusterAudio;
2022-08-28 05:44:40 +00:00
2022-08-28 17:30:03 +00:00
public void Init(GameObject modelShip)
2022-08-28 05:44:40 +00:00
{
2022-08-28 17:46:14 +00:00
ThrusterModel = modelShip.GetComponent<ThrusterModel>();
2022-08-28 17:30:03 +00:00
_thrusterAudio = modelShip.GetComponentInChildren<ThrusterAudio>();
2022-08-28 05:44:40 +00:00
ModelShipThrusterManager.CreateModelShipVFX(modelShip);
2022-08-28 05:44:40 +00:00
}
public void Update()
{
2023-04-26 23:08:16 +00:00
// fixes #590
if (ModelShipManager.Instance.CurrentFlyer == uint.MaxValue)
{
if (ThrusterModel)
{
AccelerationSyncer.Value = Vector3.zero;
}
return;
}
if (PlayerTransformSync.LocalInstance && QSBPlayerManager.LocalPlayer.FlyingModelShip)
2022-08-28 05:44:40 +00:00
{
GetFromShip();
return;
}
if (AccelerationSyncer.public_HasChanged())
{
if (AccelerationSyncer.Value == Vector3.zero)
{
foreach (var item in ModelShipThrusterManager.ThrusterFlameControllers)
2022-08-28 05:44:40 +00:00
{
item.OnStopTranslationalThrust();
}
_thrusterAudio.OnStopTranslationalThrust();
2022-08-28 22:23:10 +00:00
ModelShipThrusterManager.ThrusterWashController.OnStopTranslationalThrust();
2022-08-28 05:44:40 +00:00
}
else
{
foreach (var item in ModelShipThrusterManager.ThrusterFlameControllers)
2022-08-28 05:44:40 +00:00
{
item.OnStartTranslationalThrust();
}
_thrusterAudio.OnStartTranslationalThrust();
2022-08-28 22:23:10 +00:00
ModelShipThrusterManager.ThrusterWashController.OnStartTranslationalThrust();
2022-08-28 05:44:40 +00:00
}
}
}
private void GetFromShip()
{
2022-08-28 17:46:14 +00:00
if (ThrusterModel)
2022-08-28 05:44:40 +00:00
{
2022-08-28 17:46:14 +00:00
AccelerationSyncer.Value = ThrusterModel.GetLocalAcceleration();
2022-08-28 05:44:40 +00:00
}
}
}