You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.2 KiB
86 lines
2.2 KiB
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<ToggleGroup>().AnyTogglesOn()) |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
private void CreateItem(DisasterInfo msg) |
|
{ |
|
GameObject item = Instantiate(prefab, transform); |
|
item.GetComponent<DisasterItem>().Set(msg); |
|
} |
|
|
|
public void DeleteDisaster(long Id) |
|
{ |
|
//list.Remove(msg); |
|
for(int i = 0; i < transform.childCount; i++) |
|
{ |
|
var id = transform.GetChild(i).GetComponent<DisasterItem>().msg.Id; |
|
if (id == Id) |
|
{ |
|
Destroy(transform.GetChild(i).gameObject); |
|
} |
|
} |
|
} |
|
/// <summary> |
|
/// 显示当页灾情列表 |
|
/// </summary> |
|
/// <param name="list"></param> |
|
public void ShowIndexDisasters(IEnumerable<DisasterInfo> 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<DisasterItem>().msg.Id; |
|
if (id == info.Id) |
|
{ |
|
transform.GetChild(i).GetComponent<DisasterItem>().Set(info); |
|
} |
|
} |
|
} |
|
}
|
|
|