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

98 lines
3.4 KiB

using DG.Tweening;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class PlanController : MonoBehaviour
{
public Toggle PlanToggle;
public Button NewButton;
public Button DeleteButton;
// Start is called before the first frame update
void Start()
{
PlanToggle.onValueChanged.AddListener((bool value) => PlanToggleValueChanged(value));
NewButton.OnClickAsObservable()
.Subscribe(_ => NewNode()).AddTo(gameObject);
DeleteButton.OnClickAsObservable()
.Subscribe(_ => MessageBox.Show("确认删除?",Color.white, DeletePlan)).AddTo(gameObject);
}
private void NewNode()
{
PlanToggle.isOn = true;
UIManager.Instance.Show<NewSchemePanel>();
PowerManager.Instance.PlanMode = DisposalPlanMode.;
PowerManager.Instance.NodeParent = transform;
PowerManager.Instance.PlanName = name;
PowerManager.Instance.planController = this;
}
private void PlanToggleValueChanged(bool value)
{
if (value)
{
PowerManager.Instance.NodeParent = transform;
PowerManager.Instance.PlanName = name;
PowerManager.Instance.planController = this;
PlanToggle.transform.Find("Background").localEulerAngles = new Vector3(0,0,90);
Plans();
}
else
{
PlanToggle.transform.Find("Background").localEulerAngles = new Vector3(0, 0, 180);
foreach (Transform obj in transform)
{
if (obj.name != "Subtitles")
Destroy(obj.gameObject);
}
PowerManager.Instance.ClearAll();
}
}
private void Plans()
{
var plan =UIManager.Instance.GetView<DisposalPlanPanel>().Plans.Find(a => a.Name == name);
foreach(var item in plan.Nodes)
{
string id = item.Name;
GameObject go = Instantiate(UIManager.Instance.GetView<DisposalPlanPanel>().NodeItem) as GameObject;
go.SetActive(true);
go.name = id;
go.transform.SetParent(transform, false);
go.transform.Find("Load/Label").GetComponent<Text>().text = id;
LoadImage(go);
}
}
void LoadImage(GameObject go)
{
var plan = UIManager.Instance.GetView<DisposalPlanPanel>().Plans.Find(a => a.Name == name);
var node = plan.Nodes.Find(n => n.Name == go.name);
HttpManager.Instance.GetFile<NodeFile>(node.Id, actionResult =>
{
Debug.Log(actionResult.ImageUrl);
if (!string.IsNullOrEmpty(actionResult.ImageUrl))
HttpManager.Instance.GetImage($"{ actionResult.ImageUrl}?x-oss-process=image/resize,h_64", texture =>
{
var sp = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
go.transform.Find("ImageButton").GetComponent<Image>().sprite = sp;
});
go.GetComponent<NodeController>().ImageUrl = actionResult.ImageUrl;
});
}
private void DeletePlan()
{
var temp = UIManager.Instance.GetView<DisposalPlanPanel>().Plans.Find(a => a.Name == name);
UIManager.Instance.GetView<DisposalPlanPanel>().Plans.Remove(temp);
Destroy(gameObject);
UIManager.Instance.GetView<DisposalPlanPanel>().SavePlanList();
}
}