Level save + load

This commit is contained in:
2023-06-16 17:08:56 +03:00
parent d9fbd99072
commit 0eb8b1d4ee
132 changed files with 20138 additions and 15 deletions

View File

@@ -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);
}
}
}
}