Building Engine for Unity3D - Tiny house data saving and loading

4b.Save data for rubtime loading (alternative option)

Select the BuildingEngine gameObject, hit the "SAVE MAP" button. Enter "tinyHouse" in the textfield and hit "SAVE". As the "tinyHouse" saves already exists, you need to confirm. Hit the "OVERWRITE" button.

Overwriting save

To load the tiny house, select the BuildingEngine gameObject, hit the "LOAD MAP" button and then hit the "tinyHouse" button.

Lading map

In order to load through code the tiny house map, you can use the following script :

using UnityEngine;
using System.IO;
using System.Xml;
using BuildingEngine;

public class TinyHouseLoader : MonoBehaviour
{
 private void OnGUI()
 {
  if(GUI.Button(new Rect(20,20,180,20), "Load tinyHouse"))
  {
   LoadAndBuildTinyHouse();
  }
 }

 private void LoadAndBuildTinyHouse()
 {
  //load XML data and parse it
  string s = File.ReadAllText("Assets/saves/tinyHouse.xml");
  XmlDocument doc = new XmlDocument();
  doc.LoadXml(s);
  XmlElement mapXML = doc.DocumentElement;
  Engine.Map = Engine.decoder.DecodeToMap(mapXML);
  Engine.designer.SetHigherIndexes(Engine.Map);
  //build map
  Engine.Build(Engine.Map);
 }
}

© 2017 Magyc Pixel. All rights reserved | Design by W3layouts