/// <summary> /// /// </summary> /// <param name="clipsQueue">список аудио клипов, которые будут проигрываться по очереди</param> /// <param name="priority">приоритет. чем больше число, тем больше приоритет. если нет свободных источнико звука, то более приоритетная очередь клипов вытеснит самую менее приоритетную, из проигрываемых сейчас</param> /// <param name="loop">иповторять ли проигрывание данной очереди клипов</param> /// <returns></returns> public bool PlayClips(List <ClipSet> clipsQueue, SoundManager.SoundType type, int priority = 0, bool loop = false, float volume = 1) { bool res = true; var src = GetSource(); if (src.source != null) { src.clipQueue = new Queue <ClipSet>(clipsQueue); src.coroutineClipQueue = StartCoroutine(PlayClipsQueue(src, loop, volume, type)); } else { if (usedSources.Count > 0 && usedSources[0].priority < priority) { ReturnBackSource(usedSources[0]); src = GetSource(); src.clipQueue = new Queue <ClipSet>(clipsQueue); src.coroutineClipQueue = StartCoroutine(PlayClipsQueue(src, loop, volume, type)); Debug.Log("Был заменен источник звука с боле низким приоритетом"); } else { Debug.Log("В пуле нет доступного сурса"); res = false; } } return(res); }
public bool PlayManagedClip(object key, Transform parent, ClipSet clip, SoundManager.SoundType type, int priority = 0, float volume = 1, float updateDeltaTime = 0.5f) { bool res = true; var src = GetManagedSource(key, parent); if (src.source != null) { src.clipQueue = new Queue <ClipSet>(); src.clipQueue.Enqueue(clip); src.coroutineClipQueue = StartCoroutine(PlayClipsQueue(src, false, volume, type, updateDeltaTime)); } else { if (usedSources.Count > 0 && usedSources.Any(s => s.priority < priority)) { var prirsrc = usedSources.Where(s => s.priority < priority).OrderBy(s => s.priority).First(); ReturnBackSource(prirsrc); src = GetManagedSource(key, parent); src.clipQueue = new Queue <ClipSet>(); src.clipQueue.Enqueue(clip); src.coroutineClipQueue = StartCoroutine(PlayClipsQueue(src, false, volume, type)); Debug.Log("Был заменен источник звука с боле низким приоритетом"); } else if (managedUsedSources.Count > 0 && managedUsedSources.Any(s => s.Value.Any(ss => ss.priority < priority))) { var prirsrc = managedUsedSources.Where(s => s.Value.Any(ss => ss.priority < priority)) .SelectMany(s => s.Value.Where(ss => ss.priority < priority)) .OrderBy(s => s.priority) .First(); ReturnBackSource(prirsrc); src = GetManagedSource(key, parent); src.clipQueue = new Queue <ClipSet>(); src.clipQueue.Enqueue(clip); src.coroutineClipQueue = StartCoroutine(PlayClipsQueue(src, false, volume, type)); Debug.Log("Был заменен источник звука с боле низким приоритетом"); } else { Debug.Log("В пуле нет доступного сурса"); res = false; } } return(res); }
public AudioData(string path, SoundManager.SoundType type, bool loop, Transform parent, Vector3 position, int priority, float minPitch, float maxPitch, float volume) { this.go = new GameObject(string.Format("Audio_{0}_{1}", type.ToString(), path)); this.go.transform.SetParent(parent); this.go.transform.position = position; this.path = path; this.type = type; this.audio = this.go.AddComponent <AudioSource>(); this.audio.playOnAwake = false; this.audio.bypassEffects = true; this.audio.loop = loop; this.audio.priority = priority; this.audio.rolloffMode = AudioRolloffMode.Linear; this.audio.dopplerLevel = 0f; this.audio.maxDistance = 25f; this.audio.volume = volume; this.defaultVol = volume; this.minPitch = minPitch; this.maxPitch = maxPitch; }
IEnumerator PlayClipsQueue(AudioSourseSet src, bool loop, float volume, SoundManager.SoundType type, float updateDeltaTime = 0.5f) { while (src.clipQueue.Count > 0) { var clipSet = src.clipQueue.Peek(); src.currentClipSet = clipSet; src.source.clip = clipSet.Clip; src.source.loop = clipSet.Loop; src.volumeDempfer = volume; src.Type = type; src.source.transform.position = src.clipQueue.Peek().Position; //src.source.transform.localPosition = src.clipQueue.Peek().Position; src.Play(); if (!src.source.loop) { var clip = src.clipQueue.Dequeue(); if (loop) { src.clipQueue.Enqueue(clip); } //если установили позицию для апдейта, то обновляем регулярно... if (src.PosToUpdate != null) { var timer = 0f; var duration = src.source.clip.length; while (timer < duration) { timer += Time.unscaledDeltaTime; if (src.PosToUpdate != null) { src.source.transform.position = src.PosToUpdate.position; } yield return(new WaitForSecondsRealtime(updateDeltaTime)); } } else { yield return(new WaitForSecondsRealtime(src.source.clip.length)); } } else { if (src.PosToUpdate != null) { while (true) { if (src.PosToUpdate != null) { src.source.transform.position = src.PosToUpdate.position; } yield return(new WaitForSecondsRealtime(updateDeltaTime)); } } else { break; } } } if (src.clipQueue.Count == 0) { ReturnBackSource(src); } }
public void PlaySound(SoundManager.SoundType soundtype) { soundManager.Play(soundtype); }
public void AddSound(SoundManager.SoundType soundtype, int index) { soundqueue[index] = soundtype; }
public void PlayMusic(string musicName, SoundManager.SoundType soundType = SoundManager.SoundType.Default) { soundManager.PlayMusic(musicName, soundType); }