NewN_UAVPlane/Assets/Zion/Scripts/ListInformation.cs

23 lines
762 B
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;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ListInformation : 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;
Root data = JsonMapper.ToObject<Root>(jsonString);
GameObject item = Instantiate(prefab, parent.transform);
contents.Add(item);
contents[0].transform.GetChild(0).GetChild(0).GetComponent<Text>().text = data.Name;
}
}