//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 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(); }
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); }