/// <summary> /// Releases sound instance and return it back to the sound pool. /// </summary> /// <param name="instance">A reference to a sound instance.</param> /// <returns> /// True, if the sound instance was successfully returned to sound pool. False otherwise. /// </returns> /// <remarks> /// <para>Once the sound instance is returned back to a sound pool, it's possible to reuse it again by calling <see cref="GrabSound()"/> or <see cref="GrabSound(string)"/>.</para> /// </remarks> public static bool ReleaseSound(SoundInstance instance) { if (shutdown) { return(false); } SoundInstanceManagerRuntime runtime = FetchSoundManager(); if (runtime == null) { return(false); } return(runtime.ReleaseSound(instance)); }
/// <summary> /// Grabs an empty sound instance from the sound pool. Used for manual playback and custom mixing logic. /// </summary> /// <returns> /// A reference to an empty sound instance. /// </returns> /// <remarks> /// <para>This method may increase the size of the sound pool causing additional memory allocations.</para> /// <para>When a sound instance is not needed anymore, use <see cref="ReleaseSound(SoundInstance)"/> to return it back to the sound pool.</para> /// </remarks> public static SoundInstance GrabSound() { if (shutdown) { return(null); } SoundInstanceManagerRuntime runtime = FetchSoundManager(); if (runtime == null) { return(null); } return(runtime.GrabSound()); }
private static SoundInstanceManagerRuntime FetchSoundManager() { if (shutdown) { return(null); } if (instanceManagerRuntime != null) { return(instanceManagerRuntime); } instanceManagerGameObject = new GameObject(); instanceManagerGameObject.name = "Sound Instance Pool"; GameObject.DontDestroyOnLoad(instanceManagerGameObject); instanceManagerRuntime = instanceManagerGameObject.AddComponent <SoundInstanceManagerRuntime>(); return(instanceManagerRuntime); }
/// <summary> /// Grabs a sound instance from the sound pool. Used for manual playback and custom mixing logic. /// </summary> /// <returns> /// A reference to a sound instance. /// </returns> /// <remarks> /// <para>If multiple banks have sounds with a matching name, primary sound bank will be checked first. /// Within a bank, the first occurrence of found sound will be used.</para> /// <para>This method may increase the size of the sound pool causing additional memory allocations.</para> /// <para>When a sound instance is not needed anymore, use <see cref="ReleaseSound(SoundInstance)"/> to return it back to the sound pool.</para> /// </remarks> public static SoundInstance GrabSound(string name) { if (shutdown) { return(null); } Sound sound = GetSound(name); if (sound == null) { return(null); } SoundInstanceManagerRuntime runtime = FetchSoundManager(); if (runtime == null) { return(null); } return(runtime.GrabSound(sound)); }