Defining data models

In the holographic app, the data model will hold the data returned by the Building Rest Services, hence it should be same structure. You can use any of the Rest Client Applications and hit the service end to get the JSON response from services, and based on that you can create the data model; for that, perform the following steps:

  1. Add a new folder inside the Script folder called Building Models:
  2. Add four different script files: Building, Wing, Floor, and Room

Define all the classes, as follows:

[Serializable]
public class Building
{
public string BuildingName;
public string Id;
public string Address;
public List<Wing> Wings;
}

[Serializable]
public class Wing
{
public string WingName;
public List<Floor> Floors;
}

[Serializable]
Public class Floor
{
public string FloorNumber;
public List<Room> Rooms;
}

[Serializable]
public class Room
{
public string RoomNumber;
public int Temperature;
public bool IsSmoke;
public bool IsFire;
}

Ensure that you add serializable attributes for each class so that it can be serialized.

This is how our Building data model looks with Collection Association:

Building data model class diagram
You may wonder why we have used data fields rather than using properties for the given data models. Unity cannot serialize properties; that's why all the members in the data model are defined as fields rather than properties. Refer to http://docs.unity3d.com/ScriptReference/SerializeField.html for more information related to Unity serialization.
..................Content has been hidden....................

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