using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PowerDockPanel : UIView { public GameObject Item; public override void Awake() { base.Awake(); } public override void Show() { base.Show(); var url = HttpManager.Instance.GetPowerButtons; HttpManager.Instance.Get(url, data => { switch (PowerManager.Instance.powerButtonType) { case PowerButtonType.灾情设定: LoadButtons(data.DisaterForces); break; case PowerButtonType.消防力量: LoadButtons(data.FireForces); break; case PowerButtonType.内部力量: LoadButtons(data.InteriorForces); break; case PowerButtonType.联动力量: LoadButtons(data.LinkageForces); break; case PowerButtonType.标绘工具: LoadButtons(data.ToolForces); break; } }); } public override void Hide() { base.Hide(); UnloadButtons(); } private void LoadButtons(List Buttons) { foreach(PowerButton PB in Buttons) { GameObject go = Instantiate(Item) as GameObject; go.SetActive(true); go.transform.SetParent(Item.transform.parent, false); go.transform.Find("Tips/Label").GetComponent().text = PB.label; go.transform.Find("Mask/Icon").GetComponent().sprite =AssetManager.Instance.PowerAtlas.GetSprite(PB.icon); go.GetComponent().PowerName = PB.name; go.GetComponent().CreateMode = PB.mode; } } public void UnloadButtons() { var list = Item.transform.parent; for (int i = 0; i < list.childCount; i++) { if (list.GetChild(i).gameObject.activeSelf) { list.GetChild(i).GetComponent().isOn = false; Destroy(list.GetChild(i).gameObject); } } } }