using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class VictoryConditionSetting { public int Count;//胜利条件条数 public int BurnedArea;//过火面积 public int FireManDied;//牺牲消防员个数 public int UnRescued;//未被营救的伤员和被困人员之和 public int BurnedTime;//燃烧时间 } public class VictoryConditionPanel : MonoBehaviour { public Transform VictoryScrollView; public Transform CountSettingInputField; public Transform FireAreaToggle; public Transform FireAreaInputField; public Transform FireManSettingToggle; public Transform FireMaSettingInputField; public Transform TrappedPersonToggle; public Transform TrappedPersonInputField; public Transform FireTimeToggle; public Transform FireTimeInputField; private Toggle[] all; public int SetCount; public int FireArea; public int FireMan; public int Trapped; public int FireTime; private void Awake() { MessageDispatcher.AddListener("LOAD_UIDISASTER", LoadUIDisaster); } // Use this for initialization void Start() { all = VictoryScrollView.transform.GetComponentsInChildren(); CountSettingInputField.GetComponent().OutInterFaceInPutField = CountSettingInputFieldChange; FireAreaToggle.GetComponent().OutInterFaceToggle = FireAreaToggleChange; FireAreaInputField.GetComponent().OutInterFaceInPutField = FireAreaInputFieldChange; FireManSettingToggle.GetComponent().OutInterFaceToggle = FireManSettingToggleChange; FireMaSettingInputField.GetComponent().OutInterFaceInPutField = FireMaSettingInputFieldChange; TrappedPersonToggle.GetComponent().OutInterFaceToggle = TrappedPersonToggleChange; TrappedPersonInputField.GetComponent().OutInterFaceInPutField = TrappedPersonInputFieldChange; FireTimeToggle.GetComponent().OutInterFaceToggle = FireTimeToggleChange; FireTimeInputField.GetComponent().OutInterFaceInPutField = FireTimeInputFieldChange; CountSettingInputField.GetComponentInChildren().ActivateInputField(); } private void OnDestroy() { MessageDispatcher.RemoveListener("LOAD_UIDISASTER", LoadUIDisaster); } private void LoadUIDisaster(IMessage obj) { if (GameSettings.othersSettings.isSelectedDisaster) { DataBind(); if (GameSettings.othersSettings.mode != Mode.DisasterManagement) {//若是练习或演习模式进入导调组界面,则不可以修改 CountSettingInputField.GetComponent().interactable = false; FireAreaToggle.GetComponent().interactable = false; FireAreaInputField.GetComponent().interactable = false; FireManSettingToggle.GetComponent().interactable = false; FireMaSettingInputField.GetComponent().interactable = false; TrappedPersonToggle.GetComponent().interactable = false; TrappedPersonInputField.GetComponent().interactable = false; FireTimeToggle.GetComponent().interactable = false; FireTimeInputField.GetComponent().interactable = false; } else { if (!GameSettings.disasterSetting.isEdit) {//若是灾情库设置模式的查看,则不可以修改 CountSettingInputField.GetComponent().interactable = false; FireAreaToggle.GetComponent().interactable = false; FireAreaInputField.GetComponent().interactable = false; FireManSettingToggle.GetComponent().interactable = false; FireMaSettingInputField.GetComponent().interactable = false; TrappedPersonToggle.GetComponent().interactable = false; TrappedPersonInputField.GetComponent().interactable = false; FireTimeToggle.GetComponent().interactable = false; FireTimeInputField.GetComponent().interactable = false; } else { //若是灾情库设置模式的编辑,则可以修改 } } } } public void VictoryConditionSettingFunction() { VictoryConditionSetting vs = new VictoryConditionSetting { Count = SetCount, BurnedArea = FireArea, FireManDied = FireMan, UnRescued = Trapped, BurnedTime = FireTime, }; Debug.Log(vs.Count + "setcount" + vs.BurnedArea + "firearea" + vs.FireManDied + "fireman" + vs.UnRescued + "trapped" + vs.BurnedTime + "firetime"); } public VictoryConditionSetting VictoryConditionSetting() { VictoryConditionSetting vs = new VictoryConditionSetting { Count = SetCount, BurnedArea = FireArea, FireManDied = FireMan, UnRescued = Trapped, BurnedTime = FireTime, }; return vs; Debug.Log(vs.Count + "setcount" + vs.BurnedArea + "firearea" + vs.FireManDied + "fireman" + vs.UnRescued + "trapped" + vs.BurnedTime + "firetime"); } void Update() { } /// /// 胜利条件条数设置 /// void countSettingActiveJudge() { //Toggle[] all = VictoryScrollView.transform.GetComponentsInChildren(); if (int.Parse(CountSettingInputField.GetComponentInChildren().text) >= 1) { FireAreaToggle.GetComponent().interactable = true; FireManSettingToggle.GetComponent().interactable = true; TrappedPersonToggle.GetComponent().interactable = true; FireTimeToggle.GetComponent().interactable = true; for (int i = 0; i < all.Length; i++) { all[i].isOn = false; } } else { FireAreaToggle.GetComponent().interactable = false; FireManSettingToggle.GetComponent().interactable = false; TrappedPersonToggle.GetComponent().interactable = false; FireTimeToggle.GetComponent().interactable = false; for (int i = 0; i < all.Length; i++) { all[i].isOn = false; } } } void toggleActiveJudge(Toggle myself, bool value, int max) { // Toggle[] all = VictoryScrollView.transform.GetComponentsInChildren(); if (value) { List ontoggle = new List(); for (int i = 0; i < all.Length; i++) { if (all[i].isOn) { ontoggle.Add(all[i]); } } if (ontoggle.Count == max) { for (int i = 0; i < all.Length; i++) { if (!ontoggle.Contains(all[i])) { all[i].interactable = false; } } } } else { for (int i = 0; i < all.Length; i++) { all[i].interactable = true; } } } //} //超过几条,演练失败 private void CountSettingInputFieldChange(string value) { if (string.IsNullOrEmpty(value) || value == "" || int.Parse(value) < 1) { CountSettingInputField.GetComponentInChildren().text = "0"; SetCount = 0; } else { CountSettingInputField.GetComponentInChildren().text = Mathf.Clamp(int.Parse(value.Substring(0, 1)), 0, all.Length).ToString(); SetCount = int.Parse(CountSettingInputField.GetComponentInChildren().text); } countSettingActiveJudge(); } /// /// 火灾面积toggle /// /// private void FireAreaToggleChange(bool value) { FireAreaToggle.parent.Find("InputField").GetComponent().interactable = value; //toggleActiveJudge(FireAreaToggle.GetComponent(), value, int.Parse(CountSettingInputField.GetComponentInChildren().text)); if (!value) FireAreaToggle.parent.Find("InputField").GetComponent().text = ""; } /// /// 火灾面积inputfield /// /// private void FireAreaInputFieldChange(string value) { if (string.IsNullOrEmpty(value)) { FireAreaInputField.GetComponentInChildren().text = ""; FireArea = 0; } else { FireAreaInputField.GetComponentInChildren().text = Mathf.Clamp(int.Parse(value), 0, 99999).ToString(); FireArea = int.Parse(FireAreaInputField.GetComponentInChildren().text); } } /// /// 消防员牺牲toggle /// /// private void FireManSettingToggleChange(bool value) { FireManSettingToggle.parent.Find("InputField").GetComponent().interactable = value; // toggleActiveJudge(FireManSettingToggle.GetComponent(), value, int.Parse(CountSettingInputField.GetComponentInChildren().text)); if (!value) FireManSettingToggle.parent.Find("InputField").GetComponent().text = ""; } /// /// 消防员牺牲Inputfield /// /// private void FireMaSettingInputFieldChange(string value) { if (string.IsNullOrEmpty(value)) { FireMaSettingInputField.GetComponentInChildren().text = ""; FireMan = 0; } else { FireMaSettingInputField.GetComponentInChildren().text = Mathf.Clamp(int.Parse(value), 0, 999).ToString(); FireMan = int.Parse(FireMaSettingInputField.GetComponentInChildren().text); } } /// /// 被困人员Toggle /// /// private void TrappedPersonToggleChange(bool value) { TrappedPersonToggle.parent.Find("InputField").GetComponent().interactable = value; //toggleActiveJudge(TrappedPersonToggle.GetComponent(), value, int.Parse(CountSettingInputField.GetComponentInChildren().text)); if (!value) TrappedPersonToggle.parent.Find("InputField").GetComponent().text = ""; } /// /// 被困人员Inputfield /// /// private void TrappedPersonInputFieldChange(string value) { if (string.IsNullOrEmpty(value)) { TrappedPersonInputField.GetComponentInChildren().text = ""; Trapped = 0; } else { TrappedPersonInputField.GetComponentInChildren().text = Mathf.Clamp(int.Parse(value), 0, 999).ToString(); Trapped = int.Parse(TrappedPersonInputField.GetComponentInChildren().text); } } /// /// 火灾时间Toggle /// /// private void FireTimeToggleChange(bool value) { FireTimeToggle.parent.Find("InputField").GetComponent().interactable = value; //toggleActiveJudge(FireTimeToggle.GetComponent(), value, int.Parse(CountSettingInputField.GetComponentInChildren().text)); if (!value) FireTimeToggle.parent.Find("InputField").GetComponent().text = ""; } /// /// 火灾时间Inputfield /// /// private void FireTimeInputFieldChange(string value) { if (string.IsNullOrEmpty(value)) { FireTimeInputField.GetComponentInChildren().text = ""; FireTime = 0; } else { FireTimeInputField.GetComponentInChildren().text = Mathf.Clamp(int.Parse(value), 0, 999).ToString(); FireTime = int.Parse(FireTimeInputField.GetComponentInChildren().text); } } /// /// 灾情库进来绑定胜利条件设置 /// private void DataBind() { SetCount = GameSettings.othersSettings.disaster.VictoryCondition.Count; CountSettingInputField.GetComponent().text = SetCount.ToString(); if (GameSettings.othersSettings.disaster.VictoryCondition.BurnedArea > 0) { FireAreaToggle.GetComponent().isOn = true; FireArea = GameSettings.othersSettings.disaster.VictoryCondition.BurnedArea; FireAreaInputField.GetComponent().text = FireArea.ToString(); } if (GameSettings.othersSettings.disaster.VictoryCondition.FireManDied > 0) { FireManSettingToggle.GetComponent().isOn = true; FireMan = GameSettings.othersSettings.disaster.VictoryCondition.FireManDied; FireMaSettingInputField.GetComponent().text = FireMan.ToString(); } if (GameSettings.othersSettings.disaster.VictoryCondition.UnRescued > 0) { TrappedPersonToggle.GetComponent().isOn = true; Trapped = GameSettings.othersSettings.disaster.VictoryCondition.UnRescued; TrappedPersonInputField.GetComponent().text = Trapped.ToString(); } if (GameSettings.othersSettings.disaster.VictoryCondition.BurnedTime > 0) { FireTimeToggle.GetComponent().isOn = true; FireTime = GameSettings.othersSettings.disaster.VictoryCondition.BurnedTime; FireTimeInputField.GetComponent().text = FireTime.ToString(); } } }