Cloak Entry Audio

This commit is contained in:
Noah Pilarski 2022-05-27 06:05:12 -04:00
parent 855a4caa2f
commit 0fe3ed06ac
5 changed files with 48 additions and 2 deletions

View File

@ -1,14 +1,30 @@
using NewHorizons.Components; using NewHorizons.Components;
using NewHorizons.External.Modules; using NewHorizons.External.Modules;
using NewHorizons.Utility; using NewHorizons.Utility;
using OWML.Common;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
public static class CloakBuilder public static class CloakBuilder
{ {
public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, CloakModule module, bool keepReferenceFrame) public static void Make(GameObject planetGO, Sector sector, OWRigidbody OWRB, CloakModule module, bool keepReferenceFrame, IModBehaviour mod)
{ {
var radius = module.radius; var radius = module.radius;
AudioClip clip = null;
if (module.audioClip != null) clip = SearchUtilities.FindResourceOfTypeAndName<AudioClip>(module.audioClip);
else if (module.audioFilePath != null)
{
try
{
clip = AudioUtilities.LoadAudio(mod.ModHelper.Manifest.ModFolderPath + "/" + module.audioFilePath);
}
catch (System.Exception e)
{
Utility.Logger.LogError($"Couldn't load audio file {module.audioFilePath} : {e.Message}");
}
}
var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP"); var cloak = SearchUtilities.Find("RingWorld_Body/CloakingField_IP");
var newCloak = GameObject.Instantiate(cloak, sector?.transform ?? planetGO.transform); var newCloak = GameObject.Instantiate(cloak, sector?.transform ?? planetGO.transform);
@ -31,6 +47,14 @@ namespace NewHorizons.Builder.Body
var cloakSectorController = newCloak.AddComponent<CloakSectorController>(); var cloakSectorController = newCloak.AddComponent<CloakSectorController>();
cloakSectorController.Init(newCloak.GetComponent<CloakFieldController>(), planetGO); cloakSectorController.Init(newCloak.GetComponent<CloakFieldController>(), planetGO);
var cloakAudioSource = newCloak.GetComponentInChildren<OWAudioSource>();
cloakAudioSource._audioSource = cloakAudioSource.GetComponent<AudioSource>();
cloakAudioSource._audioLibraryClip = AudioType.None;
cloakAudioSource._clipArrayIndex = 0;
cloakAudioSource._clipArrayLength = 0;
cloakAudioSource._clipSelectionOnPlay = OWAudioSource.ClipSelectionOnPlay.MANUAL;
cloakAudioSource.clip = clip;
newCloak.SetActive(true); newCloak.SetActive(true);
cloakFieldController.enabled = true; cloakFieldController.enabled = true;
@ -38,6 +62,7 @@ namespace NewHorizons.Builder.Body
// To cloak from the start // To cloak from the start
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(cloakSectorController.OnPlayerExit); Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(cloakSectorController.OnPlayerExit);
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(clip != null ? cloakSectorController.TurnOnMusic : cloakSectorController.TurnOffMusic);
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(keepReferenceFrame ? cloakSectorController.EnableReferenceFrameVolume : cloakSectorController.DisableReferenceFrameVolume); Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(keepReferenceFrame ? cloakSectorController.EnableReferenceFrameVolume : cloakSectorController.DisableReferenceFrameVolume);
} }
} }

View File

@ -80,5 +80,8 @@ namespace NewHorizons.Components
public void SetReferenceFrameVolumeActive(bool active) => _cloak._referenceFrameVolume.gameObject.SetActive(active); public void SetReferenceFrameVolumeActive(bool active) => _cloak._referenceFrameVolume.gameObject.SetActive(active);
public void EnableReferenceFrameVolume() => SetReferenceFrameVolumeActive(true); public void EnableReferenceFrameVolume() => SetReferenceFrameVolumeActive(true);
public void DisableReferenceFrameVolume() => SetReferenceFrameVolumeActive(false); public void DisableReferenceFrameVolume() => SetReferenceFrameVolumeActive(false);
public void TurnOnMusic() => _cloak._hasTriggeredMusic = false;
public void TurnOffMusic() => _cloak._hasTriggeredMusic = true;
} }
} }

View File

@ -15,5 +15,15 @@ namespace NewHorizons.External.Modules
/// don't want a cloak, leave this as 0. /// don't want a cloak, leave this as 0.
/// </summary> /// </summary>
public float radius; public float radius;
/// <summary>
/// Name of an existing AudioClip in the game that will play when entering the cloaking field.
/// </summary>
public string audioClip;
/// <summary>
/// Relative filepath to the .wav file to use as the audio. Mutually exclusive with audioClip.
/// </summary>
public string audioFilePath;
} }
} }

View File

@ -482,7 +482,7 @@ namespace NewHorizons.Handlers
// Has to go last probably // Has to go last probably
if (body.Config.Cloak != null && body.Config.Cloak.radius != 0f) if (body.Config.Cloak != null && body.Config.Cloak.radius != 0f)
{ {
CloakBuilder.Make(go, sector, rb, body.Config.Cloak, body.Config.Base.hasReferenceFrame); CloakBuilder.Make(go, sector, rb, body.Config.Cloak, body.Config.Base.hasReferenceFrame, body.Mod);
} }
return go; return go;

View File

@ -297,6 +297,14 @@
"type": "number", "type": "number",
"description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you\ndon't want a cloak, leave this as 0.", "description": "Radius of the cloaking field around the planet. It's a bit finicky so experiment with different values. If you\ndon't want a cloak, leave this as 0.",
"format": "float" "format": "float"
},
"audioClip": {
"type": "string",
"description": "Name of an existing AudioClip in the game that will play when entering the cloaking field."
},
"audioFilePath": {
"type": "string",
"description": "Relative filepath to the .wav file to use as the audio. Mutually exclusive with audioClip."
} }
} }
}, },