Defining the application data model

The data model will hold the data returns by the Asset Rest Services, hence the data model structure would same as what we used during development of Web API. You can use any of the Rest Client Application and hit the service end to get the JSON response from services and based on that you can create the data model. Follow these steps here:

  • In the Unity3D Project, add a new folder inside the Scripts folder called Models.
  • Add two different script file Product.cs and ProductList.cs.

Define all the classes as follows:

[Serializable]
public class Product
{
public string Name;
public string AssetURL;
public string Price;
public string AssetName;
}

[Serializable]
public class ProductList
{
public string Id;
public Product[] Products;
}

Make sure you add Serializable attributes for each class, so that it can be serialized.

You must remember, in Unity, we must use a data field rather than using properties for any given data models where data serialization is required. Unity cannot serialize properties; that's why all the members in the data model define as fields rather than properties. Refer to http://docs.unity3d.com/ScriptReference/SerializeField.html for more information related with Unity Serialization.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.126.11