using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoadCTRL : MonoBehaviour
{
private static LoadCTRL _instance;
public static LoadCTRL Instance
{
get
{
if (null == _instance)
{
_instance = new LoadCTRL();
}
return _instance;
}
}
void Start()
{
string path = Application.dataPath + "/StreamingAssets/" + "data" + ".json";
StartCoroutine(GetData(path, ShowInfo));
}
public IEnumerator GetData(string path, Action<WWW> cb)
{
WWW www = new WWW(path);
yield return www;
if (www.isDone)
{
if (www.error == null)
{
cb(www);
}
}
}
public void ShowInfo(WWW www)
{
JsonReader js = new JsonReader(www.text);
Root res = JsonMapper.ToObject<Root>(js);
Debug.Log(res.root[2].modelname);
}
}
public class RootItem
{
/// <summary>
///
/// </summary>
public string modelname { get; set; }
/// <summary>
///
/// </summary>
public string type { get; set; }
/// <summary>
///
/// </summary>
public string resource { get; set; }
}
public class Root
{
/// <summary>
///
/// </summary>
public List<RootItem> root { get; set; }
}
协程加载的回调函数
最新推荐文章于 2024-03-20 20:58:10 发布