NewN_UAVPlane/Assets/Zion/Scripts/TableTest.cs

40 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using LitJson;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public class TableTest : MonoBehaviour
{
public List<GameObject> contents;
[SerializeField] GameObject prefab; //预制体
[SerializeField] GameObject parent; //父物体content
// Start is called before the first frame update
void Start()
{
TextAsset jsonFile = Resources.Load<TextAsset>("testfile");
string jsonString = jsonFile.text;
JsonData jsonData = JsonMapper.ToObject(jsonString);
Root data = JsonMapper.ToObject<Root>(jsonString);
List<SubjectsInfoItem> subjectsInfoItems = data.subjectsInfo;
List<SeatInfosItem> seatInfosItems = new List<SeatInfosItem>();
foreach (SubjectsInfoItem subjectsInfoItem in subjectsInfoItems)
{
if (subjectsInfoItem.seatInfos != null && subjectsInfoItem.seatInfos.Count() > 0)
{
seatInfosItems.AddRange(subjectsInfoItem.seatInfos);
}
Debug.Log(seatInfosItems.Count);
}
for (int i = 0; i < seatInfosItems.Count; i++)
{
GameObject item = Instantiate(prefab, parent.transform);
contents.Add(item);
contents[i].transform.GetChild(0).GetComponent<Text>().text = seatInfosItems[i].seatId;
contents[i].transform.GetChild(1).GetComponent<Text>().text = seatInfosItems[i].seatName;
contents[i].transform.GetChild(2).GetComponent<Text>().text = seatInfosItems[i].subjectId;
}
}
}