From 0b295af56b1a0ba60cec920de2837dfe52724830 Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Mon, 28 Sep 2020 23:07:12 -0400 Subject: [PATCH] Implement scene transition --- Assets/Story/SceneId.cs | 2 ++ Assets/Story/Scenes/Scene_Prologue_First.cs | 2 +- Assets/Story/StoryBox.cs | 2 -- Assets/Story/StoryController.cs | 25 ++++++++++++--------- Assets/Story/StoryDisplay.cs | 2 -- Assets/Story/StoryScene.cs | 13 +++++++++++ 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Assets/Story/SceneId.cs b/Assets/Story/SceneId.cs index 0b9635b..3183b1a 100644 --- a/Assets/Story/SceneId.cs +++ b/Assets/Story/SceneId.cs @@ -4,6 +4,8 @@ using UnityEngine; public enum SceneId { + None, + Prologue_First, Chapter1_Cave, } diff --git a/Assets/Story/Scenes/Scene_Prologue_First.cs b/Assets/Story/Scenes/Scene_Prologue_First.cs index d6398b7..30eb162 100644 --- a/Assets/Story/Scenes/Scene_Prologue_First.cs +++ b/Assets/Story/Scenes/Scene_Prologue_First.cs @@ -27,6 +27,6 @@ public class Scene_Prologue_First: StoryScene { DialogPosition.Right); yield return new WaitForSeconds(2f); - // TODO: Transition to Chapter 1. + this.SetNextSceneId(SceneId.Chapter1_Cave); } } diff --git a/Assets/Story/StoryBox.cs b/Assets/Story/StoryBox.cs index 1bfd5fd..fca75fd 100644 --- a/Assets/Story/StoryBox.cs +++ b/Assets/Story/StoryBox.cs @@ -12,12 +12,10 @@ public class StoryBox : MonoBehaviour { private bool clicked; void Start() { - Debug.Log("StoryBox Start"); this.button.onClick.AddListener(NotifyOnClick); } public IEnumerator Display(string message) { - Debug.Log("StoryBox Display"); this.gameObject.SetActive(true); this.clicked = false; this.text.text = message; diff --git a/Assets/Story/StoryController.cs b/Assets/Story/StoryController.cs index 02de8a6..735ffe5 100644 --- a/Assets/Story/StoryController.cs +++ b/Assets/Story/StoryController.cs @@ -6,19 +6,22 @@ public class StoryController : MonoBehaviour { public StoryDisplay storyDisplay; - // Start is called before the first frame update - void Start() - { - // TODO: Read which scene should be loaded. - //StoryScene scene = StorySceneDatabase.Load(SceneId.Chapter1_Cave); - StoryScene scene = StorySceneDatabase.Load(SceneId.Prologue_First); + private SceneId nextSceneId; - StartCoroutine(scene.Play(this.storyDisplay)); + void Start() { + // TODO: Read which scene should be loaded. + this.nextSceneId = SceneId.Prologue_First; + + StartCoroutine(this.PlayScenes()); } - // Update is called once per frame - void Update() - { - + private IEnumerator PlayScenes() { + while (true) { + SceneId id = this.nextSceneId; + this.nextSceneId = SceneId.None; + StoryScene scene = StorySceneDatabase.Load(id); + yield return scene.Play(this.storyDisplay); + this.nextSceneId = scene.GetNextSceneId(); + } } } diff --git a/Assets/Story/StoryDisplay.cs b/Assets/Story/StoryDisplay.cs index fbdead4..8b63296 100644 --- a/Assets/Story/StoryDisplay.cs +++ b/Assets/Story/StoryDisplay.cs @@ -16,7 +16,6 @@ public class StoryDisplay : MonoBehaviour private StoryBox storyBoxLeft; void Awake() { - Debug.Log("StoryDisplay Awake"); this.storyBoxLeft = GameObject.Instantiate(this.storyBox, this.uiCanvas.transform); RectTransform rt = this.storyBoxLeft.GetComponent(); rt.anchorMin = new Vector2(0, 0.5f); @@ -28,7 +27,6 @@ public class StoryDisplay : MonoBehaviour } public IEnumerator DisplayText(string message, DialogPosition position) { - Debug.Log("DisplayText " + message); if (position == DialogPosition.Left) { yield return this.storyBoxLeft.Display(message); } else { diff --git a/Assets/Story/StoryScene.cs b/Assets/Story/StoryScene.cs index 50e5d41..91cf285 100644 --- a/Assets/Story/StoryScene.cs +++ b/Assets/Story/StoryScene.cs @@ -4,5 +4,18 @@ using UnityEngine; public abstract class StoryScene { + private SceneId nextSceneId = SceneId.None; + public abstract IEnumerator Play(StoryDisplay storyDisplay); + + protected void SetNextSceneId(SceneId id) { + this.nextSceneId = id; + } + + public SceneId GetNextSceneId() { + if (nextSceneId == SceneId.None) { + throw new System.InvalidOperationException("nextSceneId is None"); + } + return this.nextSceneId; + } }