56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using LitJson;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public class JsonTest : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public Dictionary<string, List<MoveData>> cameraMoveTrans;//jsonÖÐÐÅÏ¢ºÏ¼¯
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
cameraMoveTrans = ReadData("ErrorPosData.json");
|
|
|
|
foreach (var item in cameraMoveTrans)
|
|
{
|
|
|
|
for (int i = 0; i < item.Value.Count; i++)
|
|
{
|
|
Debug.Log(item.Key + "----------" + item.Value[i].Position + "----------" + item.Value[i].EulerAngles);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// ¶ÁjsonÎļþ
|
|
/// </summary>
|
|
/// <param name="fileName"></param>
|
|
/// <returns></returns>
|
|
private Dictionary<string, List<MoveData>> ReadData(string fileName)
|
|
{
|
|
Dictionary<string, List<MoveData>> tempDic = new Dictionary<string, List<MoveData>>();
|
|
string path = Path.Combine(Application.streamingAssetsPath, fileName);
|
|
string data = File.ReadAllText(path);
|
|
try
|
|
{
|
|
tempDic = JsonMapper.ToObject<Dictionary<string, List<MoveData>>>(data);
|
|
return tempDic;
|
|
}
|
|
catch (LitJson.JsonException e)
|
|
{
|
|
//Debug.Log(e.Message);
|
|
return null;
|
|
}
|
|
|
|
}
|
|
}
|