6 using System.Collections.Generic;
20 public TBank[] DefaultBanks = null;
24 protected TEvent[] Events = null;
26 protected const float InfiniteLoop = -1;
33 #pragma warning disable 612 34 public TEvent[] EditorEvents {
get {
return Events; }
set { Events = value; } }
35 #pragma warning restore 612 36 public List<ActiveEvent> ProfilerEvents {
get {
return ActiveEvents; } }
43 ActiveEvents =
new List<ActiveEvent>();
44 LoadedBanks =
new List<TBank>(DefaultBanks.Length + 5);
45 for (
int i = 0; i < DefaultBanks.Length; i++)
47 LoadBank(DefaultBanks[i]);
53 UpdateEmitterVolumes();
67 return LoadedBanks.Contains(bank);
74 Debug.LogWarningFormat(
"Attempting to Load {0} bank twice", bank.name);
78 LoadedBanks.Add(bank);
85 LoadedBanks.Remove(bank);
94 for (
int i = ActiveEvents.Count - 1; i >= 0; i--)
96 StopEvent(ActiveEvents[i]);
106 for (
int i = ActiveEvents.Count - 1; i >= 0; i--)
108 StartCoroutine(StopEventWithFadeCoroutine(ActiveEvents[i], fadeTime));
117 for (
int i = ActiveEvents.Count - 1; i >= 0; i--)
121 StopEvent(ActiveEvents[i]);
131 for (
int i = ActiveEvents.Count - 1; i >= 0; i--)
133 if (ActiveEvents[i].PrimarySource == emitter)
135 StopEvent(ActiveEvents[i]);
143 private void UpdateEmitterVolumes()
146 for (
int i = 0; i < ActiveEvents.Count; i++)
202 StartOneOffEvent(activeEvent);
206 StartOneOffEvent(activeEvent);
210 StartOneOffEvent(activeEvent);
233 private void StartOneOffEvent(
ActiveEvent activeEvent)
237 StartCoroutine(PlayLoopingOneOffContainerCoroutine(activeEvent));
242 PlayOneOffContainer(activeEvent);
245 StartCoroutine(RecordEventInstanceCoroutine(activeEvent));
251 private float PlayOneOffContainer(
ActiveEvent activeEvent)
266 clipTime = PlaySimultaneousClips(currentContainer, activeEvent);
271 clipTime = PlaySingleClip(currentContainer, activeEvent);
284 float finalActiveTime = 0f;
288 finalActiveTime = InfiniteLoop;
291 for (
int i = 0; i < currentContainer.
Sounds.Length; i++)
293 tempDelay = PlayClipAndGetTime(currentContainer.
Sounds[i], activeEvent.
PrimarySource, activeEvent);
295 if (finalActiveTime != InfiniteLoop)
297 float estimatedActiveTimeNeeded = GetActiveTimeEstimate(currentContainer.
Sounds[i], activeEvent, tempDelay);
299 if (estimatedActiveTimeNeeded == InfiniteLoop || estimatedActiveTimeNeeded > finalActiveTime)
301 finalActiveTime = estimatedActiveTimeNeeded;
306 return finalActiveTime;
325 tempDelay = PlayClipAndGetTime(currentClip, activeEvent.
PrimarySource, activeEvent);
338 return GetActiveTimeEstimate(currentClip, activeEvent, tempDelay);
344 private IEnumerator PlayLoopingOneOffContainerCoroutine(
ActiveEvent activeEvent)
348 float tempLoopTime = PlayOneOffContainer(activeEvent);
352 if (eventLoopTime != 0)
354 tempLoopTime = eventLoopTime;
357 yield
return new WaitForSeconds(tempLoopTime);
380 PlayClipAndGetTime(tempClip, emitter, activeEvent);
382 StartCoroutine(RecordEventInstanceCoroutine(activeEvent));
388 StartCoroutine(ContinueRandomContainerCoroutine(audioContainer, activeEvent, waitTime));
398 private IEnumerator ContinueRandomContainerCoroutine(
AudioContainer audioContainer,
ActiveEvent activeEvent,
float waitTime)
402 yield
return new WaitForSeconds(waitTime);
415 PlayClipAndGetTime(tempClip, activeEvent.
PrimarySource, activeEvent);
425 PlayClipAndGetTime(tempClip, activeEvent.
SecondarySource, activeEvent);
438 private void PlayContinuousSequenceContainer(
AudioContainer audioContainer, AudioSource emitter,
ActiveEvent activeEvent)
450 PlayClipAndGetTime(tempClip, emitter, activeEvent);
452 StartCoroutine(RecordEventInstanceCoroutine(activeEvent));
460 StartCoroutine(ContinueSequenceContainerCoroutine(audioContainer, activeEvent, waitTime));
470 private IEnumerator ContinueSequenceContainerCoroutine(
AudioContainer audioContainer,
ActiveEvent activeEvent,
float waitTime)
474 yield
return new WaitForSeconds(waitTime);
476 if (tempClip.
Sound == null)
478 Debug.LogErrorFormat(
this,
"Sound clip in event \"{0}\" is null!", activeEvent.
AudioEvent.
Name);
491 PlayClipAndGetTime(tempClip, activeEvent.
PrimarySource, activeEvent);
501 PlayClipAndGetTime(tempClip, activeEvent.
SecondarySource, activeEvent);
540 StartCoroutine(PlayClipDelayedCoroutine(audioClip, emitter, rndDelay, activeEvent));
559 private IEnumerator PlayClipDelayedCoroutine(
UAudioClip audioClip, AudioSource emitter,
float delay,
ActiveEvent activeEvent)
561 yield
return new WaitForSeconds(delay);
563 if (this.ActiveEvents.Contains(activeEvent))
586 RemoveEventInstance(activeEvent);
604 yield
return new WaitForSeconds(fadeTime);
617 RemoveEventInstance(activeEvent);
627 private IEnumerator RecordEventInstanceCoroutine(
ActiveEvent activeEvent)
631 ActiveEvents.Add(activeEvent);
636 yield
return new WaitForSeconds(activeEvent.
ActiveTime);
656 RemoveEventInstance(activeEvent);
664 private void RemoveEventInstance(
ActiveEvent activeEvent)
666 ActiveEvents.Remove(activeEvent);
684 int tempInstances = 0;
686 for (
int i = 0; i < ActiveEvents.Count; i++)
688 var eventInstance = ActiveEvents[i];
690 if (!eventInstance.IsActiveTimeComplete && eventInstance.AudioEvent.Name == eventName)
696 return tempInstances;
706 private static float GetActiveTimeEstimate(
UAudioClip audioClip,
ActiveEvent activeEvent,
float additionalDelay)