RiverAudio
A class in Root.Township, Alta.Forests.
Client: moves an ambience audio source to the nearest point on the river to the local player's head and fades its volume by river size and distance.
- Listed in World generation
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
RiverAudio() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
float minDistance | Scales the falloff curve; the volume factor is capped at 1. |
9 private and internal fields
| Member | What it is |
|---|---|
private AmbienceAudio audioSource | The ambience audio this component positions and fades. |
private RiverPath lastPath | The river path the sound was on last frame, checked first next frame. |
private float maxSize | River volume that counts as full loudness. |
private float moveSpeed | How fast the source slides towards the river while silent; when audible it snaps. |
private PlayerController player | The local player being tracked. |
private RiverGenerator river | The river generator whose overground paths are used. |
private AnimationCurve rolloffCurve | An animation curve field; this code doesn't read it. |
private float rolloffScale | How quickly volume drops with distance in Falloff. |
private float volumeSpeed | How fast the volume eases towards its target, per second. |
Methods
6 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Mutes the audio, disables the component and waits for the local player to be set. |
private void Disable(NetworkEntity entity, bool isUnload) | Mutes and disables the component when the local player's entity is destroyed by the scene. |
private float Falloff(float input) | Turns a distance into a volume factor using minDistance and rolloffScale. |
private void LocalPlayerSet(PlayerController player) | Stores the new local player, hooks its destruction and enables the component. |
private void OnDestroy() | Unhooks the local player events. |
private void Update() | Finds the loudest nearby river path, moves the source to its closest point and eases the volume. Mutes when far outside the forest. |