Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace BayatGames.SaveGamePro.Serialization.Types
- {
- /// <summary>
- /// Save Game Type WorldData serialization implementation.
- /// </summary>
- public class SaveGameType_WorldData : SaveGameType
- {
- /// <summary>
- /// Gets the associated type for this custom type.
- /// </summary>
- /// <value>The type of the associated.</value>
- public override Type AssociatedType
- {
- get
- {
- return typeof ( World.WorldData );
- }
- }
- /// <summary>
- /// Write the specified value using the writer.
- /// </summary>
- /// <param name="value">Value.</param>
- /// <param name="writer">Writer.</param>
- public override void Write ( object value, ISaveGameWriter writer )
- {
- World.WorldData worldData = ( World.WorldData )value;
- writer.WriteProperty ( "worldName", worldData.worldName );
- writer.WriteProperty ( "width", worldData.width );
- writer.WriteProperty ( "height", worldData.height );
- writer.WriteProperty ( "tiles", worldData.tiles );
- }
- /// <summary>
- /// Read the data using the reader.
- /// </summary>
- /// <param name="reader">Reader.</param>
- public override object Read ( ISaveGameReader reader )
- {
- World.WorldData worldData = new World.WorldData();
- ReadInto(worldData, reader);
- return worldData;
- // return base.Read(reader);
- }
- /// <summary>
- /// Read the data into the specified value.
- /// </summary>
- /// <param name="value">Value.</param>
- /// <param name="reader">Reader.</param>
- public override void ReadInto ( object value, ISaveGameReader reader )
- {
- World.WorldData worldData = ( World.WorldData )value;
- foreach ( string property in reader.Properties )
- {
- switch ( property )
- {
- case "worldName":
- worldData.worldName = reader.ReadProperty<System.String> ();
- break;
- case "width":
- worldData.width = reader.ReadProperty<System.Int32> ();
- break;
- case "height":
- worldData.height = reader.ReadProperty<System.Int32> ();
- break;
- case "tiles":
- worldData.tiles = reader.ReadProperty<Tile[,]> ();
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement