private static void HandleOnComplete(AudioSource channel, AudioConfig audioConfig) { // Remove the reference audioConfig.RemoveOccupiedChannel(channel); // Check the callbacks var callback = audioConfig.Callbacks.GetAndRemove(channel); if (callback != null) { callback.Invoke(); } // Reset the channel AudioSystem.Instance.ResetChannel(channel); }
/// <summary> /// Stop the audio /// </summary> /// <param name="audioConfig">The target audio config</param> /// <param name="parent">The target parent transform</param> /// <param name="removeOnCompleteCallback">Remove the callback</param> /// <returns>False if the channel is invalid (not from this Audio System) or already stopped</returns> public static void Stop(this AudioConfig audioConfig, Transform parent = null, bool removeOnCompleteCallback = false) { var channels = audioConfig.GetChannels(parent); // Use for loop here because the collection will be modified during the iteration for (var i = channels.Count - 1; i >= 0; --i) { var channel = channels[i]; AudioSystem.Instance.Stop(channel, true); audioConfig.RemoveOccupiedChannel(channel); var callback = audioConfig.Callbacks.GetAndRemove(channel); if (callback != null && !removeOnCompleteCallback) { callback.Invoke(); } } }