diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index 7e661295..0765df42 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -51,7 +51,7 @@ namespace NewHorizons.Builder.Props fluidDetector._alignmentFluid = waterVolume; // Light sensors - foreach(var lightSensor in raftObject.GetComponentsInChildren()) + foreach (var lightSensor in raftObject.GetComponentsInChildren()) { lightSensor._sector.OnSectorOccupantsUpdated -= lightSensor.OnSectorOccupantsUpdated; lightSensor._sector = sector; diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 64329a21..16c0d11e 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -17,6 +17,7 @@ namespace NewHorizons.Builder.Props { private static GameObject upPrefab; private static GameObject downPrefab; + private static GameObject soundPrefab; public static void Make(GameObject go, Sector sector, PropModule.TornadoInfo info, bool hasClouds) { @@ -29,7 +30,11 @@ namespace NewHorizons.Builder.Props { downPrefab = GameObject.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/MockDownTornado").InstantiateInactive(); downPrefab.name = "Tornado_Down_Prefab"; - downPrefab.name = "Tornado_Down_Prefab"; + } + if(soundPrefab == null) + { + soundPrefab = GameObject.Find("GiantsDeep_Body/Sector_GD/Sector_GDInterior/Tornadoes_GDInterior/SouthernTornadoes/DownTornado_Pivot/DownTornado/AudioRail").InstantiateInactive(); + soundPrefab.name = "AudioRail_Prefab"; } float elevation; @@ -55,13 +60,41 @@ namespace NewHorizons.Builder.Props tornadoGO.transform.localPosition = position; tornadoGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(position.normalized)); + // Add the sound thing before changing the scale + var soundGO = soundPrefab.InstantiateInactive(); + soundGO.name = "AudioRail"; + soundGO.transform.parent = tornadoGO.transform; + soundGO.transform.localPosition = Vector3.zero; + soundGO.transform.localRotation = Quaternion.identity; + + // Height of the tornado is 10 by default + var audioRail = soundGO.GetComponent(); + audioRail.SetSector(sector); + audioRail._railPointsRoot.GetChild(0).transform.localPosition = Vector3.zero; + audioRail._railPointsRoot.GetChild(1).transform.localPosition = Vector3.up * 10; + audioRail._railPoints = new Vector3[] + { + Vector3.zero, + Vector3.up * 10 + }; + + var audioSpreadController = soundGO.GetComponentInChildren(); + audioSpreadController.SetSector(sector); + + var audioSource = audioRail._audioTransform.GetComponent(); + audioSource.playOnAwake = true; + var scale = info.height == 0 ? 1 : info.height / 10f; tornadoGO.transform.localScale = Vector3.one * scale; + // Resize the distance it can be heard from to match roughly with the size + audioSource.maxDistance = 100 * scale; + var controller = tornadoGO.GetComponent(); controller.SetSector(sector); + // Found these values by messing around in unity explorer until it looked right controller._bottomStartPos = Vector3.up * -20; controller._midStartPos = Vector3.up * 150; controller._topStartPos = Vector3.up * 300; @@ -95,6 +128,7 @@ namespace NewHorizons.Builder.Props wanderer.sector = sector; } + soundGO.SetActive(true); tornadoGO.SetActive(true); } } diff --git a/NewHorizons/Components/NHPlanetaryRaftFix.cs b/NewHorizons/Components/NHPlanetaryRaftFix.cs deleted file mode 100644 index 4e5a9408..00000000 --- a/NewHorizons/Components/NHPlanetaryRaftFix.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UnityEngine; -using Logger = NewHorizons.Utility.Logger; - -namespace NewHorizons.Components -{ - public class NHPlanetaryRaftFix : MonoBehaviour - { - private RaftController _raftController; - private RaftFluidDetector _fluidDetector; - private FluidVolume _fluidVolume; - private RaftEffectsController _effectsController; - - public void Awake() - { - _raftController = gameObject.GetComponent(); - _fluidDetector = _raftController._fluidDetector; - _fluidVolume = _fluidDetector._alignmentFluid; - _effectsController = _raftController._effectsController; - } - - public void FixedUpdate() - { - if (_raftController._raftBody.IsSuspended()) return; - if (!_raftController._playerInEffectsRange) return; - - // Normally this part won't get called because in RaftController it checks how submerged we are in the Ringworld river - // Just copy pasted it here using the actual fluid volume instead of making an ugly patch - float num = _fluidDetector.InFluidType(FluidVolume.Type.WATER) ? _fluidVolume.GetFractionSubmerged(_fluidDetector) : 0f; - bool allowMovement = num > 0.25f && num < 1f; - Logger.Log($"AllowMovement? [{allowMovement}]"); - allowMovement = true; - _effectsController.UpdateMovementAudio(allowMovement, _raftController._lightSensors); - _effectsController.UpdateGroundedAudio(_fluidDetector); - } - } -}