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

70 lines
1.5 KiB
C#
Raw Normal View History

2022-08-28 05:44:40 +00:00
using Mirror;
using QSB.Player;
2022-08-28 17:30:03 +00:00
using QSB.Utility;
2022-08-28 05:44:40 +00:00
using QSB.Utility.VariableSync;
using System.Collections.Generic;
using System.Linq;
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()
{
if (QSBPlayerManager.LocalPlayer.FlyingModelShip)
{
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
}
}
}