public void displayText(string unsplitLine) { NPCFaceRenderer.sprite = currentNode.getSprite(); string[] dialogue = unsplitLine.Split('|'); textBox.text = dialogue[0]; if (currentNode.getName() != "") { nameBox.text = currentNode.getName(); } if (currentButtonLayout != null) { currentButtonLayout.disableChildren(); } if (currentNode.getNumButtons() != 0 && currentNode.getNextNode() == -1) { //Well so much for elegance. To get the buttons to spawn on top of the text box and other things they need to be below them in the heirarcy //Before chilcount - 1 was pretty perfect, but now we use childcount + 2 because there are 3 more objects on top of the button layouts currentButtonLayout = transform.GetChild(currentNode.getNumButtons() + 2).gameObject.GetComponent <DisableButtonChildren>(); } else { currentButtonLayout = transform.GetChild(3).gameObject.GetComponent <DisableButtonChildren>(); } //didn't use foreach here because (reason) if (currentNode.getNextNode() == -1) { if (dialogue.Length > 1) { //didn't use foreach here because (reason) for (int i = 0; i < currentNode.getChildCount() && i + 1 < dialogue.Length; i++) { currentButtonLayout.transform.GetChild(i).GetComponentInChildren <Text>().text = dialogue[i + 1]; } } else { currentButtonLayout.transform.GetChild(0).GetComponentInChildren <Text>().text = ""; } } else { if (dialogue.Length > 1) { currentButtonLayout.transform.GetChild(0).GetComponentInChildren <Text>().text = dialogue[1]; } else { currentButtonLayout.transform.GetChild(0).GetComponentInChildren <Text>().text = ""; } } currentButtonLayout.enableChidlren(); }
///<summary>Start a dialogue with the existing tree and without disabling anything. ///This is mostly used for colliders, where we still want them to have collision but we don't want it to stop interacting entirely ///</summary> public void startDialogue() { gameObject.GetComponent <Canvas>().enabled = true; gameObject.GetComponent <GraphicRaycaster>().enabled = true; //Prevent the player from moving while they're in dialogue player.GetComponent <CustomPlatformer2DUserControl>().canControl = false; player.GetComponentInChildren <Animator>().SetFloat("Speed", 0f); player.GetComponent <Rigidbody2D>().velocity = Vector3.zero; currentNode = dialogueTree.getNodeAtIndex(1); currentButtonLayout = null; displayText(currentNode.getLine()); }
public void startDialogue(TextAsset dialogue, Collider2D triggerToDisable, Sprite NPCSprite) { triggeredThis = triggerToDisable; triggeredThis.enabled = false; gameObject.GetComponent <Canvas>().enabled = true; gameObject.GetComponent <GraphicRaycaster>().enabled = true; //Prevent the player from moving while they're in dialogue player.GetComponent <CustomPlatformer2DUserControl>().canControl = false; player.GetComponentInChildren <Animator>().SetFloat("Speed", 0f); player.GetComponent <Rigidbody2D>().velocity = Vector3.zero; dialogueTextAsset = dialogue; dialogueTree = new dialogueTree(dialogue.text, dialogueEvent, NPCSprite); currentNode = dialogueTree.getNodeAtIndex(1); currentButtonLayout = null; displayText(currentNode.getLine()); }