using OWML.Utils; using QSB.Player; using QSB.Utility; using UnityEngine; namespace QSB.Animation.Player.Thrusters { internal class ThrusterManager { public static void CreateRemotePlayerVFX(PlayerInfo player) { var localPlayerVfx = GameObject.Find("PlayerVFX"); var newVfx = localPlayerVfx.InstantiateInactive(); ReplaceParticleSystems(newVfx, player); CreatePlayerParticlesController(newVfx); CreateThrusterParticlesBehaviour(newVfx, player); CreateThrusterWashController(newVfx.transform.Find("ThrusterWash").gameObject, player); CreateThrusterFlameController(newVfx, player); newVfx.transform.parent = player.Body.transform; // Body isnt the actualy player body... it's the model... ;( newVfx.transform.localPosition = new Vector3(0, 10.24412f, 2.268939f); newVfx.transform.rotation = Quaternion.Euler(1.5f, 0, 0); newVfx.transform.localScale = new Vector3(10, 10, 10); // Deleted objects take 1 update to actually be deleted QSBCore.UnityEvents.FireOnNextUpdate(() => newVfx.SetActive(true)); } private static void ReplaceParticleSystems(GameObject root, PlayerInfo player) { var existingSystems = root.GetComponentsInChildren(true); foreach (var system in existingSystems) { var gameObject = system.gameObject; Object.Destroy(system); var newSys = gameObject.AddComponent(); newSys.Init(player); } } private static void CreateThrusterFlameController(GameObject root, PlayerInfo player) { var existingControllers = root.GetComponentsInChildren(true); foreach (var controller in existingControllers) { var gameObject = controller.gameObject; var oldThruster = controller.GetValue("_thruster"); var oldLight = controller.GetValue("_light"); var oldAnimCurve = controller.GetValue("_scaleByThrust"); var oldScaleSpring = controller.GetValue("_scaleSpring"); var oldScalar = controller.GetValue("_belowMaxThrustScalar"); var oldBase = controller.GetValue("_baseLightRadius"); Object.Destroy(controller); var newObj = gameObject.AddComponent(); newObj.InitFromOld(oldThruster, oldLight, oldAnimCurve, oldScaleSpring, oldScalar, oldBase, player); } } private static void CreatePlayerParticlesController(GameObject root) => // TODO : Implement this. (Footsteps / Landing) Object.Destroy(root.GetComponent()); private static void CreateThrusterParticlesBehaviour(GameObject root, PlayerInfo player) { var existingBehaviours = root.GetComponentsInChildren(true); foreach (var behaviour in existingBehaviours) { // TODO : Implement this. (Bubbles for underwater thrusters) Object.Destroy(behaviour); } } private static void CreateThrusterWashController(GameObject root, PlayerInfo player) { var old = root.GetComponent(); var oldDistanceScale = old.GetValue("_emissionDistanceScale"); var oldThrusterScale = old.GetValue("_emissionThrusterScale"); var defaultParticleSystem = old.GetValue("_defaultParticleSystem"); Object.Destroy(old); var newObj = root.AddComponent(); newObj.InitFromOld(oldDistanceScale, oldThrusterScale, defaultParticleSystem, player); } } }