コード例 #1
0
    public void LoadMap(MapData md)
    {
        string path = Application.persistentDataPath + "/" + md.saveName + ".mp";

        if (File.Exists(path))
        {
            BinaryFormatter bf     = new BinaryFormatter();
            FileStream      stream = new FileStream(path, FileMode.Open);

            MapData mapData = bf.Deserialize(stream) as MapData;
            Debug.Log("Mapdata size: " + mapData.tiles.Count);
            foreach (TileEntry entry in mapData.tiles)
            {
                Debug.Log("Tile: " + entry.xPosition + ":" + entry.yPosition + "  type: " + entry.tileType);
                Vector2 position = new Vector2(entry.xPosition, entry.yPosition);
                terrainEditor.PutTileInField(position, entry.tileType);
            }

            stream.Close();
        }
        else
        {
            Debug.Log("No file found");
        }
    }