Sound Manager
Description
Sound Manager is the entry point for sound playback and sound instance management. It does not require to create any additional game objects in order to use it.
All currently playing sounds are represented by the Sound Instance class. There are two types of them:
- One-shot sound instances — they are played and automatically managed by the sound manager. When playing a sound, Sound Manager will look up for available sound instance and use it for playback.
- Manual sound instances — the sound manager allows getting a reference to a sound instance from the sound pool for manual playback.
One-shot sound instances
Call these methods to play a one-shot sound:
Use default volume, pitch and delay values from the sound:
Stem.ID soundId; // Assume it's filled earlier in the code or was set by the Stem.SoundID attribute
Vector3 soundPosition = new Vector3(100.0f, 0.0f, 0.0f);
Stem.SoundManager.Play(soundID);
Stem.SoundManager.Play3D(soundID, soundPosition);
Or override them:
Stem.ID soundId; // Assume it's filled earlier in the code or was set by the Stem.SoundID attribute
Vector3 soundPosition = new Vector3(100.0f, 0.0f, 0.0f);
float newVolume = 0.5f;
float newPitch = 0.9f;
float newDelay = 0.1f;
Stem.SoundManager.Play(soundID, newVolume, newPitch, newDelay);
Stem.SoundManager.Play3D(soundID, soundPosition, newVolume, newPitch, newDelay);
Manual sound instances
Call Stem.SoundManager.GrabSound to get a reference to a sound instance from the sound pool:
Stem.ID soundId; // Assume it's filled earlier in the code or was set by the Stem.SoundID attribute
Stem.SoundInstance soundInstance = Stem.SoundManager.GrabSound(soundID);
Call Stem.SoundInstance.Play or Stem.SoundInstance.Play3D to manuall play a sound. Use default volume, pitch and delay values from the sound:
Vector3 soundPosition = new Vector3(100.0f, 0.0f, 0.0f);
soundInstance.Play();
soundInstance.Play3D(soundPosition);
Or override them:
Vector3 soundPosition = new Vector3(100.0f, 0.0f, 0.0f);
float newVolume = 0.5f;
float newPitch = 0.9f;
float newDelay = 0.1f;
soundInstance.Play(newVolume, newPitch, newDelay);
soundInstance.Play3D(soundPosition, newVolume, newPitch, newDelay);
Once the sound instance is not needed anymore, call Stem.SoundManager.ReleaseSound to return it back to the sound pool:
Stem.SoundManager.ReleaseSound(soundInstance);
Playback controls
Call these methods to change playback state of all sound instances:
// Stop all playing sound instances (including manual sound instances)
Stem.SoundManager.Pause();
// Resume all playing sound instances (including manual sound instances)
Stem.SoundManager.UnPause();
// Stop all playing sound instances (including manual sound instances)
Stem.SoundManager.Stop();