How to do it...

To create XML text data through serialization, perform the following steps:

  1. Create a C# PlayerScore script class:
    using System.Xml.Serialization;     [System.Serializable]     public class PlayerScore     {         [XmlElement("Name")]         public string name;         [XmlElement("Score")]         public int score;         [XmlElement("Version")]         public string version;     } 
  1. Create a C# PlayerScoreCollection scrip class:
    using System.Xml.Serialization;     using System.IO;     [XmlRoot("PlayerScoreCollection")]     public class PlayerScoreCollection     {         [XmlArray("PlayerScores"), XmlArrayItem("PlayerScore")]         public PlayerScore[] playerScores;         public void Save(string path) {             var serializer = new XmlSerializer(typeof(PlayerScoreCollection)); using (var stream = new FileStream(path, ...

Get Unity 2018 Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.