Skip to main content

SoundSource

A class in Root.Township, the global namespace.

Plays a sound effect on (or at) its object, optionally when enabled, and stops it when disabled. Does nothing when headless.

Constructors​

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

Fields​

MemberWhat it is
protected AudioControl audioControlHandle to the playing sound.
8 private and internal fields
MemberWhat it is
private bool isStaticWhen set, plays at a fixed position instead of following the object.
private bool isStoppedSet by Stop so a pending play on enable is skipped.
private SoundEffectSet playSound set to play. Filled from the old soundEffect value if empty.
private bool playOnEnableBacking field for PlayOnEnable.
private bool separateStopEffectWhen set, Stop plays the stop sound instead of stopping the playing one.
private SoundEffect soundEffectOld sound effect value, kept for migration to play.
private SoundEffectSet stopSound set played on stop when separateStopEffect is set.
private SoundEffect stopEffectOld stop sound value, kept for migration to stop.

Properties​

MemberWhat it is
bool IsPlaying { get; private set; }True between Play and Stop.
bool PlayOnEnable { get; }Whether it plays when enabled.

Events​

MemberWhat it is
event SoundSourceEvent OnPlayFired when the sound starts.
event SoundSourceEvent OnStopFired when the sound stops.

Methods​

MemberWhat it is
virtual void Play()Plays the sound on the object, or at its position if static, unless a sound from this source is still playing.
void Stop()Stops the sound, or plays the separate stop effect if one is set.
protected virtual void OnDisable()Stops the sound.
protected virtual void OnEnable()If PlayOnEnable, plays once the audio manager and Wwise are ready.
1 private and internal method
MemberWhat it is
private IEnumerator StartAfterInitialized() (iterator)Waits a frame, and until the audio manager and Wwise are ready, then plays unless stopped meanwhile.

Used in​

Members of other types that take, return or hold a SoundSource: