void Display(string node) { //Debug.Log("display dialog"); line = dlg.GetNode (node); //Debug.Log (line.text); NPCText.GetComponent<Text> ().text = line.text; options = dlg.GetAnswers (line.answers); //now create the list of choices int count = 0; buttons = new List<GameObject> (); foreach (KeyValuePair<string, PlayerLine> pl in options) { var go = Instantiate(ButtonPrefab); go.name = pl.Key; var rt = go.GetComponent<RectTransform>(); rt.SetParent(gameObject.transform); rt.anchoredPosition = new Vector2(10,-80-count*32); count++; foreach (Transform bText in go.GetComponentsInChildren<Transform>()) { if (bText.name == "Text") { bText.GetComponent<Text>().text = pl.Value.text; } } //setup the event handler var b = go.GetComponent<Button>(); b.onClick.AddListener(() => MouseClick(go)); buttons.Add(go); } }
void SerializeJson() { //Get all the presentation lines fitting with the current scene string scene = Application.loadedLevelName; string json = DataReader.GetAllText ("Assets/"+ scene +"cs.json"); //Convert the lines data to a managable format JSONNode data = JSON.Parse (json); var cutsjs = data ["scenes"]; _cutscenes = new Dictionary<string, SceneModel> (); //Loop trough all sentences and place them in the _lines member for (int i = 0; i < cutsjs.Count; i++) { var cutscenejs = cutsjs [i]; string key = cutscenejs["SceneName"]; var cutscene = new List<Interaction>(); var interactions = cutscenejs["Interaction"]; //Loop through interactions for(int j = 0; j < interactions.Count; j++) { var interaction = interactions[j]; //Check what kind of interaction it is Interaction part = null; switch (interaction["Type"]) { case "Event": part = SceneEvent.GetScript(interaction["ScriptKey"], interaction["Duration"].AsFloat); break; case "NPCLine": part = new NPCLine(interaction["NpcName"], interaction["VoiceKey"], interaction["Duration"].AsFloat); break; case "PlayerLine": part = new PlayerLine(interaction["Hint"], interaction["Duration"].AsFloat, GoToNextPart); break; } if(part == null) throw new Exception("JSON format exception in cutscene controller. Unknown type used. Input: " + interaction["Type"]); if(part != null) cutscene.Add(part); } _cutscenes.Add(key, new SceneModel(cutscenejs["Range"].AsFloat ,cutscene)); } }
/** * Receives a node and starts parsing from there, returning */ public NPCLine GetNode(string id) { NPCLine retval = new NPCLine(); XmlNodeList root = doc.SelectNodes ("dialog/node"); foreach (XmlNode node in root) { if (node.Attributes.GetNamedItem("id").Value==id) { //parse the lines XmlNodeList lines = node.ChildNodes; foreach (XmlNode line in lines) { //Debug.Log("NPC line"+line.InnerText); //validate checks if (line.Attributes.GetNamedItem("check")!=null) { string check = line.Attributes.GetNamedItem("check").Value; string value = line.Attributes.GetNamedItem("value").Value; string eval = line.Attributes.GetNamedItem("eval").Value; if (check=="HasQuest") { //check if player has quest if (player.GetQuestStatus(value)==eval) { //this is the line retval.text = line.InnerText; retval.answers = line.Attributes.GetNamedItem("answers").Value; return retval; } //break; } else if (check=="HasItem") { } //if checks } else { //has no checks Debug.Log("NPC line has no checks "+line.InnerText); retval.text = line.InnerText; retval.answers = line.Attributes.GetNamedItem("answers").Value; return retval; }//if check } //for each line //Debug.Log("NPC line"+NPCline); } }//foeach node return null; }