上海虹口龙之梦项目
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.
 
 
 
 

82 lines
2.2 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class PowerTaskListPanel : UIView
{
public GameObject Item;
public override void Awake()
{
base.Awake();
transform.Find("TitleBar/CloseButton").GetComponent<Button>().OnClickAsObservable()
.Subscribe(_ => Hide());
}
public override void Show()
{
base.Show();
LoadData();
}
public override void Hide()
{
base.Hide();
UnLoadData();
}
private void LoadData()
{
var url = HttpManager.Instance.GetPowerTasks;
HttpManager.Instance.Get<TaskDatas>(url, data =>
{
switch (PowerManager.Instance.taskType)
{
case TaskType.Character:
CreateList(data.Character);
break;
case TaskType.Car:
CreateList(data.Car);
break;
case TaskType.WaterMonitor:
CreateList(data.Firemonitor);
break;
}
});
}
private void CreateList(List<TaskData> list)
{
foreach (TaskData td in list)
{
GameObject go = Instantiate(Item) as GameObject;
go.SetActive(true);
go.transform.SetParent(Item.transform.parent, false);
go.transform.Find("Label").GetComponent<Text>().text = td.Task;
go.GetComponent<Toggle>().OnValueChangedAsObservable()
.Subscribe(value => OnItemValueChanged(value, td.Task)).AddTo(gameObject);
}
}
private void OnItemValueChanged(bool value, string task)
{
if (value)
{
UIManager.Instance.GetView<PowerAttributePanel>().TaskInput.text = task;
Hide();
}
}
private void UnLoadData()
{
var parent = Item.transform.parent;
for (int i = 0; i < parent.childCount; i++)
{
if (parent.GetChild(i).gameObject.activeSelf)
{
GameObject.Destroy(parent.GetChild(i).gameObject);
}
}
}
}