public void StopPlaying(Sound.SoundType soundType) { switch (soundType) { case Sound.SoundType.Menu: case Sound.SoundType.Battle: //go into BG Music Audio Track backgroundMusic.Stop(); break; case Sound.SoundType.Title_VO: case Sound.SoundType.Tie_VO: case Sound.SoundType.GameStart_VO: case Sound.SoundType.Explode_VO: case Sound.SoundType.Obliteration_VO: case Sound.SoundType.XWin_VO: case Sound.SoundType.OWin_VO: // go into the Boice over VO Track voiceOver.Stop(); break; default: // All other sounds go to SFX Track soundEffects.Stop(); break; } }
public void Play(Sound.SoundType t) { foreach (Sound s in sounds) { if (s.type == t) { s.Play(); } } }
/// <summary> /// Stops playing all sounds of a given sound type /// </summary> /// <param name="type">The sound type to be stopped (either SFX or Music)</param> public void StopAllSounds(Sound.SoundType type) { AudioSource[] ASList = GetComponents <AudioSource>(); for (int i = 0; i < ASList.Length; i++) { if (ASList[i].isPlaying && FindSound(ASList[i].clip.name).soundType == type) { ASList[i].Stop(); } } }
public void Play(Sound.SoundType soundType) { Sound[] s = Array.FindAll <Sound>(sounds, sound => sound.soundType == soundType); //the sound => ... is called a lambda function if (s == null || s.Length <= 0) { Debug.LogWarning($"Sound: {soundType} not found!"); return; } Sound chosenSound = s[0]; if (s.Length > 1) { //Randomize var count = s.Length; var clipToPlay = UnityEngine.Random.Range(0, count - 1); chosenSound = s[clipToPlay]; } switch (chosenSound.soundType) { case Sound.SoundType.Menu: case Sound.SoundType.Battle: case Sound.SoundType.Victory: //go into BG Music Audio Track backgroundMusic.Stop(); SetAudioToTrack(backgroundMusic, chosenSound); backgroundMusic.Play(); break; case Sound.SoundType.Title_VO: case Sound.SoundType.Tie_VO: case Sound.SoundType.GameStart_VO: case Sound.SoundType.Explode_VO: case Sound.SoundType.Obliteration_VO: case Sound.SoundType.XWin_VO: case Sound.SoundType.OWin_VO: // go into the Voice over VO Track voiceOver.Stop(); SetAudioToTrack(voiceOver, chosenSound); voiceOver.Play(); break; default: // All other sounds go to SFX Track soundEffects.Stop(); SetAudioToTrack(soundEffects, chosenSound); soundEffects.Play(); break; } }
public void ToggleMuteSound(Sound.SoundType type) { if (_state.mutedSounds.Exists(t => t == type)) { _state.mutedSounds.Remove(type); } else { _state.mutedSounds.Add(type); } Save(false); }
public void VerifySoundPrefs(Sound.SoundType type, bool isInitializing) { bool isMuted = false; if (type == Sound.SoundType.Music) { isMuted = Convert.ToBoolean(PlayerPrefs.GetInt("MusicMuted")); } if (type == Sound.SoundType.SFX) { isMuted = Convert.ToBoolean(PlayerPrefs.GetInt("SfxMuted")); } if (isInitializing) { if (isMuted) { MuteSoundByType(type); } } }
public void MuteSoundByType(Sound.SoundType type)//True for Music and False for BFX { bool isMuted = false; foreach (Sound s in instance.soundList) { if (s.soundType == type) { s.source.mute = !s.source.mute; isMuted = s.source.mute; } } //Salva em PlayerPrefs qual tipo de som foi mutado. if (type == Sound.SoundType.Music) { PlayerPrefs.SetInt("MusicMuted", Convert.ToInt32(isMuted)); } if (type == Sound.SoundType.SFX) { PlayerPrefs.SetInt("SfxMuted", Convert.ToInt32(isMuted)); } }
public bool IsMuted(Sound.SoundType type) { return(MutedSounds.Exists(t => t == type)); }