Search Unity

Xml Tutorial On Unity Gems

Discussion in 'Made With Unity' started by whydoidoit, Feb 23, 2014.

  1. whydoidoit

    whydoidoit

    Joined:
    Mar 12, 2012
    Posts:
    365
    After a number of questions on Unity Answers concerning working with XML data we've published a new tutorial on Unity Gems covering how to easily use XML data to populate class hierarchies in Unity/C# in just a few lines of code.

    The article is available here.

    Unity Gems​
     
  2. jaybennett

    jaybennett

    Joined:
    Jul 10, 2012
    Posts:
    165
    Nice helper class, great article. You have some of the best unity programming tips on the web! I'm still using your delegate/reflection based state machine.

    Thanks!
     
  3. jaybennett

    jaybennett

    Joined:
    Jul 10, 2012
    Posts:
    165
    Do you have a recommendation for using system.xml to work with generic Dictionaries?
     
  4. whydoidoit

    whydoidoit

    Joined:
    Mar 12, 2012
    Posts:
    365
    i usually end end up writing a property that uses Linq to project an array structure loaded from the XML into a generic dictionary on first use.

    Very simple example:

    Code (csharp):
    1.  
    2.  
    3. private public Dictionary<string, Track> _tracks;
    4. public Dictionary<string, Track>  trackLookup {
    5.       get {
    6.             return _tracks ?? _tracks = tracks.ToDictionary(t => t.name);
    7.        }
    8. }
    9.  
    10.