using AX.InputSystem; using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public class TruckMessages : MonoBehaviour { public CarAttributeBase CarAttribute; public TruckSkillsEnum CurrentSkill; public bool IsR; public TruckSkillsEnum TruckSkills { get; private set; } public TruckSkillsEnum EnabledSkills { get { return enabledSkills; } set { // if (!IsR)//防止加载数据被初始化数据覆盖 enabledSkills = value; } } public TruckSkillsEnum enabledSkills; void Awake() { Initialize(); MessageDispatcher.AddListener("WaterSourceChanged", WaterSourceChanged); MessageDispatcher.AddListener("WaterSeparaterChange",WaterseparadChange); } private void OnDestroy() { MessageDispatcher.RemoveListener("WaterSourceChanged", WaterSourceChanged); MessageDispatcher.RemoveListener("WaterSeparaterChange", WaterseparadChange); } private void WaterseparadChange(IMessage obj) { if (GetComponent()) { var Id = GetComponent().gameObjID; Waterseparadata data = (Waterseparadata)obj.Data; if (Id==data.receiveId) { if (data.watertype == WaterType.water || data.watertype == WaterType.both)//普通水 { if (data.IsContent) { EnabledSkills |= TruckSkillsEnum.SprayWater; } else { EnabledSkills &= ~TruckSkillsEnum.SprayWater; if ((CurrentSkill & TruckSkillsEnum.SprayWater) != 0) { MessageDispatcher.SendMessage(Id, "WaterSwitch", data.IsContent); CurrentSkill &= ~TruckSkillsEnum.SprayWater; } } } if (data.watertype == WaterType.foam || data.watertype == WaterType.both)//泡沫 { if (data.IsContent) { EnabledSkills |= TruckSkillsEnum.SprayFoam; } else { EnabledSkills &= ~TruckSkillsEnum.SprayFoam; if ((CurrentSkill & TruckSkillsEnum.SprayFoam) != 0) { MessageDispatcher.SendMessage(Id, "WaterSwitch", data.IsContent); CurrentSkill &= ~TruckSkillsEnum.SprayFoam; } } } if (data.watertype == WaterType.none)//不供水 { if (data.IsContent) { //EnabledSkills |= TruckSkillsEnum.SprayFoam; } else { EnabledSkills &= ~TruckSkillsEnum.SprayFoam; if ((CurrentSkill & TruckSkillsEnum.SprayFoam) != 0) { MessageDispatcher.SendMessage(Id, "WaterSwitch", data.IsContent); CurrentSkill &= ~TruckSkillsEnum.SprayFoam; } EnabledSkills &= ~TruckSkillsEnum.SprayWater; if ((CurrentSkill & TruckSkillsEnum.SprayWater) != 0) { MessageDispatcher.SendMessage(Id, "WaterSwitch", data.IsContent); CurrentSkill &= ~TruckSkillsEnum.SprayWater; } } } if (TruckSkillSPanel.GetInstance.gameObject.activeSelf && SelectedObjs.selectedObj == gameObject) MessageDispatcher.SendMessage("TruckSkillsPanelDraw", gameObject); } } } private void WaterSourceChanged(IMessage obj) { var data = (WaterConnectionData)obj.Data; // var gameObjId = (long)obj.Sender; var Id = GetComponent().GameObjID; if (data.supplierID == Id) { if (data.connected) GetComponent().pathFindEnable = false; else { if (GetComponent().waterLineInfos.Count <= 0) GetComponent().pathFindEnable = true; } } if (data.receiverID != Id) return; GetComponent().pathFindEnable = !data.connected; if (data.type == WaterType.water|| data.type == WaterType.both)//普通水 { if (data.connected) { EnabledSkills |= TruckSkillsEnum.SprayWater; } else { EnabledSkills &= ~TruckSkillsEnum.SprayWater; if ((CurrentSkill & TruckSkillsEnum.SprayWater) != 0) { MessageDispatcher.SendMessage(Id, "WaterSwitch", data.connected); CurrentSkill &= ~TruckSkillsEnum.SprayWater; } } } if (data.type == WaterType.foam || data.type == WaterType.both)//泡沫 { if (data.connected) { EnabledSkills |= TruckSkillsEnum.SprayFoam; } else { EnabledSkills &= ~TruckSkillsEnum.SprayFoam; if ((CurrentSkill & TruckSkillsEnum.SprayFoam) != 0) { MessageDispatcher.SendMessage(Id, "WaterSwitch", data.connected); CurrentSkill &= ~TruckSkillsEnum.SprayFoam; } } } if (data.type == WaterType.none)//不供水 { if (data.connected) { //EnabledSkills |= TruckSkillsEnum.SprayFoam; } else { EnabledSkills &= ~TruckSkillsEnum.SprayFoam; if ((CurrentSkill & TruckSkillsEnum.SprayFoam) != 0) { MessageDispatcher.SendMessage(Id, "WaterSwitch", data.connected); CurrentSkill &= ~TruckSkillsEnum.SprayFoam; } EnabledSkills &= ~TruckSkillsEnum.SprayWater; if ((CurrentSkill & TruckSkillsEnum.SprayWater) != 0) { MessageDispatcher.SendMessage(Id, "WaterSwitch", data.connected); CurrentSkill &= ~TruckSkillsEnum.SprayWater; } } } if (TruckSkillSPanel.GetInstance.gameObject.activeSelf && SelectedObjs.selectedObj == gameObject) MessageDispatcher.SendMessage("TruckSkillsPanelDraw", gameObject); } void Initialize() { CarAttribute = CarAttributeRecord.GetCarAttributeByType(GetComponent().gameObjType); foreach (int v in Enum.GetValues(typeof(TruckSkillsEnum))) { string strName = Enum.GetName(typeof(TruckSkillsEnum), v); var truckskills = (TruckSkillsEnum)v; switch (truckskills) { case TruckSkillsEnum.Debarkation: if (GetComponent()) { TruckSkills |= truckskills; EnabledSkills |= truckskills; } //TruckSkills &= truckskills; //EnabledSkills &= ~truckskills; //Skills |= ~truckskills; break; case TruckSkillsEnum.SprayWater: if (GetComponent()) TruckSkills |= truckskills; if (GetComponent()) if (GetComponent().WaterReceiverType == WaterType.water || GetComponent().WaterReceiverType == WaterType.both) EnabledSkills |= truckskills; break; case TruckSkillsEnum.SprayFoam: if (GetComponent()) TruckSkills |= truckskills; if (GetComponent()) if (GetComponent().WaterReceiverType == WaterType.both || GetComponent().WaterReceiverType == WaterType.both) EnabledSkills |= truckskills; break; case TruckSkillsEnum.FixedSupport: if (GetComponent()) { TruckSkills |= truckskills; EnabledSkills |= truckskills; GetComponent().ArmLength = CarAttribute.Height; GetComponent().SetHeight(CarAttribute.Height); } break; case TruckSkillsEnum.AutomaticLiftArm: //if (GetComponent()) // TruckSkills |= truckskills; break; case TruckSkillsEnum.PackUpTheLiftArm: if (GetComponent()) TruckSkills |= truckskills; break; case TruckSkillsEnum.ForcibleEntry: //if (GetComponent()) // TruckSkills |= truckskills; break; case TruckSkillsEnum.Illumination: //if (GetComponent()) // TruckSkills |= truckskills; break; case TruckSkillsEnum.DischargeSmoke: //if (GetComponent()) // TruckSkills |= truckskills; break; case TruckSkillsEnum.SelectTarget: if (GetComponent()) { //该车辆包含此技能 TruckSkills |= truckskills; //该车辆可激活此技能按钮 //EnabledSkills |= truckskills; //暂不实现此功能 } break; case TruckSkillsEnum.AutoSwing: if (GetComponent()) { //该车辆包含此技能 TruckSkills |= truckskills; //该车辆可激活此技能按钮 //EnabledSkills |= truckskills; //暂不实现此功能 } break; case TruckSkillsEnum.SprayPowder: if(GetComponent()) { //该车辆包含此技能 TruckSkills |= truckskills; //该车辆可激活此技能按钮 //EnabledSkills |= truckskills; //暂不实现此功能 } break; default: break; } } IsR = false; } }