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();}).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().text = UnitInput.text + "-" + NumberInput.text; OnIncrease(); } else { go.GetComponent().text = UnitInput.text; } } if (list[i].transform.Find("Info/Task")) { var task = list[i].transform.Find("Info/Task").gameObject; task.GetComponent().text = TaskInput.text; } list[i].GetComponent().Remarks = RemarksInput.text; if (list[i].GetComponent().Remarks != string.Empty) list[i].GetComponent().RemarksObj.SetActive(true); else list[i].GetComponent().RemarksObj.SetActive(false); Hide(); UIManager.Instance.Hide(); } } 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(SetParent); } private void SetParent() { var panel =UIManager.Instance.GetView(); panel.transform.SetParent(transform, false); panel.GetComponent().anchoredPosition = new Vector2(5, 0); } }