public void QueueAudio(AudioClip audioFile, EAudioType type, EInterrupt interruptsAudioTypes = EInterrupt.None, bool isInterruptible = true) { //Debug.Log("playing " + audioFile.name); // Build struct and call internal add function SAudioEntry newEntry = new SAudioEntry(); newEntry.m_Audio = audioFile; newEntry.m_AudioType = type; newEntry.m_IsInterruptible = isInterruptible; QueueAudio(newEntry, interruptsAudioTypes); }
////////////////////////////////////////////////////////////////////////// public void QueueAudio(string textForTTS, EAudioType type, bool allowVoiceOver, EInterrupt interruptsAudioTypes = EInterrupt.None, bool isInterruptible = true) { //Debug.Log("speaking " + textForTTS); // Build struct and call internal add function SAudioEntry newEntry = new SAudioEntry(); newEntry.m_TTS_Text = textForTTS; newEntry.m_AllowVoiceOver = allowVoiceOver; newEntry.m_AudioType = type; newEntry.m_IsInterruptible = isInterruptible; QueueAudio(newEntry, interruptsAudioTypes); }
////////////////////////////////////////////////////////////////////////// private void QueueAudio(SAudioEntry newEntry, EInterrupt interrupts) { // check for interrupts and cancel/queue accordingly if (interrupts != EInterrupt.None) { // Stop current element (if any) if (m_ActiveEntry != null && m_ActiveEntry.m_IsInterruptible) { if (((int)m_ActiveEntry.m_AudioType & (int)interrupts) > 0) { //Debug.Log("Current audio type is " + m_ActiveEntry.m_AudioType + " and it is interruptible"); StopAudio(); m_ActiveEntry = null; } } // Go through the queue and remove all entries that match the type int entryCount = m_AudioQueue.Count; Queue <SAudioEntry> tempQueue = new Queue <SAudioEntry>(); for (int i = 0; i < entryCount; ++i) { SAudioEntry entry = m_AudioQueue.Dequeue(); if (!entry.m_IsInterruptible) { tempQueue.Enqueue(entry); } else if (((int)entry.m_AudioType & (int)interrupts) == 0) { tempQueue.Enqueue(entry); } } m_AudioQueue = tempQueue; } // Sanity Check - don't queue up empty entries if (newEntry.m_AudioType == EAudioType.None) { return; } if (newEntry.m_AudioType != EAudioType.Pause && (newEntry.m_Audio == null && newEntry.m_TTS_Text.Length == 0)) { return; } m_AudioQueue.Enqueue(newEntry); }
////////////////////////////////////////////////////////////////////////// public void QueueAudio(string textForTTS, EAudioType type, bool allowVoiceOver, UAP_GenericCallback callbackOnDone = null, EInterrupt interruptsAudioTypes = EInterrupt.None, bool isInterruptible = true) { //Debug.Log("speaking " + textForTTS); // Build struct and call internal add function SAudioEntry newEntry = new SAudioEntry(); newEntry.m_TTS_Text = Regex.Replace(textForTTS, "(<.[^(><.)]+>)", " "); newEntry.m_AllowVoiceOver = allowVoiceOver; newEntry.m_AudioType = type; newEntry.m_IsInterruptible = isInterruptible; newEntry.m_CallbackOnDone = callbackOnDone; QueueAudio(newEntry, interruptsAudioTypes); }