IEnumerator SlavePlayer(Narration curr) { if (curr == null || !curr.HasSomethingToPlay()) { yield break; } float timer = 0; bool skipPressed = false; bool continuePressed = false; float subDuration = 0; float lastTimePressed = 0; //last time continue/skip button was pressed src.clip = null; //prepare AudioSource if the Narration is singleAudio or looping if (curr.singleAudio_MultiSub && curr.mainAudio != null) { src.clip = curr.mainAudio; } if (curr.LoopAudioForDuration) { src.loop = true; subDuration = .01f;//to prevent infinite looping } else { src.loop = false; if (curr.singleAudio_MultiSub && curr.mainAudio != null) { src.Play(); } } //IF NO PHRASES/SUBS AND MAIN AUDIO IS NON-LOOPING if ((curr.phrases == null || curr.phrases.Length <= 0) && curr.singleAudio_MultiSub && curr.mainAudio != null && src.isPlaying) { subDuration = curr.mainAudio.length; subManager.DisplaySubtitle("", curr.mainAudio.length, !pressToContinue); //while time left OR continue isn't yet pressed subDuration += .05f; while (timer < subDuration) { Debug.Log("nm time: " + timer); if (interrupt) { yield break; } //check for continue/skip button presses if ((pressToContinue || pressToSkip) && (timer - lastTimePressed > 0.3f)) { if (Input.GetButtonUp(buttonName)) { lastTimePressed = timer; if (pressToSkip && !skipPressed) { skipPressed = true; src.Stop(); src.clip = null; subManager.Hurry(); if (!pressToContinue) { break; } } else if (pressToContinue && (!pressToSkip || skipPressed)) { if (!skipPressed) { src.Stop(); src.clip = null; } subManager.Stop(); break; } } } timer += Time.deltaTime; yield return(null); } src.Stop(); src.clip = null; //pause between narrations if (!pressToContinue && pauseBetweenNarrations > 0) { yield return(new WaitForSeconds(pauseBetweenNarrations)); } //Force player to hit the Continue button if necessarys while (pressToContinue) { if (interrupt) { yield break; } if (Input.GetButtonUp(buttonName)) { subManager.Stop(); yield break; } yield return(null); } yield break; } //ELSE IF HAS PHRASES/SUBS, PROCESS EACH HERE for (int i = 0; i < curr.phrases.Length; i++) { if (!curr.phrases[i].HasSomethingToPlay()) { continue; //is an empty phrase, so skip } skipPressed = false; continuePressed = false; timer = 0; lastTimePressed = 0; Phrase curPhrase = curr.phrases[i]; subDuration = curPhrase.duration; //play the audio if (curr.LoopAudioForDuration && curr.singleAudio_MultiSub && curr.mainAudio != null) { src.clip = curr.mainAudio; src.Play(); } else if (!curr.singleAudio_MultiSub && curPhrase.audio != null) { src.clip = curPhrase.audio; src.Play(); } if (subManager != null) { subManager.DisplaySubtitle(Assets.Script.Manager.manager.GetTranslation(curPhrase.text), subDuration, !pressToContinue); } //subManager.DisplaySubtitle(curPhrase.text, subDuration, !pressToContinue); if (subDuration <= 0) { subDuration = defaultPhraseDuration; if (subManager != null) { subDuration = defaultPhraseDuration; } if (subDuration <= 0) { subDuration = 0.05f; } } //while time left OR continue isn't yet pressed subDuration += .05f; while (timer < subDuration) { if (interrupt) { yield break; } //check for and handle continue/skip button presses if ((pressToContinue || pressToSkip) && (timer - lastTimePressed > 0.3f)) { if (Input.GetButtonUp(buttonName)) { lastTimePressed = timer; if (pressToSkip && !skipPressed) { skipPressed = true; src.Stop(); src.clip = null; subManager.Hurry(); if (!pressToContinue) { break; } } else if (pressToContinue && (!pressToSkip || skipPressed)) { if (!skipPressed) { src.Stop(); src.clip = null; } subManager.Stop(); break;//end the loop } } } timer += Time.deltaTime; yield return(null); } if (!(curr.singleAudio_MultiSub && !curr.LoopAudioForDuration && (i + 1 < curr.phrases.Length))) { src.Stop(); src.clip = null; } //Force player to hit the Continue button if they haven't and is required while ((!continuePressed) && pressToContinue) { if (interrupt) { yield break; } if (Input.GetButtonUp(buttonName)) { subManager.Stop(); src.Stop(); src.clip = null; break; } yield return(null); } } src.Stop(); src.clip = null; yield break; }