using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class DataShow : MonoBehaviour { public TextMeshProUGUI data; string value; public TextMeshProUGUI 气象编号; public TextMeshProUGUI 探测时间; public TextMeshProUGUI 探测高程; public TextMeshProUGUI 地面气压; public Transform itemPra; List qiXiangDatas = new List(); // Start is called before the first frame update void Start() { //默认清除所有数据 for (int j = 0; j < itemPra.childCount; j++) { itemPra.GetChild(j).GetChild(0).GetComponent().text = ""; itemPra.GetChild(j).GetChild(1).GetComponent().text = ""; itemPra.GetChild(j).GetChild(2).GetComponent().text = ""; } value = data.text; //解析数据并填充 string[] result = value.Split('-'); 气象编号.text= result[0]; 探测时间.text = result[1]; 探测高程.text =result[2]; 地面气压.text=result[3]; List groups=new List(); int startIndex = 4; int ramainingLength = result.Length - startIndex; int groupCount = ramainingLength / 3; groups.Capacity = groupCount; for (int i = 0; i < groupCount; i++) { int baseIndex = startIndex + (i * 3); string[] group = new string[3]; group[0] = result[baseIndex]; group[1] = result[baseIndex + 1]; group[2] = result[baseIndex + 2]; groups.Add(group); } Debug.Log(groups.Count); for (int j = 0; j < groups.Count; j++) { itemPra.GetChild(j).GetChild(0).GetComponent().text = groups[j][0]; itemPra.GetChild(j).GetChild(1).GetComponent().text = groups[j][1]; itemPra.GetChild(j).GetChild(2).GetComponent().text = groups[j][2]; } //for (int k = 1; k < dataLength; k++) //{ // result[k*3+1] // QiXiangData data = new QiXiangData(); // data.index= //} //for (int i = 0; i < itemPra.childCount; i++) //{ // for (int j = 0; j < 3; j ++) // { // itemPra.GetChild(i).GetChild(j).GetComponent().text= // } //} } // Update is called once per frame void Update() { } } public class QiXiangData { public string index; public string sppedAndJoy; public string xuwen; }