//e.g) //{ // "filename": "texture_00.png", // "frame": {"x":2,"y":2,"w":1016,"h":1004}, // "spriteSourceSize": {"x":3,"y":13,"w":1016,"h":1004}, // "sourceSize": {"w":1024,"h":1024} //} public static TextureLayout loadJson(Value json) { var ret = new TextureLayout(); try { ret.filename = json.get("filename").toString(); ret.srcWidth = json.get("sourceSize").get("w").toInt(0); ret.srcHeight = json.get("sourceSize").get("h").toInt(0); ret.x = json.get("frame").get("x").toInt(0); ret.y = json.get("frame").get("y").toInt(0); ret.trimX = json.get("spriteSourceSize").get("x").toInt(0); ret.trimY = json.get("spriteSourceSize").get("y").toInt(0); } catch (Exception) { UtDebug.print("JSON Parse Error!"); } return(ret); }
//e.g) //{"frames": [ //{ // "filename": "texture_00.png", // "frame": {"x":2,"y":2,"w":1016,"h":1004}, // "spriteSourceSize": {"x":3,"y":13,"w":1016,"h":1004}, // "sourceSize": {"w":1024,"h":1024} //}, //{ // "filename": "texture_01.png", // "frame": {"x":1020,"y":2,"w":972,"h":1011}, // "spriteSourceSize": {"x":29,"y":4,"w":972,"h":1011}, // "sourceSize": {"w":1024,"h":1024} //}], //"meta": { // "image": "texture_atlas.png", // "size": {"w":2048,"h":2048} //} //} public static TextureAtlasLayout loadJson(Value json) { var ret = new TextureAtlasLayout(); try { ret.image = json.get("meta").get("image").toString(); ret.width = json.get("meta").get("size").get("w").toInt(0); ret.height = json.get("meta").get("size").get("h").toInt(0); var array = json.get("frames").getVector(null); int n = array.Count; for (int i = 0; i < n; i++) { ret.frames.Add(TextureLayout.loadJson(array[i])); } } catch (Exception) { UtDebug.print("JSON Parse Error!"); } return(ret); }