Show / Hide Table of Contents

Bank Management

Description

By default, Stem automatically manages all banks assets. In case of a manually created bank, it's required to register it in the corresponding manager for proper use.

Creating banks at runtime

As banks are inherited from ScriptableObject, use ScriptableObject.CreateInstance to create a bank instance. Note that there'll be no .asset file created in the project.

Stem.SoundBank bank = ScriptableObject.CreateInstance<Stem.SoundBank>();
// add bank content here
Stem.MusicBank bank = ScriptableObject.CreateInstance<Stem.MusicBank>();
// add bank content here

Registration

Call Stem.SoundManager.RegisterBank or Stem.MusicManager.RegisterBank to register a bank in the corresponding manager. If the return value is true, the bank was successfully registered and is ready to use.

Stem will automatically create all required runtime data like game objects, audio sources, etc.

if (Stem.SoundManager.RegisterBank(bank))
{
	// it's ready to use
}
if (Stem.MusicManager.RegisterBank(bank))
{
	// it's ready to use
}

Bank collection

Use Stem.SoundManager.Banks or Stem.MusicManager.Banks property to get a read-only collection of registered banks.

int totalSounds = 0;
int totalSoundBuses = 0;
foreach (Stem.SoundBank bank in Stem.SoundManager.Banks)
{
	totalSounds += bank.Sounds.Count;
	totalSoundBuses += bank.Buses.Count;
}
int totalPlaylists = 0;
int totalMusicPlayers = 0;
foreach (Stem.MusicBank bank in Stem.MusicManager.Banks)
{
	totalPlaylists += bank.Playlists.Count;
	totalMusicPlayers += bank.Players.Count;
}

Deregistration

Call Stem.SoundManager.DeregisterBank or Stem.MusicManager.DeregisterBank to deregister a bank in the corresponding manager so it won't be in the search.

Stem will automatically destroy all bank's runtime data like game objects, audio sources, etc.

Stem.SoundManager.DeregisterBank(bank);
Stem.MusicManager.DeregisterBank(bank);
  • Improve this Doc
Back to top Generated by DocFX