void PlayNode() { UpdateEvents(); Type nodeType = currentNode.GetType(); if (nodeType == typeof(TextNode)) { TextNode tNode = currentNode as TextNode; UIManager.instance.ShowText(tNode); } if (nodeType == typeof(BranchNode)) { BranchNode bNode = currentNode as BranchNode; currentNode = bNode.GetNextNode(); PlayNode(); } if (nodeType == typeof(ChoiceNode)) { ChoiceNode cNode = currentNode as ChoiceNode; List <Node> availableNodes = cNode.GetValidNodes(); UIManager.instance.ShowPlayerOptions(availableNodes); } if (nodeType == typeof(CustomNode)) { PlayCustomNode(); } }
public void ShowPlayerOptions(List <Node> options) { for (int i = 0; i < playerOptionsPanel.transform.childCount; i++) { Destroy(playerOptionsPanel.transform.GetChild(i).gameObject); } float totalItemHeight = 0f; for (int i = 0; i < options.Count; i++) { Node n = options[i]; if (n.GetType() == typeof(BranchNode)) { BranchNode bNode = n as BranchNode; n = bNode.GetNextNode(); } PlayerChoiceButton buttonOption = Instantiate(playerChoiceItemPrefab); buttonOption.nodeId = n.id; buttonOption.textComponent.text = LocalizationManager.instance.GetLocalizedValue(n.id); buttonOption.gameObject.name = "Button option " + i; buttonOption.transform.SetParent(playerOptionsPanel.transform, false); totalItemHeight += buttonOption.GetComponent <RectTransform>().sizeDelta.y; if (i == 0) { EventSystem.current.SetSelectedGameObject(null); StartCoroutine(SetSelectedGameObjectNextFrame(buttonOption.gameObject)); } } Vector2 sizeDelta = playerOptionsPanel.sizeDelta; sizeDelta.y = totalItemHeight + (options.Count - 1) * playerOptionsPanel.GetComponent <VerticalLayoutGroup>().spacing; playerOptionsPanel.sizeDelta = sizeDelta; if (!playerPanel.activeSelf) { AudioManager.instance.PlaySfxForCharacter("player"); AnimatePanelIn(playerPanel, "player"); } playerMessageText.gameObject.SetActive(false); playerOptionsScrollPane.gameObject.SetActive(true); }