Json转string:
///
/// Json转string
///
/// Json
///
private string GetJsonWriter(ExperimentalResultData experimentalResultData_)
{
JsonWriter tdata = new JsonWriter();
tdata.WriteObjectStart();
tdata.WritePropertyName("user");//
tdata.Write(experimentalResultData_.user);
tdata.WritePropertyName("resid");//
tdata.Write(experimentalResultData_.resid);
tdata.WritePropertyName("secret");//
tdata.Write(experimentalResultData_.secret);
tdata.WritePropertyName("status");//
tdata.Write(1);
tdata.WritePropertyName("score");//
tdata.Write(experimentalResultData_.score);
tdata.WritePropertyName("timeUsed");//
tdata.Write(experimentalResultData_.timeUsed);
tdata.WritePropertyName("stepDetails");//步骤List
tdata.WriteArrayStart();
for (int i = 0; i < experimentalResultData_.steps.Count; i++)
{
tdata.WriteObjectStart();
tdata.WritePropertyName("title");//
tdata.Write(experimentalResultData_.steps[i].title);
tdata.WritePropertyName("timeUsed");//
tdata.Write(experimentalResultData_.steps[i].timeUsed);
tdata.WritePropertyName("expectTime");//
tdata.Write(experimentalResultData_.steps[i].expectTime);
tdata.WritePropertyName("maxScore");//
tdata.Write(experimentalResultData_.steps[i].maxScore);
tdata.WritePropertyName("score");//
tdata.Write(experimentalResultData_.steps[i].score);
tdata.WritePropertyName("repeatCount");//
tdata.Write(experimentalResultData_.steps[i].repeatCount);
tdata.WriteObjectEnd();
}
tdata.WriteArrayEnd();
tdata.WriteObjectEnd();
return tdata.ToString();
}
Json 在线编辑 ,转化为解析类 网址:JSON转C#实体类-BeJSON.com
{
"ConfigInfo": [
{
"Name": "旅游",
"Audio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png",
"ParentPointItmes": [
{
"PointName": "旅游1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png",
"ChildPointItmes": [
{
"PointName": "故居1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "山1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "旧址1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
}
]
},
{
"PointName": "旅游2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png",
"ParentPointItmes": [
{
"PointName": "故居2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "山2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "旧址3",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
}
]
}
]
},
{
"Name": "展厅",
"Audio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香念馆/2021-05-25 11_14_07_043.png",
"ParentPointItmes": [
{
"PointName": "展厅1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/纪念馆/2021-05-25 11_14_07_043.png",
"ChildPointItmes": [
{
"PointName": "念馆1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "纪念馆1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "周年1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/念馆/2021-05-25 11_14_07_043.png"
}
]
},
{
"PointName": "展厅2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/纪念馆/2021-05-25 11_14_07_043.png",
"ChildPointItmes": [
{
"PointName": "纪念馆2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "争纪念馆2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "周年2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
}
]
}
]
},
{
"Name": "教育",
"Audio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png",
"ParentPointItmes": [
{
"PointName": "教育1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png",
"ChildPointItmes": [
{
"PointName": "一1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "一2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "一3",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
}
]
},
{
"PointName": "教育2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png",
"ChildPointItmes": [
{
"PointName": "二1",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "二2",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
},
{
"PointName": "二3",
"PointAudio": "/Audios/1631001459775.mp3",
"ImageUrl": "/Images/香山纪念馆/2021-05-25 11_14_07_043.png"
}
]
}
]
}
]
}
解析类:
//如果好用,请收藏地址,帮忙分享。
using System;
using System.Collections.Generic;
[Serializable]
public class ChildPointItmesItem
{
///
///
///
public string PointName;
///
///
///
public string PointAudio;
///
///
///
public string ImageUrl;
}
[Serializable]
public class ParentPointItmesItem
{
///
///
///
public string PointName;
///
///
///
public string PointAudio;
///
///
///
public string ImageUrl;
///
///
///
public List ChildPointItmes;
}
[Serializable]
public class ConfigInfoItem
{
///
///
///
public string Name;
///
///
///
public string Audio;
///
///
///
public string ImageUrl;
///
///
///
public List ParentPointItmes;
}
public class Root
{
///
///
///
public List ConfigInfo;
}
调用方法:
public Transform transform;
void Start()
{
//方法一
//找到文件 StreamingAssets
string jsonTest = File.ReadAllText(Application.streamingAssetsPath+"/Data.json", Encoding.UTF8);
// string jsonTest = File.ReadAllText("D:/Data.json", Encoding.UTF8);
//直接调用Unity提供的接口JsonUtility.FromJson即可实现解析
List configInfo = JsonUtility.FromJson(jsonTest).ConfigInfo;
Debug.Log(jsonTest);
for (int i = 0; i < configInfo.Count; i++)
{
Debug.Log(configInfo[i].Name);
//GlobalFunction.CreationUI("ItmeList", transform);
}
//方法二:用于 WebGL端 加载文件
StartCoroutine(GetInfoDataJson());
}
private IEnumerator GetInfoDataJson()
{
GHSJData GHSJData_ = LitJson.JsonMapper.ToObject(webRequest.downloadHandler.text);
UnityWebRequest webRequest = UnityWebRequest.Get(Application.streamingAssetsPath + "/InfoData.json");
yield return webRequest.SendWebRequest();
if (webRequest.isHttpError || webRequest.isNetworkError)
Debug.Log(webRequest.error);
else
{
List configInfo = JsonUtility.FromJson(webRequest.downloadHandler.text).ConfigInfo;
GlobalVariable.posListItem = configInfo[0].PosList;
var GZTJ = GlobalVariable.posListItem[2].GaiZaoTiaoJian;
Debug.Log("可用楼层:" + GZTJ.KeYongLouCeng);
// Report report = LitJson.JsonMapper.ToObject(webRequest.downloadHandler.text);
}
}
///
/// 获取URLJson()
///
///
private IEnumerator GetInfoDataJson01()
{
UnityWebRequest webRequest = UnityWebRequest.Get(Application.streamingAssetsPath + "/Json/ZhiWuRenZhiData.Json");
yield return webRequest.SendWebRequest();
if (webRequest.isHttpError || webRequest.isNetworkError)
Debug.Log(webRequest.error);
else
{
var data = LitJson.JsonMapper.ToObject(webRequest.downloadHandler.text);
ZhiWuDataList = data.ZhiWuDataList;
Debug.Log(data.ZhiWuDataList.Count);
Debug.Log("ZhiWuDataList.name" + ZhiWuDataList[0].Name);
//注意使用数据的节点,保证json 已经解析成功(WebGL端 测试成功)
for (int i = 0; i < ZhiWuDataList.Count; i++)
{
int x = i;
GetItme(ZhiWuDataList[x].Name, ZhiWuDataList[x].Introduce);
}
}
}
2.加载Resources文件夹下纯文本
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
///
/// 试题区
///
public class TheAnswerPaper : MonoSingleton
{
public GameObject Mask;
public Text TitleText;//总标题名字
public Transform Content;
public GameObject QuestionsItme;
public Button ShiTiQu_Btn;//返回试题区(和交卷位置重叠的按钮)
public Button JiaoJuanBtn;//交卷
public Button DingBuBtn;//顶部
public Button DaTiKaBtn;//查看答题卡
public Button ShiTiQuBtn;//返回试题区
public GameObject JiaoJuanChengGong;
public Button test;
public Button GuanBiBtn;//关闭按钮
public string TitleStr;
protected override void Awake()
{
ShiTiQu_Btn.onClick.AddListener(OnShiTiQuBtn);
JiaoJuanBtn.onClick.AddListener(OnJiaoJuanBtn);
DingBuBtn.onClick.AddListener(OnDingBuBtn);
DaTiKaBtn.onClick.AddListener(OnDaTiKaBtn);
ShiTiQuBtn.onClick.AddListener(OnShiTiQuBtn);
GuanBiBtn.onClick.AddListener(OnGuanBi);
// UI_SystemInfo.Instance.AddReturnListener(OnReturnBtn);
}
private void Start()
{
var json = Resources.Load("Texts/Data");//Resources文件夹下Texts文件夹下Data
//找到文件
string jsonTest = json.text;
//string jsonTest = File.ReadAllText(Application.streamingAssetsPath+"/Data.json", Encoding.UTF8);
//直接调用Unity提供的接口JsonUtility.FromJson即可实现解析
List configInfo = JsonUtility.FromJson(jsonTest).ConfigInfo;
//Debug.Log(configInfo[0].Title);
TitleStr = configInfo[0].Title;
TitleText.text = TitleStr;
for (int i = 0; i < configInfo[0].ParentPointItmes.Count; i++)
{
// CreationUI(QuestionsItme, Content, i, configInfo[0].ParentPointItmes[i]);
var tempObject = GameObject.Instantiate(QuestionsItme, Content);
tempObject.SetActive(true);
tempObject.transform.GetComponent().title = (i + 1) + "." + configInfo[0].ParentPointItmes[i].Title;
tempObject.transform.GetComponent().singlemultiple = bool.Parse(configInfo[0].ParentPointItmes[i].singlemultiple);
tempObject.transform.GetComponent().analysis = "这里是解析";
tempObject.transform.GetComponent().answer = configInfo[0].ParentPointItmes[i].answer;
tempObject.transform.GetComponent().Init(configInfo[0].ParentPointItmes[i].option);
}
//for (int i = 0; i < 10; i++)
//{
// CreationUI(QuestionsItme, Content, i);
//}
ShuaXinRect(15);
ShiTiQu_Btn.gameObject.SetActive(false);
JiaoJuanBtn.gameObject.SetActive(true);
}
public void Test()
{
Debug.Log("Test");
ShuaXinRect(240);
}
///
/// 交卷
///
public void OnJiaoJuanBtn()
{
TipDialog.Instance.ShowDialog("提交后就无法修改了哦,是否确认提交?", (b) =>
{
if (b)
{
JiaoJuanChengGong.SetActive(true);
}
}, TipDialog.DialogType.AffirmAndCancel);
}
///
/// 顶部
///
public void OnDingBuBtn()
{
//初始位置
Content.parent.parent.GetComponent().normalizedPosition = new Vector2(0, 1);
}
///
/// 打开 答题卡
///
public void OnDaTiKaBtn()
{
TitleText.text = TitleStr;
OpenAnswer(true);
JiaoJuanChengGong.SetActive(false);
ShuaXinRect(240);
ShiTiQu_Btn.gameObject.SetActive(true);
JiaoJuanBtn.gameObject.SetActive(false);
}
///
/// 返回 试题区
///
public void OnShiTiQuBtn()
{
TitleText.text = TitleStr;
OpenAnswer(false);
JiaoJuanChengGong.SetActive(false);
ShuaXinRect(15);
ShiTiQu_Btn.gameObject.SetActive(false);
JiaoJuanBtn.gameObject.SetActive(true);
}
///
/// 手动刷新列表
///
///
public void ShuaXinRect(int n)
{
Content.GetComponent().spacing = new Vector2(0, n);
//刷新(有时候需要收到刷新)
LayoutRebuilder.ForceRebuildLayoutImmediate(Content.GetComponent());
//初始位置
Content.parent.parent.GetComponent().normalizedPosition = new Vector2(0, 1);
}
///
/// 打开 解析
///
public void OpenAnswer(bool bo)
{
for (int i = 1; i < Content.childCount; i++)
{
Content.GetChild(i).transform.GetComponent().OpenAnswer(bo);
}
}
/
/ 创建选择题Itme
/
/
/
//public GameObject CreationUI(GameObject Itme, Transform pTr,int i, List ParentPointItmes)
//{
// var tempObject = GameObject.Instantiate(Itme, pTr);
// tempObject.SetActive(true);
// tempObject.transform.GetComponent().title = (i+1)+"."+ ParentPointItmes.Title;
// tempObject.transform.GetComponent().singlemultiple =true;
// tempObject.transform.GetComponent().analysis = "这里是解析";
// tempObject.transform.GetComponent().Init();
// return tempObject;
//}
///
/// 抬头 返回按钮
///
public void OnReturnBtn()
{
Debug.Log("在试题区 点击抬头 返回按钮");
if (Mask.active)
{
EmergencyKnowledge_Library.Instance.SetSteat(true);
}
Mask.SetActive(false);
}
public GameObject EmergencyKnowledge;
public void OnGuanBi()
{
EmergencyKnowledge.gameObject.SetActive(true);
Mask.SetActive(false);
}
///
/// 设置状态
///
public void SetSteat(bool bo)
{
Mask.SetActive(bo);
init();
}
public void init()
{
}
private void OnEnable()
{
UI_SystemInfo.Instance.ReturnBtn.onClick.AddListener(OnReturnBtn);
}
private void OnDisable()
{
UI_SystemInfo.Instance.ReturnBtn.onClick.RemoveListener(OnReturnBtn);
}
private void OnDestroy()
{
ShiTiQu_Btn.onClick.RemoveListener(OnShiTiQuBtn);
JiaoJuanBtn.onClick.RemoveListener(OnJiaoJuanBtn);
DingBuBtn.onClick.RemoveListener(OnDingBuBtn);
DaTiKaBtn.onClick.RemoveListener(OnDaTiKaBtn);
ShiTiQuBtn.onClick.RemoveListener(OnShiTiQuBtn);
// UI_SystemInfo.Instance.ReturnBtn.onClick.RemoveListener(OnReturnBtn);
}
}
{
"ConfigInfo": [
{
"Title": "旅游安全应急管理概述试题(共22题)",
"ParentPointItmes": [
{
"Title": "信息安全的含义主要指信息的完整性、可用性、保密性、可靠性和抗否认性。信息安全的基本要求是指保证信息的( ) ?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "D",
"option": [
{
"A": "可靠性"
},
{
"B": "保密性"
},
{
"C": "可用性"
},
{
"D": "完整性"
}
]
},
{
"Title": "旅游饭店星级的划分与评定中规定:应有应急照明设施和应急供电系统的饭店是( )?",
"singlemultiple": "true",
"analysis": "这里是解析",
"answer": "BCD",
"option": [
{
"A": "二星级饭店"
},
{
"B": "三星级饭店"
},
{
"C": "四星级饭店"
},
{
"D": "五星级饭店"
}
]
},
{
"Title": "《中华人民共和国突发事件应对法》自___起施行?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "D",
"option": [
{
"A": "2007年10月1日"
},
{
"B": "2007年11月1日"
},
{
"C": "2007年12月1日"
},
{
"D": "2008年1月1日"
}
]
},
{
"Title": "国务院____出台《国家突发公共事件总体应急预案》?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "C",
"option": [
{
"A": "2005年"
},
{
"B": "2006年"
},
{
"C": "2007年"
},
{
"D": "2008年"
}
]
},
{
"Title": "国务院和____以上地方人民政府是突发事件应对工作的行政领导机关,其办事机构及具体职责由国务院规定?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "A",
"option": [
{
"A": "省级"
},
{
"B": "地市级"
},
{
"C": "县级"
},
{
"D": "乡镇级"
}
]
},
{
"Title": "2008年2月21日,黄华华省长在全省应急管理工作会议上的讲话中指出,应急管理工作的最终目标是?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "B",
"option": [
{
"A": "迅速反应,消除隐患"
},
{
"B": "无急可应,有急能应"
},
{
"C": " 以人为本,减少损失"
},
{
"D": "消除隐患,有急能应"
}
]
},
{
"Title": "突发事件预警信息最高级别为I级,用_____表示?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "B",
"option": [
{
"A": "橙色"
},
{
"B": "红色"
},
{
"C": "黄色"
},
{
"D": "蓝色"
}
]
},
{
"Title": "台风黄色预警信号含义∶24小时内可能或者已经受热带气旋的影响,平均风力____级以上?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "B",
"option": [
{
"A": "8"
},
{
"B": "9"
},
{
"C": "10"
},
{
"D": "11"
}
]
},
{
"Title": "生产经营单位的应急管理机构以及应急管理人员需履行的主要应急管理工作职责有?",
"singlemultiple": "true",
"analysis": "这里是解析",
"answer": "ABCD",
"option": [
{
"A": "组织或者参与拟订本单位生产安全事故应急救援预案"
},
{
"B": "组织或者参与本单位应急教育和培训,如实记录教育和培训情况"
},
{
"C": "组织或者参与本单位应急救援演练"
},
{
"D": "在应急领导小组办公室的领导下,开展相关工作"
}
]
},
{
"Title": "成人经静脉补充钾离子时,要求尿量每小时不得少于?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "B",
"option": [
{
"A": "20ml"
},
{
"B": "30ml"
},
{
"C": "40ml"
},
{
"D": "50ml"
}
]
},
{
"Title": "休克病人补液一般首选?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "D",
"option": [
{
"A": "全血"
},
{
"B": "血浆"
},
{
"C": "10%葡萄糖液"
},
{
"D": "平衡盐溶液"
}
]
},
{
"Title": "过敏药物迟缓型反应的发生,护士在注射后至少应观察病人?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "C",
"option": [
{
"A": "10分钟"
},
{
"B": "20分钟"
},
{
"C": "30分钟"
},
{
"D": "60分钟"
}
]
},
{
"Title": "发生过敏性休克的时,先使病人平卧的目的时是?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "B",
"option": [
{
"A": "防止发生创伤"
},
{
"B": "有利于脑部血液循环"
},
{
"C": "缓解呼吸困难"
},
{
"D": "方便抢救"
}
]
},
{
"Title": "试敏药物过敏性休克时,立即皮下注射肾上腺素的目的?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "A",
"option": [
{
"A": "增加心输出量"
},
{
"B": "减少外周阻力"
},
{
"C": "减少心输出量"
},
{
"D": "兴奋呼吸中枢"
}
]
},
{
"Title": "台风黄色预警信号含义∶24小时内可能或者已经受热带气旋的影响,平均风力____级以上?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "B",
"option": [
{
"A": "8"
},
{
"B": "9"
},
{
"C": "10"
},
{
"D": "11"
}
]
},
{
"Title": "心肺复苏指南建议对婴儿实施双人CPR均按照( )的比例给予按压和通气?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "B",
"option": [
{
"A": "5.1"
},
{
"B": "15.2"
},
{
"C": "30.2"
},
{
"D": "15.1"
}
]
},
{
"Title": "地震灾害的伤亡主要由____造成?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "A",
"option": [
{
"A": " 建筑物倒塌"
},
{
"B": "地震的余波"
},
{
"C": "地震引起的火灾"
},
{
"D": "地震引起的传染病"
}
]
},
{
"Title": "高楼失火,当通道被火封住,无法出逃时,关紧迎火门窗,用湿手巾、湿布堵塞门缝,或用水淋透房门,迅速跑到临街的窗户或__发出求救信号?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "A",
"option": [
{
"A": "阳台"
},
{
"B": "房间"
},
{
"C": "卫生间"
},
{
"D": "客厅"
}
]
},
{
"Title": "家庭装配的应急箱中,食品和饮用水至少够每个人用____天?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "C",
"option": [
{
"A": "1"
},
{
"B": "2"
},
{
"C": "3"
},
{
"D": "4"
}
]
},
{
"Title": "发生直接危及人身安全的紧急情况,现场工作人员( )或在采取了可能的应急措施后撤离现场?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "B",
"option": [
{
"A": "有权停止作业"
},
{
"B": "必须停止作业"
},
{
"C": "向上级请示停止作业"
},
{
"D": "坚守岗位、等待救援"
}
]
},
{
"Title": "各种类型休克基本病理变化是?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "D",
"option": [
{
"A": "血压下降"
},
{
"B": "中心静脉压下降"
},
{
"C": "脉压减小"
},
{
"D": "有效循环血量锐减"
}
]
},
{
"Title": "休克的主要致死原因是?",
"singlemultiple": "false",
"analysis": "这里是解析",
"answer": "D",
"option": [
{
"A": "心功能衰竭"
},
{
"B": "肺间质水肿"
},
{
"C": "DIC"
},
{
"D": "多系统器官衰竭(MSOF)"
}
]
}
]
}
]
}
3.图片加载
1.放置StreamingAssets文件下,
2.注意路径
3.加上图片后缀
4.代码:
//刷新(有时候需要收到刷新)
LayoutRebuilder.ForceRebuildLayoutImmediate(Content.GetComponent());
StartCoroutine(DownSpriteOne(Itme, configInfo[i].nameId, configInfo[i].sceneType));
///
/// 1.异步:(其实还是在主线程加载)
///使用UnityWebRequest(或者WWW)进行图片加载,可以加载本地(速度慢,2048*1024大小的图片加载时间780ms,不卡界面)和网络图片。
///注意:这里的路径中一定不能有中文,否则加载不出来,注意是路径跟文件名无关.
///
///
///
///
IEnumerator DownSpriteOne(GameObject go, string nameId,int sceneType)
{
UnityWebRequest request = UnityWebRequestTexture.GetTexture(Application.streamingAssetsPath+ "/AssociatedScenario/" + nameId+ ".png");
yield return request.SendWebRequest();
if (request.downloadHandler.isDone)
{
var tex = DownloadHandlerTexture.GetContent(request);
Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
var item = Instantiate(go, Content);
item.transform.GetComponent().Icon.sprite = sprite;
item.transform.GetComponent().SceneType = sceneType;
item.transform.GetComponent().SceneGuanLian = 1;
item.transform.GetComponent().TitleText.text = nameId;
item.gameObject.SetActive(true);
}
}