private List <AudioClip> LoadAudioClipsByType(Enumerators.SoundType soundType) { List <AudioClip> list; string pathToSoundsLibrary = "Sounds/"; switch (soundType) { case Enumerators.SoundType.TUTORIAL: list = LoadObjectsManager.GetObjectsByPath <AudioClip>(_tutorialSoundsFilename.soundList).ToList(); break; case Enumerators.SoundType.CARDS: list = LoadObjectsManager.GetObjectsByPath <AudioClip>(_cardsSoundsFilename.soundList).ToList(); break; case Enumerators.SoundType.OVERLORD_ABILITIES: list = LoadObjectsManager.GetObjectsByPath <AudioClip>(_overlordAbilitiesSoundsFilename.soundList).ToList(); break; case Enumerators.SoundType.SPELLS: list = LoadObjectsManager.GetObjectsByPath <AudioClip>(_spellsSoundsFilename.soundList).ToList(); break; default: list = LoadObjectsManager.GetObjectsByPath <AudioClip>(new string[] { pathToSoundsLibrary + soundType.ToString() }).ToList(); break; } return(list); }
public float GetSoundLength(Enumerators.SoundType soundType, string namePattern) { SoundTypeList soundTypeList = _gameSounds.Find(x => x.SoundType == soundType); AudioClip clip = soundTypeList.AudioTypeClips.Find(x => x.name.Contains(namePattern)); return(clip != null ? clip.length : 0f); }
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 volume = -1f, Enumerators.CardSoundType cardSoundType = Enumerators.CardSoundType.NONE) { foreach (SoundContainer item in _soundContainers) { if (cardSoundType.ToString().Equals(item.Tag)) { return; } } CreateSound(soundType, volume, null, false, false, 0, clipTitle, false, cardSoundType.ToString()); }
private SoundContainer CreateSound( 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 = "") { return(DoSoundContainer(soundType, volume, parent, isLoop, isPlaylist, clipIndex, clipTitle, isInQueue, tag)); }
private List <AudioClip> LoadAudioClipsByType(Enumerators.SoundType soundType) { List <AudioClip> list = null; string pathToSoundsLibrary = "Sounds/"; switch (soundType) { default: break; } list = Resources.LoadAll <AudioClip>(pathToSoundsLibrary).ToList(); return(list); }
public void PlaySound( Enumerators.SoundType soundType, int priority = 128, float volume = -1f, Transform parent = null, bool isLoop = false, bool isPlaylist = false, bool dropOldBackgroundMusic = false, bool isInQueue = false) { if (dropOldBackgroundMusic) { StopBackroundMusic(); } CreateSound(soundType, volume, parent, isLoop, isPlaylist, isInQueue: isInQueue); }
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); }
//NEW public AudioSource PlaySound(List <AudioClip> clips, Enumerators.SoundType soundType, int clipIndex = 0, int priority = 128, float volume = -1f, Transform parent = null, bool isLoop = false, bool isPlaylist = false, bool dropOldBackgroundMusic = true, bool returnHashCode = false) { if (dropOldBackgroundMusic) { var oldContainers = _soundContainers.FindAll(x => x.soundParameters.isBackground); foreach (var oldCotainer in oldContainers) { oldCotainer.audioSource.Stop(); oldCotainer.forceClose = true; } } SoundParam soundParam = new SoundParam(); SoundContainer container = new SoundContainer(); SoundTypeList soundTypeList = new SoundTypeList(); soundTypeList.soundType = soundType; soundTypeList.audioTypeClips = clips; soundParam.isBackground = soundType.ToString().Contains("BACKGROUND") ? true : false; soundParam.audioClips = soundTypeList.audioTypeClips; soundParam.isLoop = isLoop; soundParam.isMute = false; soundParam.playOnAwake = false; soundParam.priority = 128; soundParam.volume = volume; soundParam.startPosition = 0f; container.Init(_soundsRoot, soundType, soundParam, isPlaylist, clipIndex); if (parent != null) { container.container.transform.SetParent(parent); } _soundContainers.Add(container); return(container.audioSource); }
public void StopPlaying(Enumerators.SoundType soundType, int id = 0) { SoundContainer container; if (id == 0) { container = _soundContainers.Find(x => x.SoundType == soundType); } else { container = _soundContainers.Find(x => x.SoundType == soundType && x.GetHashCode() == id); } if (container != null) { container.AudioSource.Stop(); container.ForceClose = true; } }
public void Init(Transform soundsContainerRoot, Enumerators.SoundType type, SoundParam soundParam, bool playlistEnabled, int soundIndex = 0) { forceClose = false; currentSoundIndex = soundIndex; soundParameters = soundParam; isPlaylist = playlistEnabled; soundType = type; container = new GameObject("AudioClip " + soundType.ToString()); container.transform.SetParent(soundsContainerRoot, false); audioSource = container.AddComponent <AudioSource>(); audioSource.clip = soundParam.audioClips[currentSoundIndex]; audioSource.volume = soundParam.volume; audioSource.loop = soundParam.isLoop; audioSource.time = soundParam.startPosition; audioSource.mute = soundParam.isMute; audioSource.playOnAwake = soundParam.playOnAwake; audioSource.priority = soundParam.priority; audioSource.spatialBlend = 1f; audioSource.Play(); }
public void Init( Transform soundsContainerRoot, Enumerators.SoundType type, SoundParam soundParam, bool playlistEnabled, int soundIndex = 0) { ForceClose = false; CurrentSoundIndex = soundIndex; SoundParameters = soundParam; IsPlaylist = playlistEnabled; SoundType = type; Container = new GameObject("AudioClip " + SoundType); Container.transform.SetParent(soundsContainerRoot, false); AudioSource = Container.AddComponent <AudioSource>(); AudioSource.clip = soundParam.AudioClips[CurrentSoundIndex]; AudioSource.volume = soundParam.Volume; AudioSource.loop = soundParam.IsLoop; AudioSource.time = soundParam.StartPosition; AudioSource.mute = soundParam.IsMute; AudioSource.playOnAwake = soundParam.PlayOnAwake; AudioSource.priority = soundParam.Priority; AudioSource.spatialBlend = 1f; AudioSource.Play(); }
public void PlaySound( Enumerators.SoundType soundType, string clipTitle, float volume = -1f, bool isLoop = false, bool isInQueue = false) { CreateSound(soundType, volume, null, isLoop, false, 0, clipTitle, isInQueue); }
public void PlayAttackVfx(Enumerators.CardType type, Vector3 target, int damage) { GameObject effect; GameObject vfxPrefab; target = Utilites.CastVfxPosition(target); Vector3 offset = Vector3.forward * 1; switch (type) { case Enumerators.CardType.FERAL: { vfxPrefab = _loadObjectsManager.GetObjectByPath <GameObject>("Prefabs/VFX/FeralAttackVFX"); effect = Object.Instantiate(vfxPrefab); effect.transform.position = target - offset; _soundManager.PlaySound(Enumerators.SoundType.FERAL_ATTACK, Constants.CreatureAttackSoundVolume, false, false, true); _particlesController.RegisterParticleSystem(effect, true, 5f); if (damage > 3 && damage < 7) { _timerManager.AddTimer( a => { effect = Object.Instantiate(vfxPrefab); effect.transform.position = target - offset; effect.transform.localScale = new Vector3(-1, 1, 1); _particlesController.RegisterParticleSystem(effect, true, 5f); }, null, 0.5f); } if (damage > 6) { _timerManager.AddTimer( a => { effect = Object.Instantiate(vfxPrefab); effect.transform.position = target - Vector3.right - offset; effect.transform.eulerAngles = Vector3.forward * 90; _particlesController.RegisterParticleSystem(effect, true, 5f); }); } break; } case Enumerators.CardType.HEAVY: { Enumerators.SoundType soundType = Enumerators.SoundType.HEAVY_ATTACK_1; string prefabName = "Prefabs/VFX/HeavyAttackVFX"; if (damage > 4) { prefabName = "Prefabs/VFX/HeavyAttack2VFX"; soundType = Enumerators.SoundType.HEAVY_ATTACK_2; } vfxPrefab = _loadObjectsManager.GetObjectByPath <GameObject>(prefabName); effect = Object.Instantiate(vfxPrefab); effect.transform.position = target; _particlesController.RegisterParticleSystem(effect, true, 5f); _soundManager.PlaySound(soundType, Constants.CreatureAttackSoundVolume, false, false, true); break; } default: { vfxPrefab = _loadObjectsManager.GetObjectByPath <GameObject>("Prefabs/VFX/WalkerAttackVFX"); effect = Object.Instantiate(vfxPrefab); effect.transform.position = target - offset; _particlesController.RegisterParticleSystem(effect, true, 5f); if (damage > 4) { _timerManager.AddTimer( a => { effect = Object.Instantiate(vfxPrefab); effect.transform.position = target - offset; effect.transform.localScale = new Vector3(-1, 1, 1); _particlesController.RegisterParticleSystem(effect, true, 5f); }, null, 0.5f); _soundManager.PlaySound(Enumerators.SoundType.WALKER_ATTACK_2, Constants.CreatureAttackSoundVolume, false, false, true); } else { _soundManager.PlaySound(Enumerators.SoundType.WALKER_ATTACK_1, Constants.CreatureAttackSoundVolume, false, false, true); } break; } } }
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); }
public float GetSoundLength(Enumerators.SoundType soundType) { SoundTypeList soundTypeList = _gameSounds.Find(x => x.SoundType == soundType); return(soundTypeList.AudioTypeClips.Count > 0 ? soundTypeList.AudioTypeClips[0].length : 0f); }
public void PlaySound( Enumerators.SoundType soundType, float volume = -1f, bool isLoop = false, bool dropOldBackgroundMusic = false, bool isInQueue = false) { PlaySound(soundType, 128, volume, null, isLoop, false, dropOldBackgroundMusic, isInQueue); }
public void PlaySound( Enumerators.SoundType soundType, int clipIndex, float volume = -1f, bool isLoop = false, bool isInQueue = false) { CreateSound(soundType, volume, null, isLoop, false, clipIndex, isInQueue: isInQueue); }