/* * public DialogueHead DeserializeXMLDialogueLinq(TextAsset xmlDialogue){ * string xmlString = xmlDialogue.text; * * Assembly assem = Assembly.GetExecutingAssembly (); * XDocument xDoc = XDocument.Load (new StreamReader (xmlString)); * * DialogueHead dialogue = new DialogueHead(); * dialogue.NPCName = xDoc.Element("NPCName").Value; * dialogue.FirstLineId = Int32.Parse(xDoc.Element("FirstLineId").Value); * * dialogue.dialogueElements = xDoc.Descendants("DialogueElement").Select(element => { * string typeName = element.Attribute("Type").Value; * var type = assem.GetTypes().Where(t => t.Name == typeName).First(); * DialogueElement e = Activator.CreateInstance(type) as DialogueElement; * foreach(var property in element.Descendants()){ * type.GetProperty(property.Name.LocalName).SetValue(e, property.Value, null); * } * return e; * }).ToArray(); * * return dialogue; * } */ public DialogueHead DeserializeXMLDialogueLinq(string xmlDialoguePath) { //string xmlString = xmlDialogue.text; Assembly assem = Assembly.GetExecutingAssembly(); XDocument xDoc = XDocument.Load(UnityEngine.Application.dataPath + xmlDialoguePath); DialogueHead dialogue = new DialogueHead(); //Debug.Log (xDoc.Element("NPCName").Value); dialogue.NPCName = xDoc.Descendants("NPCName").First().Value; dialogue.FirstLineId = Int32.Parse(xDoc.Descendants("FirstLineId").First().Value); dialogue.dialogueElements = xDoc.Descendants("DialogueElement").Select(element => { string typeName = element.Attribute("Type").Value; var type = assem.GetTypes().Where(t => t.Name == typeName).First(); DialogueElement e = Activator.CreateInstance(type) as DialogueElement; Debug.Log("pass 0"); foreach (var property in element.Descendants()) { if (property.Name != "value") { var setProp = type.GetProperty(property.Name.LocalName); if (setProp.PropertyType.IsArray) { Debug.Log("Pass 1"); if (setProp.Name.Contains("Id")) { int[] i = property.Descendants("value").Select(v => { return(Int32.Parse(v.Value)); }).ToArray(); Debug.Log(i); setProp.SetValue(e, i, null); } else { string[] s = property.Descendants("value").Select(v => v.Value).ToArray(); setProp.SetValue(e, s, null); Debug.Log("Pass 2"); } } else { if (setProp.Name.Contains("Id")) { setProp.SetValue(e, Int32.Parse(property.Value), null); } else { setProp.SetValue(e, property.Value, null); } } } } return(e); }).ToArray(); return(dialogue); }
// Use this for initialization void Start() { gameDriver = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameDriver> (); dialogueHead = gameDriver.DeserializeXMLDialogueLinq(dialogueXMLPath); //dialogueHead.SetHeadToLines (); //dialogueHead.SetLines (); Debug.Log(dialogueHead.FirstLineId); Debug.Log(dialogueHead.NPCName); interactSprite.SetActive(false); }
/* * public int DialogueLength{ * get{ return currentDialogue.Length; } * set { currentDialogue.Length = value; } * } */ public void StartDialogue() { gameState = GameState.Dialogue; /* * DeserializeXMLDialogue (npcTarget.dialogueXMLPath); * if (gameState == GameState.Dialogue) { * speakerName.text = currentDialogue.Speaker; * dialogueText.text = currentDialogue.Speech [0]; * currentLine = 0; * dialogueBox.SetActive (true); * } */ if (npcTarget != null) { if (npcTarget.dialogueHead != null) { currentDialogue = npcTarget.dialogueHead; currentLine = currentDialogue.FindLineById(currentDialogue.FirstLineId); dialogueBox.SetActive(true); HandleDialogue(); } } }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("DialogueCharacterPlayer").GetComponent <DialogueHead>(); other = GetComponent <DialogueHead>(); }