private IEnumerator MoveDialogDown() { UIX.UpdateLayout(CanvasTr); yield return(null); dialogScrollRect.verticalNormalizedPosition = 0f; }
// 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! AppendText(text); // Update face to match choice! gameObject.GetComponent <SpriteRenderer>().enabled = true; // Show background Background.enabled = true; // Get face tag List <string> tags = story.currentTags; if (tags.Count == 1) { UpdateFace(tags[0]); } else { Debug.Log("Not updating face because tag count is " + tags.Count); } } // Display all the choices, if there are any! if (story.currentChoices.Count > 0) { for (int i = 0; i < story.currentChoices.Count; i++) { Choice choice = story.currentChoices[i]; string text = choice.text.Trim(); UnityAction action = delegate { if (DeakAction != null) { DeakButton.onClick.RemoveListener(DeakAction); DeakAction = null; } if (DadAction != null) { DadButton.onClick.RemoveListener(DadAction); DadAction = null; } if (MomAction != null) { MomButton.onClick.RemoveListener(MomAction); MomAction = null; } DadButton.gameObject.SetActive(false); DeakButton.gameObject.SetActive(false); MomButton.gameObject.SetActive(false); map.SetActive(false); OnClickChoiceButton(choice); }; Button button = null; if (text == "Deak" || text == "Deak the Neighbor") { DeakAction = action; button = DeakButton; DeakButton.gameObject.SetActive(true); map.SetActive(true); ClearText(); ClearFace(); ClearBackground(); } else if (text == "Dad") { DadAction = action; button = DadButton; DadButton.gameObject.SetActive(true); map.SetActive(true); ClearText(); ClearFace(); } else if (text == "Mom") { MomAction = action; button = MomButton; MomButton.gameObject.SetActive(true); map.SetActive(true); ClearText(); ClearFace(); } else { button = CreateChoiceView(text); } // Tell the button what to do when we press it button.onClick.AddListener(action); } } // If we've read all the content and there's no choices, the story is finished! else { Button choice = CreateChoiceView("Game Over.\nRestart?"); choice.onClick.AddListener(delegate { ClearText(); StartStory(); }); } UIX.UpdateLayout(rootCanvas.transform); float height = scrollRect.content.rect.height; float num_to_show = 300.0f; if (num_to_show < height) { float down = height - num_to_show; old_scroll_position = scrollRect.verticalNormalizedPosition; new_scroll_position = 1.0f - (down / height); num_scroll_steps = 60; //scrollRect.verticalNormalizedPosition = 1.0f - (down / height); } else { old_scroll_position = new_scroll_position = 0.0f; num_scroll_steps = 0; } }