private void BuildChoiceList() { choiceCount = 0; foreach (DialogueNode choiceNode in playerConversant.GetChoices()) { Button button; if (choiceButtons.Count > choiceCount) { button = choiceButtons[choiceCount]; button.gameObject.SetActive(true); } else { GameObject choiceInstance = Instantiate(choicePrefab, choiceRoot); button = choiceInstance.GetComponent <Button>(); choiceButtons.Add(button); } button.onClick.AddListener(() => { isWaitingOnChoice = false; playerConversant.SelectChoice(choiceNode); SetupTextboxGroup(); ReturnChoicesToPool(); }); TextMeshProUGUI buttonTextComponent = button.GetComponentInChildren <TextMeshProUGUI>(); buttonTextComponent.text = ReplaceSubstringVariables(choiceNode.GetText()); choiceCount++; } speakerContainer.SetActive(false); textContainer.SetActive(false); choiceRoot.gameObject.SetActive(true); isWaitingOnChoice = true; }
private void BuildChoiceList() { foreach (Transform item in choiceRoot) { Destroy(item.gameObject); } foreach (DialogueNode choice in playerConversant.GetChoices()) { GameObject choiceInstance = Instantiate(choicePreFab, choiceRoot); foreach (Transform child in choiceInstance.transform) { child.gameObject.SetActive(true); } var textComp = choiceInstance.GetComponentInChildren <TextMeshProUGUI>(); textComp.text = choice.GetText(); Button button = choiceInstance.GetComponentInChildren <Button>(); button.gameObject.SetActive(true); button.onClick.AddListener(() => { playerConversant.SelectChoice(choice); UpdateUI(); }); } }
private void BuildChoiceList() { choiceRoot.Clear(); foreach (DialogueNode choice in playerConversant.GetChoices()) { GameObject choiceInstance = Instantiate(choicePrefab, choiceRoot); choiceInstance.GetComponentInChildren <TextMeshProUGUI>().text = choice.GetText(); Button button = choiceInstance.GetComponent <Button>(); button.onClick.AddListener(() => { playerConversant.SelectChoice(choice); }); } }
private void BuildChoiceList() { playerResponse.transform.DetachChildren(); foreach (DialogueNode choice in playerConversant.GetChoices()) { Button b = Instantiate(choiceButtonPrefab, playerResponse.transform); b.GetComponentInChildren <TMP_Text>().text = choice.Text; b.onClick.AddListener(() => { playerConversant.SelectChoice(choice); } ); } }
private void BuildChoiceList() { foreach (Transform child in choiceRoot) { Destroy(child.gameObject); } foreach (DialogueNode node in _player.GetChoices()) { DialogueChoiceUI dialogueChoice = Instantiate(choicePrefab, choiceRoot); dialogueChoice.SetText(node.Text); Button button = dialogueChoice.GetButton(); button.onClick.AddListener(() => _player.SelectChoice(node)); } }
private void BuildChoiceList() { foreach (Transform item in choiceRoot) { Destroy(item.gameObject); } foreach (DialogueNode choice in _playerConversant.GetChoices()) { GameObject newChoice = Instantiate(choicePrefab, choiceRoot); newChoice.GetComponentInChildren <TextMeshProUGUI>().text = choice.GetText(); Button button = newChoice.GetComponentInChildren <Button>(); button.onClick.AddListener(() => { _playerConversant.SelectChoice(choice); }); } }
private void BuildChoiceList() { foreach (Transform child in choiceRoot) { Destroy(child.gameObject); } foreach (DialogueNode choice in playerConversant.GetChoices()) { GameObject choiceInstance = Instantiate(choicePrefab, choiceRoot); var textComponent = choiceInstance.GetComponentInChildren <TextMeshProUGUI>(); textComponent.text = choice.GetDialogueText(); Button button = choiceInstance.GetComponentInChildren <Button>(); button.onClick.AddListener(() => { playerConversant.SelectChoice(choice); }); } }
/// <summary> /// Will update the values of each component and the visibility of the three buttons in function of the number of choices available /// </summary> void UpdateUI() { if (playerConversant == null) { return; } this.gameObject.SetActive(playerConversant.isActive()); if (!playerConversant.isActive()) { return; } currentSpeaker.text = playerConversant.GetCurrentConversant(); dialogueText.text = playerConversant.GetText(); List <string> choices = playerConversant.GetChoices(); closeButton.activate(true); closeButton.gameObject.SetActive(true); if (choices != null && choices.Count > 0) { if (choices.Count >= 3) { choice3Button.activate(true); choice3Button.gameObject.SetActive(true); choice3Button.GetComponentInChildren <TextMeshProUGUI>().text = choices[2]; } else { choice3Button.activate(false); choice3Button.gameObject.SetActive(false); } if (choices.Count >= 2) { choice2Button.activate(true); choice2Button.gameObject.SetActive(true); choice2Button.GetComponentInChildren <TextMeshProUGUI>().text = choices[1]; } else { choice2Button.activate(false); choice2Button.gameObject.SetActive(false); } if (choices.Count >= 1) { choice1Button.activate(true); choice1Button.gameObject.SetActive(true); choice1Button.GetComponentInChildren <TextMeshProUGUI>().text = choices[0]; GetComponent <UIStateMachine>().changeActiveObject(choice1Button); } } else { choice1Button.activate(false); choice2Button.activate(false); choice3Button.activate(false); choice1Button.gameObject.SetActive(false); choice2Button.gameObject.SetActive(false); GetComponent <UIStateMachine>().changeActiveObject(closeButton); choice3Button.gameObject.SetActive(false); } }