从本地读取文件
/// <summary>
/// IO读取
/// </summary>
/// <returns></returns>
private IEnumerator ReadData()
{
string readData;
string fileUrl = Application.streamingAssetsPath + "/FileReadTest.json";
//读取文件
using (StreamReader sr = File.OpenText(fileUrl))
{
//数据保存
readData = sr.ReadToEnd();
sr.Close();
}
//返回数据
Debug.Log("打印读取的技能Json:" + readData);
yield return null;
}
从网络或者本地读取文件
//从网络或者本地读取文件
private IEnumerator GetData(string url)
{
// var uri = new System.Uri(Path.Combine(Application.streamingAssetsPath, //"FileReadTest.json"));
UnityWebRequest www = UnityWebRequest.Get(url);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
string jsonStr = www.downloadHandler.text;
Debug.Log("打印读取的技能Json:" + jsonStr);
}
}