public AudioPlayerBehavior Play(AudioEffectDefinition definition, Vector3 location, AudioPriority priority = AudioPriority.Normal) { var currentTime = Time.time; if ((currentTime - previousPlayRequestTime < 1f) && soundsPerLastSecond >= SoundsPerSecond && priority != AudioPriority.High) { return(null); } if (currentTime - previousPlayRequestTime > 1f) { soundsPerLastSecond = 0; } previousPlayRequestTime = currentTime; soundsPerLastSecond++; InitIfNeeded(); var audioPlayer = new GameObject(string.Format(defaultPlayerName, definition.name)) .AddComponent <AudioPlayerBehavior>(); audioPlayer.transform.SetParent(audioEffectsStorage); audioPlayer.PlayDefinition(definition); audioPlayer.transform.position = location; activePlayers.Add(audioPlayer); audioPlayer.DidEndPlaying += OnPlayerEndPlaying; return(audioPlayer); }
public AudioEvent(AnnouncementType aType, AudioPriority aPrior, float t, float et) { type = aType; priority = aPrior; timeOccurred = t; timeToExpire = et; }
public void EventOccurred(AnnouncementType type, AudioPriority priority, float expirationTime) { if (announcerClips.ContainsKey(type)) { AudioEvent ae = new AudioEvent(type, priority, Time.time, expirationTime); waitingClips.Add(ae); } }
public void PlayNextAnnouncerClip() { float timeSinceLastClip = Time.time - prevClipPlayTime; if (timeSinceLastClip > minTimeBetweenClips) { if (waitingClips.Count > 0) { AudioPriority maxPriority = AudioPriority.NONE; int maxIndex = -1; for (int i = 0; i < waitingClips.Count; i++) { if (waitingClips[i].priority > maxPriority) { maxPriority = waitingClips[i].priority; maxIndex = i; } } if (maxIndex >= 0) { AnnouncementType type = waitingClips[maxIndex].type; PlayAnnouncerClip(type); waitingClips.RemoveAt(maxIndex); } for (int i = 0; i < waitingClips.Count; i++) { if (Time.time > waitingClips[i].timeToExpire + waitingClips[i].timeOccurred) { waitingClips.RemoveAt(maxIndex); } } } } }
public AudioPlayerBehavior Play(AudioEffectDefinition definition, AudioPriority priority = AudioPriority.Normal) { return(Play(definition, Vector3.zero, priority)); }