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;
        }

    }
}