using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class DisasterList : MonoBehaviour { public GameObject prefab; private static DisasterList instance; public static DisasterList Instance { get { return instance; } } private void Awake() { instance = this; } private void Start() { prefab = Resources.Load("Prefab/DisasterItem") as GameObject; //获取所有灾情 //GetDisasterList(); //生成 //CreateItems(); } public bool AnySelected() { if (GetComponent().AnyTogglesOn()) { return true; } else { return false; } } private void CreateItem(DisasterInfo msg) { GameObject item = Instantiate(prefab, transform); item.GetComponent().Set(msg); } public void DeleteDisaster(long Id) { //list.Remove(msg); for(int i = 0; i < transform.childCount; i++) { var id = transform.GetChild(i).GetComponent().msg.Id; if (id == Id) { Destroy(transform.GetChild(i).gameObject); } } } /// /// 显示当页灾情列表 /// /// public void ShowIndexDisasters(IEnumerable infos) { //3、生成当前页灾情列表 //先清空原有子物体 for (int i = 0; i < transform.childCount; i++) { Destroy(transform.GetChild(i).gameObject); } foreach(DisasterInfo msg in infos) { CreateItem(msg); } } public void UpdateDisasterInfo(DisasterInfo info) { for (int i = 0; i < transform.childCount; i++) { var id = transform.GetChild(i).GetComponent().msg.Id; if (id == info.Id) { transform.GetChild(i).GetComponent().Set(info); } } } }