//End Get and Set methods //Parses a dialogue tree from an XML string. The resulting dialogues are stored as a hash map in diaHash (<string title>, //<DialogueObject>). These are displayed in the OnGUI function - edit there if you want to change their display. This //function just creates the hashMap and the Objects inside it. //XML tags: //<XML> - encloses the document // <DOb name = "name"> - encloses a piece of dialogue; name is how this dialogue piece is referenced // <DText> - encloses the text for this piece of dialogue, it is assummed that DOb will have exactly 1 of these // the text // </DText> // <DOp (GoTo="name")> - encloses a response to the dialogue which is selectable by the player; GoTo is a reference // to a DOb name, it is where the dialogue will go when this response is selected, it is optional // <DResp> - encloses the text for this response, it is assumed that DOp will have exactly 1 of these // the text // </DResp> // <Com Obj="name" Fn="name" (Par="par" (ParType = "type"))/> - represents a command to be executed // Obj - the name of the GameObject which has the script containing the function attached. This is *not* // the name of the script // Fn - the name of the function to be called (such as "setScreenWidth"). Do not include parentheses. // Par - Optional, a parameter to be passed to the fn. This must be in string form, and convertable to // the desired type from a string // ParType - Optional, what type to convert Par to. If not specified, it assumed that it should remain // a string. Possible values: // "i" - convert to int // "f" - convert to float // "b" - convert to bool // </DOp> // </DOb> //</XML> public void parseDialogueTree(string XML) { PT_XMLHashtable xht; int tempCount; int tempCount2; string[][] commands; DiaOptObj[] tempdoo; DialogueObj tempdob; reader.Parse(XML); xht = reader.xml["XML"][0]; foreach(PT_XMLHashtable DOBxht in xht["DOb"]){ tempdob = new DialogueObj(); tempdob.text = DOBxht["DText"][0].text; if(DOBxht.HasKey("DOp")){ tempdoo = new DiaOptObj[DOBxht["DOp"].Count]; tempCount = 0; foreach(PT_XMLHashtable DOPxht in DOBxht["DOp"]){ tempdoo[tempCount] = new DiaOptObj(); tempdoo[tempCount].response = DOPxht["DResp"][0].text; if(DOPxht.ContainsAtt("GoTo")){ tempdoo[tempCount].GoTo = DOPxht.att("GoTo"); } if(DOPxht.HasKey("Com")){ commands = new string[DOPxht["Com"].Count][]; tempCount2 = 0; foreach(PT_XMLHashtable option in DOPxht["Com"]){ if(option.HasAtt("ParType")){ commands[tempCount2] = new string[4]; commands[tempCount2][3] = option.att("ParType"); commands[tempCount2][2] = option.att ("Par"); }else if(option.HasAtt("Par")){ commands[tempCount2] = new string[3]; commands[tempCount2][2] = option.att("Par"); }else{ commands[tempCount2] = new string[2]; } commands[tempCount2][0] = option.att("Obj"); commands[tempCount2][1] = option.att("Fn"); tempCount2++; } tempdoo[tempCount].commands = commands; } tempCount++; } tempdob.options = tempdoo; } diaHash.Add(DOBxht.att("name"),tempdob); } }
//End Get and Set methods //Parses a dialogue tree from an XML string. The resulting dialogues are stored as a hash map in diaHash (<string title>, //<DialogueObject>). These are displayed in the OnGUI function - edit there if you want to change their display. This //function just creates the hashMap and the Objects inside it. //XML tags: //<XML> - encloses the document // <DOb name = "name"> - encloses a piece of dialogue; name is how this dialogue piece is referenced // <DText> - encloses the text for this piece of dialogue, it is assummed that DOb will have exactly 1 of these // the text // </DText> // <DOp (GoTo="name")> - encloses a response to the dialogue which is selectable by the player; GoTo is a reference // to a DOb name, it is where the dialogue will go when this response is selected, it is optional // <DResp> - encloses the text for this response, it is assumed that DOp will have exactly 1 of these // the text // </DResp> // <Com Obj="name" Fn="name" (Par="par" (ParType = "type"))/> - represents a command to be executed // Obj - the name of the GameObject which has the script containing the function attached. This is *not* // the name of the script // Fn - the name of the function to be called (such as "setScreenWidth"). Do not include parentheses. // Par - Optional, a parameter to be passed to the fn. This must be in string form, and convertable to // the desired type from a string // ParType - Optional, what type to convert Par to. If not specified, it assumed that it should remain // a string. Possible values: // "i" - convert to int // "f" - convert to float // "b" - convert to bool // </DOp> // </DOb> //</XML> public void parseDialogueTree(string XML) { PT_XMLHashtable xht; int tempCount; int tempCount2; string[][] commands; DiaOptObj[] tempdoo; DialogueObj tempdob; reader.Parse(XML); xht = reader.xml["XML"][0]; foreach (PT_XMLHashtable DOBxht in xht["DOb"]) { tempdob = new DialogueObj(); tempdob.text = DOBxht["DText"][0].text; if (DOBxht.HasKey("DOp")) { tempdoo = new DiaOptObj[DOBxht["DOp"].Count]; tempCount = 0; foreach (PT_XMLHashtable DOPxht in DOBxht["DOp"]) { tempdoo[tempCount] = new DiaOptObj(); tempdoo[tempCount].response = DOPxht["DResp"][0].text; if (DOPxht.ContainsAtt("GoTo")) { tempdoo[tempCount].GoTo = DOPxht.att("GoTo"); } if (DOPxht.HasKey("Com")) { commands = new string[DOPxht["Com"].Count][]; tempCount2 = 0; foreach (PT_XMLHashtable option in DOPxht["Com"]) { if (option.HasAtt("ParType")) { commands[tempCount2] = new string[4]; commands[tempCount2][3] = option.att("ParType"); commands[tempCount2][2] = option.att("Par"); } else if (option.HasAtt("Par")) { commands[tempCount2] = new string[3]; commands[tempCount2][2] = option.att("Par"); } else { commands[tempCount2] = new string[2]; } commands[tempCount2][0] = option.att("Obj"); commands[tempCount2][1] = option.att("Fn"); tempCount2++; } tempdoo[tempCount].commands = commands; } tempCount++; } tempdob.options = tempdoo; } diaHash.Add(DOBxht.att("name"), tempdob); } }