Example #1
0
    public bool LoadTilesetData()
    {
        // load json data from file
        string     path = "Tilesets/" + tilesetName + "/" + tilesetName;
        JSONObject json = JsonFileManagerSync.LoadJsonFile(path);

        if (json == null)
        {
            info.text = "Could not load " + path + ". File does not exist.";
            Debug.LogWarning("Could not load " + path + ". File does not exist.");
            return(false);
        }

        info.text = "Tileset data was loaded successfully.";

        // generate tiles list from json tiles array
        JSONObject tileArr = json["tiles"];

        foreach (JSONObject tile in tileArr.list)
        {
            tiles.Add(new TileRect((int)(tile["x"].n), (int)(tile["y"].n), tile["name"].str));
        }

        // draw overlay to display the results
        DrawOverlay();

        return(true);
    }
Example #2
0
    //=============================================
    // Json
    // ============================================

    public bool SaveTilesetData()
    {
        // create json data object
        JSONObject data = new JSONObject(JSONObject.Type.OBJECT);

        // tileset name
        data.AddField("name", tilesetName);

        // tileset tiles array
        JSONObject tileArr = new JSONObject(JSONObject.Type.ARRAY);

        data.AddField("tiles", tileArr);

        foreach (TileRect tile in tiles)
        {
            JSONObject tileData = new JSONObject(JSONObject.Type.OBJECT);

            tileData.AddField("name", tile.name);
            tileData.AddField("x", tile.x);
            tileData.AddField("y", tile.y);

            tileArr.Add(tileData);
        }

        //save json data to file
        try {
            string path = "Tilesets/" + tilesetName + "/" + tilesetName;
            JsonFileManagerSync.SaveJsonFile(path, data);
            info.text = "Tileset data has been saved.";
            print("Tileset data has been saved.");
            return(true);
        } catch (System.Exception e) {
            info.text = "<color=#ff000>" + e + "</color";
            Debug.LogError(e);
            return(false);
        }
    }