// Use this for initialization void Start() { playerStatistics = GameObject.Find(GameConst.PLAYER_OBJECT_NAME).GetComponent <PlayerStatistics>(); dialogueEvent = GameObject.Find("Dialogue Canvas").GetComponent <DialogueManager>().dialogueEvent; //UnityEventTools.AddPersistentListener<int>(dialogueEvent, dialogueEventHandler); dialogueEvent.AddListener(dialogueEventHandler); }
// Use this for initialization void Start() { dialogueManager = GameObject.Find("Dialogue Canvas").GetComponent <DialogueManager>(); dialogueEvent = dialogueManager.dialogueEvent; //UnityEventTools.AddPersistentListener<int>(dialogueEvent, dialogueEventHandler); dialogueEvent.AddListener(dialogueEventHandler); //dialogueEvent.AddListener((int i) => { Debug.Log("Event triggered index of: " + i); }); }
public nodeTextLine(string text, int index, Sprite defaultSprite) { List <string> temp = new List <string>(text.Split('|')); name = temp[0]; temp.RemoveAt(0); line = string.Join("|", temp.ToArray()); //Parse the rest of the List<string> as a single string, replacing the delimiter that was removed with the first 'split' call Debug.Log(line); treeIndex = index; triggeredEvent = null; spriteToDisplay = defaultSprite; }
public dialogueTree(string fullDialogueText, nodeEvent nodeEvent, Sprite defaultSprite) { managerEvent = nodeEvent; string[] dialogueLines = fullDialogueText.Split('\n'); string[] encoding = dialogueLines[0].Split('-'); nodeTextLine currentParentNode; //Because of the extra encoding data line we offset the list by adding a blank constructor so the index of the object in the list is the same as the index of the line in the raw text file treeMember.Add(new nodeTextLine()); //We also have to add the first real node because the code works by making the correct amount of children for each node and it needs a parent node to start on //We don't have to worry about creating it's children yet because it starts on this object and makes children from there treeMember.Add(new nodeTextLine(dialogueLines[currentChildIndex], currentChildIndex++, defaultSprite)); //Encoding[0] is the encoded tree structure. First we take the layers foreach (string treeLayer in encoding[0].Split('|')) { //Then for each layer we split it again to get the individual nodes foreach (string sNumChildren in treeLayer.Split(':')) { currentParentNode = treeMember[currentParentIndex++]; //The number tells us how many children to make, so we parse the string into an int and make children for (int numChildren = int.Parse(sNumChildren); numChildren > 0; numChildren--) { treeMember.Add(new nodeTextLine(dialogueLines[currentChildIndex], currentChildIndex, defaultSprite)); currentParentNode.addChild(treeMember[currentChildIndex++]); } currentParentNode.setNumButtons(currentParentNode.getChildCount()); //Prints out every member in order with children indexes, very useful for debugging //Debug.Log(currentParentNode); } } //Encoding[1] has the nodes to add events to if (encoding.Length > 1) { foreach (string nodeWithEvent in encoding[1].Split(':')) { getNodeAtIndex(int.Parse(nodeWithEvent)).setEvent(managerEvent); } } }
public void setEvent(nodeEvent managerEvent) { triggeredEvent = managerEvent; }