Hello, I’m trying to implement a dialogue system for a game. I’m going to use xml cause I want the dialogues to be editable/added from outside of Unity. It’s the first time that I work with xml, but I already used serialize to read a xml successfully. Now I got 2 questions.
-
Say we have this class:
public class Character {
public string name;
public float strength;
public float vitality;
}
EDIT: And an XML file like this(just a sketch):
<Dialog>
<Option params = "0" value = "20" operator= "greaterThan">
<Line text="Hello, #CharacterName"/>
</Option>
</Dialog>
The attributes in Option means, for the parameter 0, have a value greater than 20. Where parameter 0 is the character’s strength. Is there way I can tell unity(or c# in this case) that 0 = Character.strength without resorting to something like a switch(cause I plan to have many more stats)? I’m looking for the best way to do it, cause probably I ignore it, so far I thought of switch or changing the numbers for words and using a dictionary. ENDOFEDIT.
- This time I have a dialogue line,where an NPC says “Hello, ‘CharacterName’”. It will be imported from the xml as a string, so, when parsing. How can I replace that’ CharacterName for Character.name? I don’t think searching for a special character on every dialog line to replace the word after it is the best approach.
Sorry for the long question and if it doesn’t belong here just say so. Thanks for reading.