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

89 lines
2.7 KiB

using UnityEngine;
using UnityEngine.UI;
using UniRx;
using System.Collections.Generic;
public class AdjacentInfoPanel : UIView
{
public List<Text> infos;
public List<InputField> Edits;
public List<BuildingAdjacentReactive> Data;
public List<Text> East;
public List<Text> South;
public List<Text> West;
public List<Text> North;
public Button SaveButton;
public override void Awake()
{
base.Awake();
InitData();
SaveButton.OnClickAsObservable()
.Subscribe(_ => SaveData());
transform.Find("TitleBar/CloseButton").GetComponent<Button>().OnClickAsObservable()
.Subscribe(_ => Hide());
}
private void InitData()
{
Data = new List<BuildingAdjacentReactive>()
{
new BuildingAdjacentReactive(),
new BuildingAdjacentReactive(),
new BuildingAdjacentReactive(),
new BuildingAdjacentReactive()
};
Data[0].Id.Value = "East";
Data[1].Id.Value = "South";
Data[2].Id.Value = "West";
Data[3].Id.Value = "North";
//数据绑定
for (int i = 0; i < Data.Count; i++)
{
BuildingAdjacentReactive temp = Data[i];
int row = i * 3;
temp.Street.SubscribeToText(infos[row]).AddTo(gameObject);
temp.Building.SubscribeToText(infos[row + 1]).AddTo(gameObject);
temp.Distance.SubscribeToText(infos[row + 2]).AddTo(gameObject);
temp.Street.SubscribeToText(Edits[row]).AddTo(gameObject);
temp.Building.SubscribeToText(Edits[row + 1]).AddTo(gameObject);
temp.Distance.SubscribeToText(Edits[row + 2]).AddTo(gameObject);
Edits[row].OnValueChangedAsObservable().Subscribe(s => temp.Street.Value = s);
Edits[row + 1].OnValueChangedAsObservable().Subscribe(s => temp.Building.Value = s);
Edits[row + 2].OnValueChangedAsObservable().Subscribe(s => temp.Distance.Value = s);
}
}
private void SaveData()
{
foreach (var item in Data)
{
Debug.Log(item.GetData().Id);
string url = string.Format(HttpManager.Instance.PostBuildingAdjoinsById, item.Id.Value);
HttpManager.Instance.Post(url, item.GetData());
}
}
public override void Show()
{
base.Show();
GetData();
}
private void GetData()
{
string url = HttpManager.Instance.GetAllBuildingAdjoins;
HttpManager.Instance.Get<List<BuildingAdjacent>>(url, data =>
{
foreach (var item in data)
{
var temp = Data.Find(a => a.Id.Value == item.Id);
temp.SetData(item);
}
});
}
}