using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using AX.MessageSystem; /// /// 属性设置按钮 /// public class AttributeSetting : BaseButton { private static AttributeSetting instance; public static AttributeSetting Instance { get { if (instance == null) { GameObject obj = Resources.Load("Common/AttributeSetting"); GameObject clone = Instantiate(obj, GameObject.Find("Canvas").transform); clone.transform.SetAsFirstSibling(); clone.name = "AttributeSetting"; instance = clone.GetComponent(); instance.init(); } return instance; } } private GameObject chooseObj; private List ShowAttriBtnTypeList; private BaseAttributeSet CurInstance; private void init() { gameObject.SetActive(false); InitShowAttriBtnTypeList(); } public override void OnEnable() { base.OnEnable(); MessageDispatcher.AddListener("CANCEL_SELECTED_COMMAND", EscCancelSelected);//ESC取消选中处理 MessageDispatcher.AddListener("CANCEL_OBJ_SELECTED", CancelObjSelected); MessageDispatcher.AddListener("DELETE_COMMAND", ObjDeleted); MessageDispatcher.AddListener("GROUP_DISMISS", ObjDeleted);//删除组 } public override void OnDisable() { base.OnDisable(); MessageDispatcher.RemoveListener("CANCEL_SELECTED_COMMAND", EscCancelSelected);//ESC取消选中处理 MessageDispatcher.RemoveListener("CANCEL_OBJ_SELECTED", CancelObjSelected); MessageDispatcher.RemoveListener("DELETE_COMMAND", ObjDeleted); MessageDispatcher.RemoveListener("GROUP_DISMISS", ObjDeleted);//删除组 } public override void OnDestroy() { base.OnDestroy(); MessageDispatcher.RemoveListener("CANCEL_SELECTED_COMMAND", EscCancelSelected);//ESC取消选中处理 MessageDispatcher.RemoveListener("CANCEL_OBJ_SELECTED", CancelObjSelected); MessageDispatcher.RemoveListener("DELETE_COMMAND", ObjDeleted); MessageDispatcher.RemoveListener("GROUP_DISMISS", ObjDeleted); } private void InitShowAttriBtnTypeList() { ShowAttriBtnTypeList = new List(); #region //车辆 //ShowAttriBtnTypeList.Add(CloneObjType.HighSprayingTruck); //ShowAttriBtnTypeList.Add(CloneObjType.FoamTruck); //ShowAttriBtnTypeList.Add(CloneObjType.AerialTowerTruck); //ShowAttriBtnTypeList.Add(CloneObjType.RescueVehicle); //ShowAttriBtnTypeList.Add(CloneObjType.Apparatus); //ShowAttriBtnTypeList.Add(CloneObjType.WaterTanker); //ShowAttriBtnTypeList.Add(CloneObjType.LadderTruck); //ShowAttriBtnTypeList.Add(CloneObjType.LightingAppliance); //ShowAttriBtnTypeList.Add(CloneObjType.ForcibleEntryTruck); //ShowAttriBtnTypeList.Add(CloneObjType.CCCar); //ShowAttriBtnTypeList.Add(CloneObjType.SmokeExhaustTruck); //ShowAttriBtnTypeList.Add(CloneObjType.UHWSVehicle); //ShowAttriBtnTypeList.Add(CloneObjType.ABICar); //ShowAttriBtnTypeList.Add(CloneObjType.ambulance); //ShowAttriBtnTypeList.Add(CloneObjType.PoliceCar); //ShowAttriBtnTypeList.Add(CloneObjType.PowerRepairVehicles); //ShowAttriBtnTypeList.Add(CloneObjType.GasEmergencyCar); //ShowAttriBtnTypeList.Add(CloneObjType.WaterSupplyRepairCar); #endregion #region//灾情 ShowAttriBtnTypeList.Add(CloneObjType.fireNormal); ShowAttriBtnTypeList.Add(CloneObjType.LiquidLevel); ShowAttriBtnTypeList.Add(CloneObjType.smokeNormal); ShowAttriBtnTypeList.Add(CloneObjType.forcibleEntryPoint); #endregion #region//工具 //ShowAttriBtnTypeList.Add(CloneObjType.securityInspector); //ShowAttriBtnTypeList.Add(CloneObjType.ObserveInspector); //ShowAttriBtnTypeList.Add(CloneObjType.SimulationEvacuate); //ShowAttriBtnTypeList.Add(CloneObjType.stagingArea); //ShowAttriBtnTypeList.Add(CloneObjType.InstanceText); //ShowAttriBtnTypeList.Add(CloneObjType.SetArea); //ShowAttriBtnTypeList.Add(CloneObjType.AttackLine); //ShowAttriBtnTypeList.Add(CloneObjType.RetreatLine); //ShowAttriBtnTypeList.Add(CloneObjType.BlockLine); //ShowAttriBtnTypeList.Add(CloneObjType.BrokenLine); //ShowAttriBtnTypeList.Add(CloneObjType.EjectSmokeLine); //ShowAttriBtnTypeList.Add(CloneObjType.WaterCannon); //ShowAttriBtnTypeList.Add(CloneObjType.ObligationFireman); #endregion //ShowAttriBtnTypeList.Add(CloneObjType.fireman); //ShowAttriBtnTypeList.Add(CloneObjType.Group); } public override void RespondFun() { if (!chooseObj || (CurInstance && CurInstance.gameObject.activeInHierarchy)) { return; } CloneObjType type = chooseObj.GetComponent().gameObjType; OpenPanelByType(type); } private void SetCurInstanceByType(CloneObjType type) { switch (type) { #region 车辆 //case CloneObjType.HighSprayingTruck: //case CloneObjType.FoamTruck: //case CloneObjType.AerialTowerTruck: //case CloneObjType.RescueVehicle: //case CloneObjType.Apparatus: //case CloneObjType.WaterTanker: //case CloneObjType.LadderTruck: //case CloneObjType.LightingAppliance: //case CloneObjType.ForcibleEntryTruck: //case CloneObjType.CCCar: //case CloneObjType.SmokeExhaustTruck: //case CloneObjType.UHWSVehicle: //case CloneObjType.ABICar: //case CloneObjType.ambulance: //case CloneObjType.PoliceCar: //case CloneObjType.PowerRepairVehicles: //case CloneObjType.GasEmergencyCar: //case CloneObjType.WaterSupplyRepairCar: // //CurInstance = TruckAttributePanel.Instance; // break; #endregion #region 工具 //case CloneObjType.ObserveInspector://观察哨 //case CloneObjType.SimulationEvacuate://模拟疏散 // //CurInstance = UIPlanPathPoint.Instance; // break; //case CloneObjType.stagingArea://集结区 // //CurInstance = UIPlanStagingArea.Instance; // break; //case CloneObjType.InstanceText://实例化文字 // //CurInstance = UIPlanInstanceText.Instance; // break; //case CloneObjType.SetArea://区域设置 // //CurInstance = UIPlanSetArea.Instance; // break; //case CloneObjType.AttackLine://进攻 //case CloneObjType.RetreatLine://撤退 //case CloneObjType.BlockLine://堵截 //case CloneObjType.BrokenLine://破拆 //case CloneObjType.EjectSmokeLine://排烟管 // //CurInstance = UIPlanLine.Instance; // break; //case CloneObjType.WaterCannon: // //CurInstance = UIPlanWaterCannon.Instance;//水炮 // break; #endregion #region 灾情 case CloneObjType.fireNormal://普通火 CurInstance = FireSpreadPanel.Instance; break; case CloneObjType.LiquidLevel://全液面火 CurInstance = FireLiquipPanel.Instance; break; case CloneObjType.smokeNormal://烟 CurInstance = SmokeSetPanel.Instance; break; case CloneObjType.forcibleEntryPoint://破拆 CurInstance = ForciblePanel.Instance; break; #endregion //case CloneObjType.fireman://消防员 //case CloneObjType.ObligationFireman://义务消防员 //case CloneObjType.securityInspector://安全哨 // //CurInstance = FireManAttributePanel.Instance; // break; //case CloneObjType.Group://消防员组 // //CurInstance = GroupAttributePanel.Instance; // break; default: CurInstance = null; break; } } /// /// 打开属性设置窗口 /// /// private void OpenPanelByType(CloneObjType type) { SetCurInstanceByType(type); if (CurInstance) { CurInstance.chooseObj = chooseObj; CurInstance.OpenPanel(); } } /// /// 打开属性设置按钮 /// public void OpenSettingsPanel(GameObject hitObj) { var type = hitObj.GetComponent().gameObjType; if (chooseObj && chooseObj == hitObj) {//避免重复打开 return; } if (!HasPanel(type)) {//判断是否选中的物体有属性设置窗口 Cancel(); return; } gameObject.SetActive(true); if (CurInstance && CurInstance.gameObject.activeSelf)//当前有属性面板在打开着 { var lastType = chooseObj.GetComponent().gameObjType; CurInstance.ResetData(chooseObj);//将原来物体属性重置 chooseObj = hitObj; if (lastType != type)//将要打开的不是同一类型的面板 { CurInstance.gameObject.SetActive(false); //打开新的属性设置窗口 OpenPanelByType(type); } else { CurInstance.chooseObj = chooseObj; CurInstance.LoadObjData(); } } chooseObj = hitObj; } /// /// ESC取消选中,隐藏按钮 /// /// private void EscCancelSelected(IMessage obj) { Cancel(); } /// /// 取消选中,隐藏按钮 /// /// private void CancelObjSelected(IMessage obj) { Cancel(); } /// /// 删除物体,隐藏按钮 /// /// private void ObjDeleted(IMessage obj) { Cancel(true); } /// /// 隐藏属性设置面板的属性设置按钮和属性设置窗口 /// private void Cancel(bool flagDelete = false) { if (!flagDelete && CurInstance) { CurInstance.gameObject.SetActive(false); } if (chooseObj != null && CurInstance != null) { SetCurInstanceByType(chooseObj.GetComponent().gameObjType); CurInstance.ResetData(chooseObj); } chooseObj = null; gameObject.SetActive(false); } /// /// 是否有对应的属性面板存在 /// /// /// private bool HasPanel(CloneObjType type) { return ShowAttriBtnTypeList.Contains(type); } }