private void FadeSound( SoundContainer soundContainer, bool isIn = false, float volumeStep = 0, float targetVolume = 0, float targetTime = 0.1f) { List <SoundContainer> list = new List <SoundContainer>(); list.Add(soundContainer); FadeSound(list, isIn, volumeStep, targetVolume, targetTime); }
public void CrossfaidSound(Enumerators.SoundType soundType, Transform parent = null, bool isLoop = false) { List <SoundContainer> oldContainers = _soundContainers.FindAll(x => x.SoundParameters.IsBackground); float volumeStep = oldContainers[0].AudioSource.volume / 15f; FadeSound(oldContainers, volumeStep: volumeStep); SoundContainer soundContainer = CreateSound(soundType, 0, parent, isLoop); soundContainer.AudioSource.time = Mathf.Min(oldContainers[0].AudioSource.time, soundContainer.AudioSource.clip.length - 0.01f); FadeSound(soundContainer, true, volumeStep, oldContainers[0].AudioSource.volume); }
public void PlaySound( Enumerators.SoundType soundType, string clipTitle, float fadeOutAfterTime, float volume = -1f, Enumerators.CardSoundType cardSoundType = Enumerators.CardSoundType.NONE) { foreach (SoundContainer item in _soundContainers) { if (cardSoundType.ToString().Equals(item.Tag)) { return; } } SoundContainer thisSoundContainer = CreateSound(soundType, volume, null, false, false, 0, clipTitle, false, cardSoundType.ToString()); FadeSound(thisSoundContainer, false, 0.005f, 0f, fadeOutAfterTime); }
private SoundContainer DoSoundContainer( Enumerators.SoundType soundType, float volume = -1f, Transform parent = null, bool isLoop = false, bool isPlaylist = false, int clipIndex = 0, string clipTitle = "", bool isInQueue = false, string tag = "") { SoundParam soundParam = new SoundParam(); SoundContainer container = new SoundContainer(); SoundTypeList soundTypeList = _gameSounds.Find(x => x.SoundType == soundType); switch (soundType) { case Enumerators.SoundType.BACKGROUND: case Enumerators.SoundType.BATTLEGROUND: soundParam.IsBackground = true; break; default: soundParam.IsBackground = false; break; } soundParam.AudioClips = soundTypeList.AudioTypeClips; if (!string.IsNullOrEmpty(clipTitle)) { soundParam.AudioClips = soundParam.AudioClips.Where(clip => clip.name.Contains(clipTitle)).ToList(); } // small hack to ignore missing audio clips if (soundParam.AudioClips.Count == 0) { return(null); } soundParam.IsLoop = isLoop; soundParam.IsMute = false; soundParam.PlayOnAwake = false; soundParam.Priority = 128; if (volume < 0) { soundParam.Volume = _sfxVolume; } else { soundParam.Volume = volume; } if (SfxMuted && !soundParam.IsBackground) { soundParam.IsMute = true; } else if (MusicMuted && soundParam.IsBackground) { soundParam.IsMute = true; } soundParam.StartPosition = 0f; container.Tag = tag; container.Init(_soundsRoot, soundType, soundParam, isPlaylist, clipIndex); if (parent != null) { container.Container.transform.SetParent(parent); } _soundContainers.Add(container); return(container); }