mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Implement AudioVolume
This commit is contained in:
parent
4f1fc602bc
commit
0952d90ffa
45
NewHorizons/Builder/Props/AudioVolumeBuilder.cs
Normal file
45
NewHorizons/Builder/Props/AudioVolumeBuilder.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using NewHorizons.External.Modules;
|
||||
using NewHorizons.Utility;
|
||||
using OWML.Common;
|
||||
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.Builder.Props
|
||||
{
|
||||
public static class AudioVolumeBuilder
|
||||
{
|
||||
public static AudioVolume Make(GameObject planetGO, Sector sector, PropModule.AudioVolumeInfo info, IModBehaviour mod)
|
||||
{
|
||||
var go = new GameObject("AudioVolume");
|
||||
go.SetActive(false);
|
||||
|
||||
go.transform.parent = sector?.transform ?? planetGO.transform;
|
||||
go.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero);
|
||||
go.layer = LayerMask.NameToLayer("AdvancedEffectVolume");
|
||||
|
||||
var audioSource = go.AddComponent<AudioSource>();
|
||||
|
||||
var owAudioSource = go.AddComponent<OWAudioSource>();
|
||||
owAudioSource._audioSource = audioSource;
|
||||
owAudioSource.loop = true;
|
||||
AudioUtilities.SetAudioClip(owAudioSource, info.audio, mod);
|
||||
|
||||
var audioVolume = go.AddComponent<AudioVolume>();
|
||||
|
||||
var shape = go.AddComponent<SphereShape>();
|
||||
shape.radius = info.radius;
|
||||
|
||||
var owTriggerVolume = go.AddComponent<OWTriggerVolume>();
|
||||
owTriggerVolume._shape = shape;
|
||||
|
||||
go.SetActive(true);
|
||||
|
||||
return audioVolume;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,6 +198,13 @@ namespace NewHorizons.Builder.Props
|
||||
{
|
||||
SingularityBuilder.Make(go, sector, go.GetComponent<OWRigidbody>(), config, singularity);
|
||||
}
|
||||
}
|
||||
if (config.Props.audioVolumes != null)
|
||||
{
|
||||
foreach (var audioVolume in config.Props.audioVolumes)
|
||||
{
|
||||
AudioVolumeBuilder.Make(go, sector, audioVolume, mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
NewHorizons/External/Modules/PropModule.cs
vendored
24
NewHorizons/External/Modules/PropModule.cs
vendored
@ -83,6 +83,11 @@ namespace NewHorizons.External.Modules
|
||||
/// </summary>
|
||||
public SingularityModule[] singularities;
|
||||
|
||||
/// <summary>
|
||||
/// Add audio volumes to this planet
|
||||
/// </summary>
|
||||
public AudioVolumeInfo[] audioVolumes;
|
||||
|
||||
[JsonObject]
|
||||
public class ScatterInfo
|
||||
{
|
||||
@ -713,5 +718,24 @@ namespace NewHorizons.External.Modules
|
||||
/// </summary>
|
||||
[DefaultValue(1f)] public float probability = 1f;
|
||||
}
|
||||
|
||||
[JsonObject]
|
||||
public class AudioVolumeInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// The location of this audio volume. Optional (will default to 0,0,0).
|
||||
/// </summary>
|
||||
public MVector3 position;
|
||||
|
||||
/// <summary>
|
||||
/// The radius of this audio volume
|
||||
/// </summary>
|
||||
public float radius;
|
||||
|
||||
/// <summary>
|
||||
/// The radius of this audio volume
|
||||
/// </summary>
|
||||
public string audio;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user