private IEnumerator IterateDialogueCoroutine(string name, string answer, string[] suggestions, DefaultDialogueGiver giver) { GameObject.Find("Viewport").GetComponent <Image>().enabled = true; GameObject.Find("Scroll View").GetComponent <Image>().enabled = true; foreach (Text t in _suggestionsTexts) { if (t != null && t.gameObject != null) { Destroy(t.gameObject); } } ShowAnswer(); _answer.text = $"[{name}]: {answer}"; RectTransform rectAnswer = _answer.GetComponent <RectTransform>(); if (answer.Length != 0) { yield return(new WaitForSeconds(TimeForSpeech)); } else { onNoAnswer(); } _suggestionsTexts = new Text[suggestions.Length]; _suggestionsList.GetComponent <RectTransform>().sizeDelta = new Vector2(_suggestionsList.GetComponent <RectTransform>().sizeDelta.x, 100 * _suggestionsTexts.Length); for (int i = 0; i < _suggestionsTexts.Length; i++) { int index = i; _suggestionsTexts[index] = new GameObject($"Line {index}").AddComponent <Text>(); _suggestionsTexts[index].transform.parent = _suggestionsList.transform; _suggestionsTexts[index].transform.localScale = Vector3.one; _suggestionsTexts[index].text = $"- {suggestions[index]}"; _suggestionsTexts[index].color = Color.white; _suggestionsTexts[index].font = font; _suggestionsTexts[index].fontSize = 48; _suggestionsTexts[index].gameObject.AddComponent <Button>().onClick.AddListener( () => { giver.GiveAnswerSafe(index); }); } if (suggestions.Length == 0) { onNoSuggestions(); } /*float canvasWidth = _menuCanvas.GetComponent<RectTransform>().sizeDelta.x; * _suggestionsList.GetComponent<RectTransform>().sizeDelta = new Vector2(canvasWidth - AnswerMargin * 2, _suggestionsTexts.Length * CellHeight); * _suggestionsList.cellSize = new Vector2(canvasWidth - AnswerMargin * 2, CellHeight);*/ ShowSuggestions(); }
public void IterateDialogue(string name, string answer, string[] suggestions, DefaultDialogueGiver giver) { _dialogueIteration = IterateDialogueCoroutine(name, answer, suggestions, giver); StartCoroutine(_dialogueIteration); }