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

129 lines
4.1 KiB

using UniRx;
using UnityEngine;
using UnityEngine.UI;
public class PowerAttributePanel : UIView
{
public InputField NumberInput;
public InputField UnitInput;
public InputField TaskInput;
public InputField RemarksInput;
public Button TaskButton;
public Button IncreaseButton;
public Button ReduceButton;
public Button CloseButton;
public Button SetButton;
public Toggle RemarksToggle;
public override void Awake()
{
base.Awake();
#region Button Click
IncreaseButton.OnClickAsObservable().Subscribe(_ => OnIncrease()).AddTo(gameObject);
ReduceButton.OnClickAsObservable().Subscribe(_ => OnReduce()).AddTo(gameObject);
CloseButton.OnClickAsObservable().Subscribe(_ => { Hide(); UIManager.Instance.Hide<PowerTaskListPanel>();}).AddTo(gameObject);
SetButton.OnClickAsObservable().Subscribe(_ => OnSetAttribute()).AddTo(gameObject);
TaskButton.OnClickAsObservable().Subscribe(_ => OpenTaskList()).AddTo(gameObject);
RemarksToggle.OnValueChangedAsObservable()
.Subscribe(value =>
{
if (value)
{
RemarksToggle.transform.Find("Icon").localEulerAngles = new Vector3(0,0,90);
RemarksInput.gameObject.SetActive(true);
}
else
{
RemarksToggle.transform.Find("Icon").localEulerAngles = new Vector3(0,0,180);
RemarksInput.gameObject.SetActive(false);
}
}).AddTo(gameObject);
#endregion
}
public override void Show()
{
base.Show();
if (PowerManager.Instance.taskType == TaskType.Character || PowerManager.Instance.taskType == TaskType.Car || PowerManager.Instance.taskType == TaskType.WaterMonitor)
{
TaskButton.interactable = true;
}
else
{
TaskButton.interactable = false;
}
}
public override void Hide()
{
base.Hide();
RemarksToggle.isOn = false;
}
private void OnSetAttribute()
{
var list = SelectionManager.GetSelectedObjects();
for (int i = 0; i < list.Count; i++)
{
if (list[i].transform.Find("Info/Name"))
{
var go = list[i].transform.Find("Info/Name").gameObject;
if (int.Parse(NumberInput.text) != 0)
{
go.GetComponent<TextMesh>().text = UnitInput.text + "-" + NumberInput.text;
OnIncrease();
}
else
{
go.GetComponent<TextMesh>().text = UnitInput.text;
}
}
if (list[i].transform.Find("Info/Task"))
{
var task = list[i].transform.Find("Info/Task").gameObject;
task.GetComponent<TextMesh>().text = TaskInput.text;
}
list[i].GetComponent<PowerController>().Remarks = RemarksInput.text;
if (list[i].GetComponent<PowerController>().Remarks != string.Empty)
list[i].GetComponent<PowerController>().RemarksObj.SetActive(true);
else
list[i].GetComponent<PowerController>().RemarksObj.SetActive(false);
Hide();
UIManager.Instance.Hide<PowerTaskListPanel>();
}
}
private void OnIncrease()
{
var number = int.Parse(NumberInput.text);
number++;
NumberInput.text = number.ToString();
}
public void OnReduce()
{
var number = int.Parse(NumberInput.text);
if (number > 0)
{
number--;
NumberInput.text = number.ToString();
}
}
private void OpenTaskList()
{
UIManager.Instance.Show<PowerTaskListPanel>(SetParent);
}
private void SetParent()
{
var panel =UIManager.Instance.GetView<PowerTaskListPanel>();
panel.transform.SetParent(transform, false);
panel.GetComponent<RectTransform>().anchoredPosition = new Vector2(5, 0);
}
}