public static NodeData CreateRoot(MapSaveStateSerializable saveState) { NodeData toReturn = new NodeData(null, saveState); toReturn.isRoot = true; toReturn.nbChild = 0; toReturn.depth = 0; toReturn.isAMerge = false; return(toReturn); }
public static NodeData CreateMergeNode(NodeData into, NodeData from) { MapSaveStateSerializable saveState = new MapSaveStateSerializable(into, from); NodeData toReturn = new NodeData(null, saveState); toReturn.parent = from.depth > into.depth ? from : into; toReturn.mergeOrigin = from.depth > into.depth ? into : from; toReturn.depth = Mathf.Max(into.depth, from.depth) + 1; toReturn.nbChild = 0; toReturn.isAMerge = true; toReturn.parent.nbChild++; return(toReturn); }
public MapSaveStateSerializable(MapSaveStateSerializable saveState) { this.xSize = saveState.xSize; this.ySize = saveState.ySize; this.isDead = false; int size = saveState.xSize * saveState.ySize; tiles = new TileData[saveState.tiles.Length]; for (int i = 0; i < saveState.tiles.Length; i++) { tiles[i] = saveState.tiles[i]; } }
// Use this for initialization public static MapSaveState CreateFromSerialized(MapSaveStateSerializable serialized) { //MapSaveState toReturn = Create(serialized.xSize, serialized.ySize); MapSaveState toReturn = Instantiate(original).GetComponent <MapSaveState>(); toReturn.xSize = serialized.xSize; toReturn.ySize = serialized.ySize; toReturn.isDead = false; toReturn.tiles = new TileData[toReturn.xSize, toReturn.ySize]; for (int i = 0; i < serialized.tiles.Length; i++) { toReturn.tiles[i % toReturn.xSize, i / toReturn.xSize] = serialized.tiles[i].GetCopy(); } toReturn.serializable = serialized; toReturn.LinkTilesWithData(); return(toReturn); }
public NodeData(NodeData parent, MapSaveStateSerializable saveState = null) { this.parent = parent; this.nbChild = 0; if (parent != null) { this.depth = parent.depth + 1; parent.nbChild++; } if (saveState == null) { this.saveState = new MapSaveStateSerializable(parent.saveState); } else { this.saveState = saveState; } this.isRoot = false; this.isAMerge = false; }
string MapToJSON(MapSaveStateSerializable obj) { // Save object to JSON string return(JsonUtility.ToJson(obj)); }