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.
73 lines
2.2 KiB
73 lines
2.2 KiB
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<PowerButtons>(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<PowerButton> 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>().text = PB.label; |
|
go.transform.Find("Mask/Icon").GetComponent<Image>().sprite =AssetManager.Instance.PowerAtlas.GetSprite(PB.icon); |
|
go.GetComponent<PowerCreate>().PowerName = PB.name; |
|
go.GetComponent<PowerCreate>().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<Toggle>().isOn = false; |
|
Destroy(list.GetChild(i).gameObject); |
|
} |
|
|
|
} |
|
} |
|
}
|
|
|