//TODO: If someone wants to reimplement this with some sort of coutroutine lambda hack and get rid of // the ugly ugly PlayScene and the CutsceneAction type I'll love you forever. Maybe smth like: // https://answers.unity.com/questions/542115/is-there-any-way-to-use-coroutines-with-anonymous.html IEnumerator PlayScene() { if (true) { foreach (CutsceneScriptLine line in script.script) { switch (line.action) { case CutsceneAction.TransitionIn: currentScriptLine = this.StartStoppableCoroutine(transitionIn(line.character, line.side)); yield return(currentScriptLine.WaitFor()); break; case CutsceneAction.TransitionOut: currentScriptLine = this.StartStoppableCoroutine(transitionOut(line.side)); yield return(currentScriptLine.WaitFor()); break; case CutsceneAction.SetCharacter: currentScriptLine = this.StartStoppableCoroutine(setCharacter(line.character, line.side)); yield return(currentScriptLine.WaitFor()); break; case CutsceneAction.FocusSide: focusSide(line.side); break; case CutsceneAction.SetBackground: setBackground(line.background); break; case CutsceneAction.SayDialogue: currentScriptLine = this.StartStoppableCoroutine(sayDialogue(line.character, line.dialogue)); yield return(currentScriptLine.WaitFor()); break; default: Debug.LogError("Unrecognized CutsceneAction type"); break; } yield return(new WaitForSeconds(0.25f)); } } }
private IEnumerator StartStateCoroutine(IEnumerator _coroutine, PawnState _state) { if (_state.invincibleDuringState) { SetInvincible(true); } currentStateCoroutine = MonoBehaviourExtension.StartCoroutineEx(this, _coroutine); yield return(currentStateCoroutine.WaitFor()); currentPawnState = null; yield return(null); if (_state.invincibleDuringState) { SetInvincible(false); } currentStateCoroutine = null; }
private IEnumerator Invoke(StageBuilder stageBuilder) { if (stageBuilder.stopAudio) { Audio.stopAudio(false); } if (stageBuilder.pauseBattleTheme) { Audio.pauseAudio(true); } if (stageBuilder.newcomer != null) { if (FindActor(stageBuilder.newcomer.name) != null) { throw new UnityException( "There already exists an actor in the scene with name: " + stageBuilder.newcomer.name); } yield return(AddActor(stageBuilder.newcomer, stageBuilder.newcomer.side)); } if (stageBuilder.expression != null) { Actor foundActor = FindActor(stageBuilder.speaker); if (foundActor == null) { throw new UnityException( "There exists no actor in the scene with name: " + stageBuilder.speaker ); } foundActor.image.sprite = stageBuilder.expression; } if (stageBuilder.sfx != null) { Audio.playSfx(stageBuilder.sfx); } if (stageBuilder.background != null) { Sprite foundSprite = (Resources.Load <Sprite>("Sprites/" + stageBuilder.background)); if (foundSprite == null) { throw new UnityException( "There exists no background " + stageBuilder.background + " in the Resources/Sprites folder, or it has not been imported as a Sprite." ); } yield return(changeBackground(foundSprite)); } if (stageBuilder.message != null) { CutsceneSide side = CutsceneSide.None; if (!string.IsNullOrEmpty(stageBuilder.speaker)) { Actor foundActor = FindActor(stageBuilder.speaker); if (foundActor == null) { throw new UnityException( "There exists no actor in the scene with name: " + stageBuilder.speaker ); } side = foundActor.side; foreach (Actor actor in actors) { if (actor.side != side) { actor.IsDark = true; } } } textbox.AddText(side, stageBuilder.speaker, stageBuilder.message); //I approximate it to take ~0.03 seconds per letter, but we do more so players can actually read float playTimeGuess = (float)(stageBuilder.message.Length * 0.06 + 1.5); currentDialogLine = this.StartStoppableCoroutine(waitForSeconds(playTimeGuess)); yield return(currentDialogLine.WaitFor()); foreach (Actor actor in actors) { actor.IsDark = false; } } if (!string.IsNullOrEmpty(stageBuilder.leaverName)) { Actor foundActor = FindActor(stageBuilder.leaverName); if (foundActor == null) { throw new UnityException( "There exists no actor in the scene with name: " + stageBuilder.leaverName ); } yield return(RemoveActor(foundActor)); } yield break; }