Add sounds to tornado

This commit is contained in:
Nick 2022-05-06 00:59:12 -04:00
parent 21ab007efd
commit b6789d6ded
3 changed files with 36 additions and 43 deletions

View File

@ -51,7 +51,7 @@ namespace NewHorizons.Builder.Props
fluidDetector._alignmentFluid = waterVolume;
// Light sensors
foreach(var lightSensor in raftObject.GetComponentsInChildren<SingleLightSensor>())
foreach (var lightSensor in raftObject.GetComponentsInChildren<SingleLightSensor>())
{
lightSensor._sector.OnSectorOccupantsUpdated -= lightSensor.OnSectorOccupantsUpdated;
lightSensor._sector = sector;

View File

@ -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>();
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>();
audioSpreadController.SetSector(sector);
var audioSource = audioRail._audioTransform.GetComponent<AudioSource>();
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<TornadoController>();
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);
}
}

View File

@ -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<RaftController>();
_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);
}
}
}