Level save + load
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -10,5 +12,24 @@ namespace Level
|
||||
public LayoutCell.LayoutCellData[][] layout;
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
public byte[] ToBytes()
|
||||
{
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
formatter.Serialize(memoryStream, this);
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static LevelData FromBytes(byte[] data)
|
||||
{
|
||||
BinaryFormatter formatter = new BinaryFormatter();
|
||||
using (MemoryStream memoryStream = new MemoryStream(data))
|
||||
{
|
||||
return (LevelData)formatter.Deserialize(memoryStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user