Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mbastias · Feb 18, 2015 at 11:14 PM · c#xmldialogue

XML and dialogues.

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cherno · Feb 19, 2015 at 12:31 AM

As for telling Unity which XML value is which variable, that would all be handlded directly in your class:

 [XmlElement("name")]
 public string name;
 [XmlElement("strength")]
 public float strength;
 [XmlElement("vitality")]
 public float vitality;


As for replacing the Charactername with the actual name, remember that you the simple string type has some fairly complex and powerful features: You can, for example, check if it contains a word or order of characters via string.Contains, or replace characters at defined positions with string.Remove, and so on. Just check on the MSDN: String Class for what will help you in the best way. If you don't want to search for a character inside each dialogue string in the game, you could create a copy of the diaolgue XML file when a new campaign is started, and then go through that XML file via script and replace all occurences directly in the file, save it, and then use this file to parse.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mbastias · Feb 19, 2015 at 12:48 AM 0
Share

O$$anonymous$$, so for the second point there was no other way than my first thought. For the first one it seems I'll need to edit my question cause is not clear enough as it is. Thanks for the answer.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Trouble updating old Unity syntax 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How To Switch A XmlNodeList To A String 1 Answer

Dtd validation with TextAsset xml gives exception 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges