/// <summary> /// This will, on a given <seealso cref="Chapter">chapter</seealso>: /// <list type="bullet"> /// <item>Instance a given prefab and set it to be the parent of the given panel.</item> /// <item>Set the text and background color depending on if the chapter has been completed or not.</item> /// <item>Register a listener that will load the yarn asset whenever the user clicks on the button.</item> /// </list> /// </summary> /// <param name="id">The said position of this chapter;</param> /// <param name="chapter">The chapter object;</param> /// <param name="isCompleted">Was the chapter completed or not.</param> private void AddChapter(int id, Chapter chapter, bool isCompleted) { var newChapterEntry = Instantiate(this.UIChapterEntryPrefab); var image = newChapterEntry.GetComponent <Image>(); var button = newChapterEntry.GetComponent <Button>(); var text = newChapterEntry.GetComponentInChildren <Text>(); // Set the parent of the chapter game object to be the content panel. newChapterEntry.transform.SetParent(this.ContainerContentPanel); // Set the button text to be: `<chapter_id>: <chapter_name>`. text.text = string.Format("{0}: {1}", id, chapter); // Set the background and text color with the given ones. // ...Here is for a completed chapter. if (isCompleted) { image.color = this.CompletedColor; text.color = this.CompletedTextColor; } // Set the colors of a non-completed chapter. else { image.color = this.UnCompletedColor; text.color = this.UnCompletedTextColor; } // Register a 'on click' event to the button, // that will load the yarn script whenever the user clicks on the button. button.onClick.AddListener(() => { YarnSceneManager.LoadYarn(chapter.YarnAsset); }); }
/// <summary> /// Load the Yarn manager (Visual Novel) scene. /// </summary> private void OnClick() { YarnSceneManager.LoadYarn(this.YarnSceneToLoad); }
/// <summary> /// Loads a new game when the user click on the element, /// and reset any game state data. /// </summary> protected override void OnClick() { SaveGameManager.ResetData(); YarnSceneManager.LoadYarn(this.YarnSceneToLoad); }