Refactor ModelShip wash to better resemble Ship

This commit is contained in:
Nick 2022-08-28 20:25:37 -04:00
parent 4a4daedc80
commit dc128d4e52
5 changed files with 35 additions and 17 deletions

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.ModelShip;
public static class ModelShipThrusterManager
{
public static readonly List<ThrusterFlameController> ThrusterFlameControllers = new();
public static ThrusterWashController ThrusterWashController { get; private set; }
public static void CreateModelShipVFX(GameObject modelShip)
{
ThrusterFlameControllers.Clear();
foreach (var item in modelShip.GetComponentsInChildren<ThrusterFlameController>())
{
ThrusterFlameControllers.Add(item);
}
ThrusterWashController = modelShip.GetComponentInChildren<ThrusterWashController>();
}
}

View File

@ -14,21 +14,14 @@ public class ModelShipThrusterVariableSyncer : MonoBehaviour
public ThrusterModel ThrusterModel { get; private set; }
private ThrusterAudio _thrusterAudio;
public List<ThrusterFlameController> ThrusterFlameControllers = new();
public ThrusterWashController ThrusterWashController { get; private set; }
public void Init(GameObject modelShip)
{
ThrusterModel = modelShip.GetComponent<ThrusterModel>();
_thrusterAudio = modelShip.GetComponentInChildren<ThrusterAudio>();
ThrusterFlameControllers.Clear();
foreach (var item in modelShip.GetComponentsInChildren<ThrusterFlameController>())
{
ThrusterFlameControllers.Add(item);
}
ThrusterWashController = modelShip.GetComponentInChildren<ThrusterWashController>();
ModelShipThrusterManager.CreateModelShipVFX(modelShip);
}
public void Update()
@ -43,25 +36,25 @@ public class ModelShipThrusterVariableSyncer : MonoBehaviour
{
if (AccelerationSyncer.Value == Vector3.zero)
{
foreach (var item in ThrusterFlameControllers)
foreach (var item in ModelShipThrusterManager.ThrusterFlameControllers)
{
item.OnStopTranslationalThrust();
}
_thrusterAudio.OnStopTranslationalThrust();
ThrusterWashController.OnStopTranslationalThrust();
ModelShipThrusterManager.ThrusterWashController.OnStopTranslationalThrust();
}
else
{
foreach (var item in ThrusterFlameControllers)
foreach (var item in ModelShipThrusterManager.ThrusterFlameControllers)
{
item.OnStartTranslationalThrust();
}
_thrusterAudio.OnStartTranslationalThrust();
ThrusterWashController.OnStartTranslationalThrust();
ModelShipThrusterManager.ThrusterWashController.OnStartTranslationalThrust();
}
}
}

View File

@ -18,7 +18,7 @@ internal class ModelShipThrusterAudioPatches : QSBPatch
[HarmonyPatch(typeof(ThrusterModel), nameof(ThrusterModel.GetThrustFraction))]
public static bool ThrusterModel_GetThrustFraction(ThrusterModel __instance, ref float __result)
{
if (__instance == ModelShipTransformSync.LocalInstance.ThrusterVariableSyncer.ThrusterModel && !QSBPlayerManager.LocalPlayer.FlyingModelShip)
if (__instance == ModelShipTransformSync.LocalInstance?.ThrusterVariableSyncer?.ThrusterModel && !QSBPlayerManager.LocalPlayer.FlyingModelShip)
{
__result = ModelShipTransformSync.LocalInstance.ThrusterVariableSyncer.AccelerationSyncer.Value.magnitude / __instance._maxTranslationalThrust;
return false;

View File

@ -17,9 +17,9 @@ internal class ModelShipThrusterPatches : QSBPatch
{
var modelShipThrusters = ModelShipTransformSync.LocalInstance?.ThrusterVariableSyncer;
if (modelShipThrusters == null) return true;
if (ModelShipThrusterManager.ThrusterFlameControllers == null) return true;
if (modelShipThrusters.ThrusterFlameControllers.Contains(__instance) && !QSBPlayerManager.LocalPlayer.FlyingModelShip)
if (ModelShipThrusterManager.ThrusterFlameControllers.Contains(__instance) && !QSBPlayerManager.LocalPlayer.FlyingModelShip)
{
if(__instance._thrusterModel.IsThrusterBankEnabled(OWUtilities.GetShipThrusterBank(__instance._thruster)))
{

View File

@ -44,7 +44,7 @@ internal class ShipFlameWashPatches : QSBPatch
public static bool Update(ThrusterWashController __instance)
{
var isShip = ShipThrusterManager.ShipWashController == __instance;
var isModelShip = ModelShipTransformSync.LocalInstance.ThrusterVariableSyncer.ThrusterWashController == __instance;
var isModelShip = ModelShipThrusterManager.ThrusterWashController == __instance;
if (!isShip && !isModelShip)
{