/// <summary> /// Pauses the current music / sound for the sent mixer. /// </summary> /// <param name="player"></param> public void PauseAudio(MixerPlayer player) { foreach (Mixer m in mixers) { if (m.player == player) { m.Pause(); } } }
/// <summary> /// Resumes the current music / sound for the sent mixer. /// </summary> /// <param name="player"></param> public void ResumeAudio(MixerPlayer player) { foreach (Mixer m in mixers) { if (m.player == player) { m.Resume(); } } }
/// <summary> /// Unmutes the sent mixer. /// </summary> /// <param name="player"></param> public void UnMute(MixerPlayer player) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.UnMute(); } } }
/// <summary> /// Will cancel or close any existing sound based on the shortest time left in one of the mixers. Will also adjust the mixer to the desired pitch. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> /// <param name="pitch"></param> public void PlaySoundOverride(MixerPlayer player, AudioClip sound, float pitch) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.OverridePlaySound(sound, pitch); } } }
/// <summary> /// Plays a Combined sound into one of the mixer groups, will try to find a group that is using the closest pitch. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> /// <param name="pitch"></param> public void PlaySoundCombined(MixerPlayer player, AudioClip sound, float pitch) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.PlayCombinedSound(sound, pitch); } } }
/// <summary> /// Plays the sound in an available mixer with the desired pitch. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> /// <param name="pitch"></param> public void PlaySound(MixerPlayer player, AudioClip sound, float pitch, bool enableLooping) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.PlaySound(sound, pitch, enableLooping); } } }
/// <summary> /// Adds an outside audio source to the desired player to provide control over that source. /// </summary> /// <param name="player"></param> /// <param name="source"></param> public void AddAudioSourceToMixer(MixerPlayer player, AudioSource source) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.AddSource(source); return; } } }
/// <summary> /// Returns the mixer that is associate with that player. /// </summary> /// <param name="player"></param> /// <returns></returns> public Mixer GetMixer(MixerPlayer player) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { return(m); } } return(null); }
/// <summary> /// Stops all other mixer channels sounds over the sent time and plays the AudioClip at the designated pitch and allows looping. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> /// <param name="pitch"></param> /// <param name="seconds"></param> public void TransitionSound(MixerPlayer player, AudioClip sound, float pitch, float seconds, bool enableLooping) { foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { AudioSource[] sources = m.MuteAllOverlayPlaySound(sound, pitch, enableLooping); foreach (AudioSource source in sources) { StartCoroutine(MuteSourceOverTime(source, seconds)); } } } }
/// <summary> /// Adjusts the volume of the sent mixer. /// </summary> /// <param name="player"></param> /// <param name="volumeLevel"></param> public void AdjustVolume(MixerPlayer player, float volumeLevel) { if (EnumFlags <MixerPlayer> .HasAllFlags(player, MixerPlayer.Dialog, MixerPlayer.Explosions, MixerPlayer.Instantiations, MixerPlayer.Interactions, MixerPlayer.Movement, MixerPlayer.Music)) { AdjustMasterVolume(volumeLevel); return; } foreach (Mixer m in mixers) { if (EnumFlags <MixerPlayer> .HasFlag(m.player, player)) { m.AdjustVolume(volumeLevel); } } }
/// <summary> /// Plays a sound a designated location by creating a new audioSource, can be automatically added to a player for additional control. /// </summary> /// <param name="sound"></param> /// <param name="location"></param> public void PlaySoundAtLocation(MixerPlayer player, AudioClip sound, Vector3 location) { GameObject obj = new GameObject(); obj = Instantiate(obj, location, Quaternion.identity); AudioSource source = obj.AddComponent <AudioSource>(); source.clip = sound; Mixer m = GetMixer(player); if (m != null) { AudioMixerGroup group = m.GetMixerGroup(); if (group != null) { source.outputAudioMixerGroup = group; } } source.Play(); }
/// <summary> /// Stops all other mixer channel's sounds over the sent time and plays the AudioClip at the designated pitch. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> /// <param name="pitch"></param> /// <param name="seconds"></param> public void TransitionSound(MixerPlayer player, AudioClip sound, float pitch, float seconds) { TransitionSound(player, sound, pitch, seconds, false); }
/// <summary> /// Plays the sound in an available mixer. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> public void PlaySound(MixerPlayer player, AudioClip sound, float pitch) { PlaySound(player, sound, pitch, false); }
/// <summary> /// Plays the sound in an available mixer. /// </summary> /// <param name="player"></param> /// <param name="sound"></param> public void PlaySound(MixerPlayer player, AudioClip sound) { PlaySound(player, sound, 1, false); }
public Mixer(MixerPlayer player, AudioMixer mixer, string groupPrefix) { this.player = player; this.mixer = mixer; this.groupPrefix = groupPrefix; }