Skip to main content

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.

Constructors​

MemberWhat it is
RiverAudio()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
float minDistanceScales the falloff curve; the volume factor is capped at 1.
9 private and internal fields
MemberWhat it is
private AmbienceAudio audioSourceThe ambience audio this component positions and fades.
private RiverPath lastPathThe river path the sound was on last frame, checked first next frame.
private float maxSizeRiver volume that counts as full loudness.
private float moveSpeedHow fast the source slides towards the river while silent; when audible it snaps.
private PlayerController playerThe local player being tracked.
private RiverGenerator riverThe river generator whose overground paths are used.
private AnimationCurve rolloffCurveAn animation curve field; this code doesn't read it.
private float rolloffScaleHow quickly volume drops with distance in Falloff.
private float volumeSpeedHow fast the volume eases towards its target, per second.

Methods​

6 private and internal methods
MemberWhat 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.