private void LoadCellData() { var fullPath = AssetDatabase.GetAssetPath(this); var path = Path.GetDirectoryName(fullPath); var dataPath = Path.Combine(path, "mapinfo", name + ".bytes").Replace("\\", "/"); if (!File.Exists(dataPath)) { throw new Exception($"Could not find cell data for {name} at path: {dataPath}"); } var bytes = CLZF2.Decompress(File.ReadAllBytes(dataPath)); if (container == null) { container = ScriptableObject.CreateInstance <MapDataContainer>(); } using (var ms = new MemoryStream(bytes)) using (var br = new BinaryReader(ms)) { MapDataContainer.Deserialize(container, br); } //container.CellData = SerializationUtility.DeserializeValue<Cell[]>(bytes, DataFormat.Binary); }
public void SaveCellDataToFile(Cell[] cellData, string path) { if (container == null) { container = ScriptableObject.CreateInstance <MapDataContainer>(); container.CellData = cellData; } else { container.CellData = cellData; } Debug.Log("Saving cell data to : " + path); using (var ms = new MemoryStream(2000000)) using (var bw = new BinaryWriter(ms)) { container.Serialize(bw); var bytes = ms.ToArray(); var b2 = CLZF2.Compress(bytes); var basePath = Path.GetDirectoryName(path); if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } File.WriteAllBytes(path, b2); } }
public static MapDataContainer Deserialize(MapDataContainer container, BinaryReader br) { var size = br.ReadInt32(); container.CellData = new Cell[size]; //Debug.LogWarning("Deserializing size " + size); for (var i = 0; i < size; i++) { container.CellData[i] = new Cell(); container.CellData[i].Deserialize(br); } return(container); }