using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class FireManSkillsPanel : ResourceLoadPanel { public GameObject chooseObj; private Transform panel; private Toggle layerwaterHose; private Toggle layliftSavingFlarePath; private Toggle forcibleEntry; private Toggle dischargeSmoke; private Toggle lighting; private Toggle sprayWater; private Toggle sprayFoam; private Toggle decontamination; public bool IsChange = false;//该变量用来判断是不是换选.是的话,换选的时候不执行子物体toggle中的ison事件 void Awake() { MessageDispatcher.AddListener("CANCEL_SELECTED_COMMAND", EscCancelSelected); MessageDispatcher.AddListener("SelectChange", SelectChange); MessageDispatcher.AddListener("FiremanSkillsPanelDraw", setData); MessageDispatcher.AddListener("DeleteObj", DeleteObj); //MessageDispatcher.AddListener("LayWaterHoseToggle", LayWaterHose); //MessageDispatcher.AddListener("LayLifeSavingFlarePathToggle", LayLifeSavingFlarePath); //MessageDispatcher.AddListener("SprayWaterToggle", SprayWater); //MessageDispatcher.AddListener("SprayFoamToggle", SprayFoam); //MessageDispatcher.AddListener("DecontaminationToggle", Decontamination); //MessageDispatcher.AddListener("ForcibleEntryToggle", ForcibleEntry); //MessageDispatcher.AddListener("DischargeSmokeToggle", DischargeSmoke); //MessageDispatcher.AddListener("LightingToggle", Lightingfunc); //MessageDispatcher.AddListener("SaveToggle", Save); //MessageDispatcher.AddListener("AskPeopleToggle", AskPeople); //MessageDispatcher.AddListener("ClearDangerousToggle", ClearDangerous); //MessageDispatcher.AddListener("ClearSundriesToggle", ClearSundries); //MessageDispatcher.AddListener("PackUpLine", PackUpLine); //MessageDispatcher.AddListener("TagSearchRoom",TagSearchRoom); //MessageDispatcher.AddListener("EquipSelect", EquipSelectfunc); //equipSelect = GameObject.Find("Canvas").transform.Find("EquipSelect"); //bag = GameObject.Find("Canvas").transform.Find("Bag"); //equipSelect.GetComponent().Init(); panel = transform.Find("Scroll View/Viewport/Content/Panel"); forcibleEntry = panel.Find("ForcibleEntry").GetComponent(); dischargeSmoke = panel.Find("DischargeSmoke").GetComponent(); lighting = panel.Find("Lighting").GetComponent(); sprayWater = panel.Find("SprayWater").GetComponent(); sprayFoam = panel.Find("SprayFoam").GetComponent(); decontamination = panel.Find("Decontamination").GetComponent(); layerwaterHose = panel.Find("LayWaterHose").GetComponent(); layliftSavingFlarePath = panel.Find("LayLifeSavingFlarePath").GetComponent(); } public void CloseSprayToggle() { //if (!chooseObj.GetComponentInChildren()) //{ // if (chooseObj.GetComponent().workType == FireManSkills.SprayWater) // { // chooseObj.GetComponent().workType = FireManSkills.None; // } //} sprayWater.isOn = false; } public bool GetSprayOn() { return sprayWater.isOn; } public void CloselayhoseToggle() { layerwaterHose.isOn = false; } public void CloseLayLiftToggle() { layliftSavingFlarePath.isOn = false; } private void OnEnable() { IsChange = true; if (SelectedObjs.selectedCharacters.Count < 0) { gameObject.SetActive(false); } } void OnDisable() { chooseObj = null; IsChange = false; if (BagPanel.GetInstance.gameObject.activeInHierarchy) { BagPanel.GetInstance.gameObject.SetActive(false); } } private void EquipSelectfunc(IMessage obj) { EquipSelect.GetInstance.gameObject.SetActive(true); BagPanel.GetInstance.gameObject.SetActive(true); //bag.gameObject.SetActive(true); //equipSelect.gameObject.SetActive(true); } private void TagSearchRoom(IMessage obj) { Debug.Log("搜查房间"); } private void PackUpLine(IMessage obj) { Debug.Log("收起水带"); } private void ClearSundries(IMessage obj) { bool value = (bool)obj.Data; Debug.Log("清理杂物堆" + value); } private void ClearDangerous(IMessage obj) { bool value = (bool)obj.Data; Debug.Log("清理危险品" + value); } private void AskPeople(IMessage obj) { bool value = (bool)obj.Data; Debug.Log("询问知情人" + value); } private void Save(IMessage obj) { bool value = (bool)obj.Data; Debug.Log("疏散救生" + value); } private void Lightingfunc(IMessage obj) { bool value = (bool)obj.Data; Debug.Log("照明" + value); } private void DischargeSmoke(IMessage obj) { bool value = (bool)obj.Data; Debug.Log("排烟" + value); } private void ForcibleEntry(IMessage obj) { bool value = (bool)obj.Data; Debug.Log("破拆" + value); } private void SprayFoam(IMessage obj) { bool value = (bool)obj.Data; if (value) MessageDispatcher.SendMessage(chooseObj.GetComponent().GameObjID, "SprayFoam", value); // else // chooseObj.GetComponent().SetAnimAndHose(value); } private void Decontamination(IMessage obj) { bool value = (bool)obj.Data; if (value) MessageDispatcher.SendMessage(chooseObj.GetComponent().GameObjID, "Decontamination", value); //else //chooseObj.GetComponent().SetAnimAndHose(value); } private void SprayWater(IMessage obj) { bool value = (bool)obj.Data; if (value) MessageDispatcher.SendMessage(chooseObj.GetComponent().GameObjID, "SprayWater", value); // else //chooseObj.GetComponent().SetAnimAndHose(value); } private void LayLifeSavingFlarePath(IMessage obj) { bool value = (bool)obj.Data; Debug.Log("铺设救生照明线" + value); } private void LayWaterHose(IMessage obj) { bool value = (bool)obj.Data; Debug.Log("铺设管线" + value); } private void DeleteObj(IMessage message) { if (!gameObject.activeSelf) return; var obj = message.Data as GameObject; if (obj == chooseObj) gameObject.SetActive(false); } /// /// 单选换选 /// /// private void SelectChange(IMessage obj) { GameObject select = (GameObject)obj.Data; if (select.GetComponent()) { if (select != chooseObj) { IsChange = true; chooseObj = select; FireManSkillsPanel.GetInstance.gameObject.SetActive(true); Bag bag = select.GetComponent(); setUI(bag); SetHasWater(chooseObj); SetToggle(); IsChange = false; } else { if (!FireManSkillsPanel.GetInstance.gameObject.activeInHierarchy) { FireManSkillsPanel.GetInstance.gameObject.SetActive(true); } } } else { FireManSkillsPanel.GetInstance.gameObject.SetActive(false); } } private void EscCancelSelected(IMessage obj) { gameObject.SetActive(false); } void Init() { //TruckArmPanel = transform.Find("TruckArmPanel").gameObject; //cloneObjType = SelectedObjs.selectedObj.GetComponent().gameObjType; } private void setData(IMessage obj) { var newChoose = (GameObject)obj.Data; gameObject.SetActive(true); chooseObj = newChoose; Bag bag = newChoose.GetComponent(); setUI(bag); SetHasWater(chooseObj); SetToggle(); //IsChange = false; //MessageDispatcher.SendMessage("SetFireManSkills", chooseObj); } /// /// 控制消防员技能面板显示,特殊处理出水的消防员显示 /// void SetToggle() { if (this == null) { return; } FireManSkills chooseskill = chooseObj.GetComponent().workType; FireManSkillTogge[] all = GetComponentsInChildren(); for (int i = 0; i < all.Length; i++) { all[i].GetComponent().isOn = false; } for (int i = 0; i < all.Length; i++) { if (FireManSkills.SprayWater == chooseskill) { if (all[i].fireManSkills == FireManSkills.SprayWater) { all[i].flag = true; all[i].GetComponent().isOn = true; } } else { if (all[i].fireManSkills == chooseskill) { all[i].GetComponent().isOn = true; } } } } void SetHasWater(GameObject gameObject) { if (this==null) { return; } FireManMessage mess = gameObject.GetComponent(); if ((mess.EnabledSkills & FireManSkills.SprayWater) != 0) { sprayWater.interactable = true; } else { sprayWater.isOn = false; sprayWater.interactable = false; } if ((mess.EnabledSkills & FireManSkills.Decontamination) != 0) { decontamination.interactable = true; } else { decontamination.isOn = false; decontamination.interactable = false; } if ((mess.EnabledSkills & FireManSkills.SprayFoam) != 0) { sprayFoam.interactable = true; } else { sprayFoam.isOn = false; sprayFoam.interactable = false; } } private void OnDestroy() { MessageDispatcher.RemoveListener("CANCEL_SELECTED_COMMAND", EscCancelSelected); MessageDispatcher.RemoveListener("SelectChange", EscCancelSelected); MessageDispatcher.RemoveListener("FiremanSkillsPanelDraw", setData); MessageDispatcher.RemoveListener("DeleteObj", DeleteObj); MessageDispatcher.RemoveListener("LayWaterHose", LayWaterHose); MessageDispatcher.RemoveListener("LayLifeSavingFlarePath", LayLifeSavingFlarePath); MessageDispatcher.RemoveListener("SprayWater", SprayWater); MessageDispatcher.RemoveListener("SprayFoam", SprayFoam); MessageDispatcher.RemoveListener("DecontaminationToggle", Decontamination); MessageDispatcher.RemoveListener("ForcibleEntry", ForcibleEntry); MessageDispatcher.RemoveListener("DischargeSmoke", DischargeSmoke); MessageDispatcher.RemoveListener("Lighting", Lightingfunc); MessageDispatcher.RemoveListener("Save", Save); //MessageDispatcher.RemoveListener("AskPeople", AskPeople); //MessageDispatcher.RemoveListener("ClearDangerous", ClearDangerous); //MessageDispatcher.RemoveListener("ClearSundries", ClearSundries); MessageDispatcher.RemoveListener("PackUpLine", PackUpLine); MessageDispatcher.RemoveListener("TagSearchRoom", TagSearchRoom); MessageDispatcher.RemoveListener("EquipSelect", EquipSelectfunc); } public void setUI(Bag bag) { CheckBag(bag, "无齿锯", forcibleEntry); CheckBag(bag, "手提式防爆强光照明灯", lighting); CheckBag(bag, "移动式排烟机", dischargeSmoke); } void CheckBag(Bag bag, string equipName, Toggle toggle) { Equip EQ = bag.GetEquipFromBag(equipName); if (EQ != null) { toggle.interactable = true; } else { toggle.interactable = false; } } }