Example #1
0
    // This is the main function called every time the story changes. It does a few things:
    // Destroys all the old content and choices.
    // Continues over all the lines of text, then displays all the choices. If there are no choices, the story is finished!
    void RefreshView()
    {
        // Remove all the UI on screen
        //RemoveChildren();

        // Read all the content until we can't continue any more
        while (story.canContinue)
        {
            // Continue gets the next line of the story
            string text = story.Continue();
            // This removes any white space from the text.
            text = text.Trim();
            // Display the text on screen!
            CreateContentView(text);
        }

        // Display all the choices, if there are any!
        if (story.currentChoices.Count > 0)
        {
            if (story.currentChoices.Count == 1)
            {
                Choice choice = story.currentChoices[0];
                Button button = CreateChoiceView(choice.text.Trim(), 1);
                // Tell the button what to do when we press it
                button.onClick.AddListener(delegate {
                    OnClickChoiceButton(choice);
                });
            }
            else if (story.currentChoices.Count == 2)
            {
                for (int i = 0; i < story.currentChoices.Count; i++)
                {
                    Choice choice = story.currentChoices[i];
                    Button button = CreateChoiceView(choice.text.Trim(), 2);
                    // Tell the button what to do when we press it
                    button.onClick.AddListener(delegate {
                        OnClickChoiceButton(choice);
                    });
                }
            }
        }
        // If we've read all the content and there's no choices, the story is finished!
        else
        {
            ButtonTwo.SetActive(false);
            ButtonOne.gameObject.SetActive(true);
            Button button = CreateChoiceView("Exit", 1);
            // Tell the button what to do when we press it
            button.onClick.AddListener(delegate {
                TextLogObj.SetActive(false);
            });
        }
    }
Example #2
0
 // Creates a new Story object with the compiled story which we can then play!
 void StartStory()
 {
     TextLogObj.SetActive(true);
     story = new Story(inkJSONAsset.text);
     RefreshView();
 }