O'Reilly logo

Unity 4.x Cookbook by Matt Smith, Chico Queiroz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating XML text data automatically through serialization

Another way to create XML data structures from game objects and properties is by serializing the contents of an object automatically. This technique automatically generates XML for all the public properties of an object.

Getting ready

In the 0423_08_06 folder, you'll find the listings for all four classes described in this recipe.

How to do it...

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

  1. Create a C# script called PlayerScore:
    // file: PlayerScore.cs public class PlayerScore { public string name; public int score; // default constructor, needed for serialization public PlayerScore() {} public PlayerScore(string newName, int newScore) { name = newName; score = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required