Unity3d 读取json文本数据
2012-11-12 23:50
453 查看
1,在unity3d 工程中创建一个Plugs文件夹,将网上下好的LitJson1.1放在这个文件夹里。
2,再创建一个Resources文件夹,将json文本“mytestui.txt”放在这个文件夹。
3,mytestui.txt 的内容为:
--------------------------------mytestui.txt-------------------
-------------------------------调用----------test.cs-----------------
-----------------打印-------------------
BarGreyBlue2.png False
UnityEngine.MonoBehaviour:print(Object)
test:Start() (at Assets/test.cs:56)
blueBg2.png False
UnityEngine.MonoBehaviour:print(Object)
test:Start() (at Assets/test.cs:56)
2,再创建一个Resources文件夹,将json文本“mytestui.txt”放在这个文件夹。
3,mytestui.txt 的内容为:
--------------------------------mytestui.txt-------------------
{ "frames": { "BarGreyBlue2.png": { "frame": {"x":2,"y":2,"w":3,"h":88}, "rotated": false, "trimmed": false, "spriteSourceSize": {"x":0,"y":0,"w":3,"h":88}, "sourceSize": {"w":3,"h":88} }, "blueBg2.png": { "frame": {"x":2,"y":92,"w":14,"h":14}, "rotated": false, "trimmed": false, "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, "sourceSize": {"w":14,"h":14} } } }
-------------------------------调用----------test.cs-----------------
using UnityEngine; using System.Collections; using System.Collections.Generic; using LitJson; public class myframe { public int x; public int y; public int w; public int h; } public class mySpriteSourceSize { public int x; public int y; public int w; public int h; } public class mySourceSize { public int w; public int h; } public class myPng { public mySourceSize sourceSize; public mySpriteSourceSize spriteSourceSize; public myframe frame; public bool rotated; public bool trimmed; } public class myPngs { public Dictionary<string, myPng> frames; } public class test : MonoBehaviour { void Start() { var textObj = Resources.Load("mytestui") as TextAsset; myPngs pngs = JsonMapper.ToObject<myPngs>(textObj.text); foreach (var i in pngs.frames) { print(i.Key + " " + i.Value.rotated); } } }
-----------------打印-------------------
BarGreyBlue2.png False
UnityEngine.MonoBehaviour:print(Object)
test:Start() (at Assets/test.cs:56)
blueBg2.png False
UnityEngine.MonoBehaviour:print(Object)
test:Start() (at Assets/test.cs:56)
相关文章推荐
- Unity3D学习(二):使用JSON进行对象数据的存储读取
- js读取本地磁盘文本文件并保存为JSON数据(有格式的文本)
- js读取本地磁盘文本文件并保存为JSON数据(有格式的文本)
- 按行数读取文本数据并返回字符串数组或者json数组
- unity中从txt文件中读取解析json数据&&unity中json数据写入txt文件
- js读取解析JSON数据
- Unity3d读取CSV中的文本到Rich Text中换行符不识别的问题
- SenchTouch 使用scriptTagProxy 代理读取json数据
- ArrayList集合中的字符串数据存储到文本文件|文本文件中读取数据到集合
- android 读取JSON数据(遍历JSONObject和JSONArray) .
- [Unity][JSON]读取写入玩家数据
- JDBC处理大数据(大文本的存储和读取)
- Jayrock.Json读取json数据(net)
- Grid读取json数据
- 从数据库读取数据存放在List<T>中,在jsp中将其取出来。(使用JSON)
- Unity3D 读取json
- Matlab 读取dat文件(包含几行多余文本,数据带有数字和字符串,且以逗号分隔)
- matlab中读取txt数据文件(txt文本文档)
- cocos2dx lua 读取json数据
- localStorage 如何存储JSON数据并读取JSON数据