public void DoAction(VIDE_Data.NodeData data) { switch (data.extraData) { case "item": //npcCommentIndex refers to the current NPC's comment when there are many in a single Node (when you use <br>) if (data.npcCommentIndex == 1) { if (!itemText.activeSelf) { itemText.SetActive(true); gotItem = true; } else { itemText.SetActive(false); dialogue.Next(); } } else { dialogue.Next(); } break; case "insanity": //This will override the Dialogue's Start Node and use this one instead dialogue.assigned.overrideStartNode = 16; dialogue.Next(); break; } }
//Very simple text animation usin StringBuilder public IEnumerator AnimateText(VIDE_Data.NodeData data) { animatingText = true; string text = data.npcComment[data.npcCommentIndex]; if (!data.currentIsPlayer) { StringBuilder builder = new StringBuilder(); int charIndex = 0; while (npcText.text != text) { if (!animatingText) { break; //CallNext() makes this possible to speed things up } builder.Append(text[charIndex]); charIndex++; npcText.text = builder.ToString(); yield return(new WaitForSeconds(0.02f)); } } npcText.text = data.npcComment[data.npcCommentIndex]; //Now just copy full text animatingText = false; }
//This will replace any "[NAME]" with the name of the gameobject holding the VIDE_Assign void ItemLookUp(VIDE_Data.NodeData data) { if (data.npcCommentIndex == 0) { data.npcComment[data.npcCommentIndex] = data.npcComment[data.npcCommentIndex].Replace("[NAME]", dialogue.assigned.gameObject.name); } }
//Check to see if there's extraData and if so, we do stuff bool ExtraVariablesLookUp(VIDE_Data.NodeData data, bool PreCall) { //Don't conduct extra variable actions if we are waiting on a paused action if (data.pausedAction) { return(false); } if (!data.currentIsPlayer) //For player nodes { //Check for extra variables //This one finds a key named "item" which has the value of the item thats gonna be given //If there's an 'item' key, then we will assume there's also an 'itemLine' key and use it if (PreCall) //Checks that happen right before calling the next node { if (data.extraVars.ContainsKey("item") && !data.dirty) { if (data.npcCommentIndex == (int)data.extraVars["itemLine"]) { if (data.extraVars.ContainsKey("item++")) //If we have this key, we use it to increment the value of 'item' by 'item++' { Dictionary <string, object> newVars = data.extraVars; //Clone the current extraVars content int newItem = (int)newVars["item"]; //Retrieve the value we want to change newItem += (int)data.extraVars["item++"]; //Change it as we desire newVars["item"] = newItem; //Set it back VIDE_Data.UpdateExtraVariables(25, newVars); //Send newVars through UpdateExtraVariable method } //If it's CrazyCap, check his stock before continuing //If out of stock, change override start node if (VIDE_Data.assigned.alias == "CrazyCap") { if ((int)data.extraVars["item"] + 1 >= example_Items.Count) { VIDE_Data.assigned.overrideStartNode = 28; } } if (!example_ItemInventory.Contains(example_Items[(int)data.extraVars["item"]])) { GiveItem((int)data.extraVars["item"]); return(true); } } } } if (data.extraVars.ContainsKey("nameLookUp")) { nameLookUp(data); } } else //for NPC nodes { //Nothing here yet ¯\_(ツ)_/¯ } return(false); }
//Unsuscribe from everything, disable UI, and end dialogue void EndDialogue(VIDE_Data.NodeData data) { VIDE_Data.OnActionNode -= ActionHandler; VIDE_Data.OnNodeChange -= NodeChangeAction; VIDE_Data.OnEnd -= EndDialogue; uiContainer.SetActive(false); VIDE_Data.EndDialogue(); }
public void EndConversation(VIDE_Data.NodeData data) { _currentDialogue.OnActionNode -= ActionHandler; _currentDialogue.OnNodeChange -= NodeChangeAction; _currentDialogue.OnEnd -= EndConversation; SetPlayerControllerActive(true); _currentDialogue.EndDialogue(); UIRoot.SetActive(false); }
//This will replace any "[NAME]" with the name of the gameobject holding the VIDE_Assign //Will also replace [WEAPON] with a different variable void nameLookUp(VIDE_Data.NodeData data) { if (data.npcComment[data.npcCommentIndex].Contains("[NAME]")) { data.npcComment[data.npcCommentIndex] = data.npcComment[data.npcCommentIndex].Replace("[NAME]", VIDE_Data.assigned.gameObject.name); } if (data.npcComment[data.npcCommentIndex].Contains("[WEAPON]")) { data.npcComment[data.npcCommentIndex] = data.npcComment[data.npcCommentIndex].Replace("[WEAPON]", example_ItemInventory[0]); } }
void NodeChangeAction(VIDE_Data.NodeData data) { if (data.currentIsPlayer) { SpeakerNameField.text = PlayerName; } else { SpeakerNameField.text = _currentDialogue.assigned.dialogueName; ConversationBox.text = data.npcComment[data.npcCommentIndex]; } SetAnswers(data.playerComments); }
//Check to see if there's extraData and if so, we do stuff bool ExtraDataLookUp(VIDE_Data.NodeData data) { if (!data.currentIsPlayer && !data.pausedAction) { //This whole chunk will read the X_item_X nomenclature, parse it, and use the information if (data.extraData.Contains("_item_")) { int[] lineAndIndex = ParseItem(data.extraData); if (data.npcCommentIndex == lineAndIndex[0]) { if (!example_ItemInventory.Contains(example_Items[lineAndIndex[1]])) { GiveItem(lineAndIndex[1]); return(true); } } } } return(false); }
void NodeChangeAction(VIDE_Data.NodeData data) { foreach (Text text in currentOptions) { Destroy(text); } currentOptions = new List <Text>(); currentOptionsAsGameObjects = new List <GameObject>(); if (data.currentIsPlayer) { playerLines = new string[data.playerComments.Length]; currentOptionsAsGameObjects = new List <GameObject>(); for (int i = 0; i < data.playerComments.Length; i++) { GameObject newLine = Instantiate(playerDialogue.gameObject, playerDialogue.transform.position, Quaternion.identity); newLine.SetActive(true); newLine.transform.SetParent(playerDialogue.transform.parent, true); newLine.GetComponent <RectTransform>().anchoredPosition = new Vector2(0, 30 - (30 * (i + 1))); newLine.GetComponent <Text>().text = data.playerComments[i]; currentOptions.Add(newLine.GetComponent <Text>()); } foreach (Text option in currentOptions) { //Vector3[] corners = new Vector3[4]; //option.gameObject.GetComponent<RectTransform>().GetWorldCorners(corners); currentOptionsAsGameObjects.Add(option.gameObject); } } if (!data.currentIsPlayer) { aiDialogue.text = VIDE_Data.nodeData.npcComment[data.npcCommentIndex]; } }
//We listen to OnNodeChange to update our UI with each new nodeData //This should happen right after calling VIDE_Data.Next() void NodeChangeAction(VIDE_Data.NodeData data) { //Reset some variables npcText.text = ""; npcText.transform.parent.gameObject.SetActive(false); playerText.transform.parent.gameObject.SetActive(false); //Look for dynamic text change in extraData if (data.extraData == "nameLookUp") { nameLookUp(data); } //If this new Node is a Player Node, set the player choices offered by the node if (data.currentIsPlayer) { SetOptions(data.playerComments); playerText.transform.parent.gameObject.SetActive(true); } else //If it's an NPC Node, let's just update NPC's text { StartCoroutine(AnimateText(data)); //If it has a tag, show it, otherwise show the dialogueName if (data.tag.Length > 0) { npcName.text = data.tag; } else { npcName.text = dialogue.assigned.dialogueName; } npcText.transform.parent.gameObject.SetActive(true); } }
void RelicLookUp(VIDE_Data.NodeData data) { QuestItemScrpt test = FindObjectOfType <QuestItemScrpt>(); data.npcComment[data.npcCommentIndex] = data.npcComment[data.npcCommentIndex].Replace("[RELIC]", (test.m_numberOfRelics - test.getCurrenNumOfQuestItems()).ToString()); }
//A method to handle extraDatas and do something with them. //Note that it is easier to call methods now with the Action node. public bool DoAction(VIDE_Data.NodeData data) { bool didAction = false; return(didAction); }
//We listen to OnNodeChange to update our UI with each new nodeData //This should happen right after calling VIDE_Data.Next() void NodeChangeAction(VIDE_Data.NodeData data) { //Reset some variables npcText.text = ""; npcText.transform.parent.gameObject.SetActive(false); playerText.transform.parent.gameObject.SetActive(false); PlayerSprite.sprite = null; NPCSprite.sprite = null; //Look for dynamic text change in extraData ExtraVariablesLookUp(data, false); //If this new Node is a Player Node, set the player choices offered by the node if (data.currentIsPlayer) { //Set node sprite if there's any, otherwise try to use default sprite if (data.nodeSprite != null) { PlayerSprite.sprite = data.nodeSprite; } else if (VIDE_Data.assigned.defaultPlayerSprite != null) { PlayerSprite.sprite = VIDE_Data.assigned.defaultPlayerSprite; } SetOptions(data.playerComments); playerText.transform.parent.gameObject.SetActive(true); } else //If it's an NPC Node, let's just update NPC's text and sprite { //Set node sprite if there's any, otherwise try to use default sprite if (data.nodeSprite != null) { //For NPC sprite, we'll first check if there's any "sprite" key //Such key is being used to apply the nodeSprite only when at a certain comment index //Check CrazyCap dialogue for reference if (data.extraVars.ContainsKey("sprite")) { if (data.npcCommentIndex == (int)data.extraVars["sprite"]) { NPCSprite.sprite = data.nodeSprite; } else { NPCSprite.sprite = VIDE_Data.assigned.defaultNPCSprite; //If not there yet, set default dialogue sprite } } else { NPCSprite.sprite = data.nodeSprite; } } else if (VIDE_Data.assigned.defaultNPCSprite != null) { NPCSprite.sprite = VIDE_Data.assigned.defaultNPCSprite; } StartCoroutine(AnimateText(data)); //If it has a tag, show it, otherwise show the dialogueName if (data.tag.Length > 0) { npcName.text = data.tag; } else { npcName.text = VIDE_Data.assigned.alias; } npcText.transform.parent.gameObject.SetActive(true); } }