using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class WaterLineInfo : CloneGameObjInfo { public ConnectState state; private GameObject waterSupplier; private GameObject waterReceiver; private long supplierID = -1; private long receiverID = -1; public override void Awake() { base.Awake(); MessageDispatcher.AddListener("ReplayEvent", ReplayWaterLineDelet); MessageDispatcher.AddListener("ClearObject", Clear); } public override void OnDestroy() { base.OnDestroy(); WaterLineDelet(); MessageDispatcher.RemoveListener("ReplayEvent", ReplayWaterLineDelet); MessageDispatcher.RemoveListener("ClearObject", Clear); } private void Clear(IMessage obj) { WaterLineDelet(); state = ConnectState.none; } public void Resertinfo() { SupplierID = -1; ReceiverID = -1; state = ConnectState.none; } private void WaterLineDelet() { switch (state) { case ConnectState.none: break; case ConnectState.hasSupplier: break; case ConnectState.hasReceiver: break; case ConnectState.both: if (waterReceiver == null) waterReceiver = EntitiesManager.Instance.GetEntityByID(ReceiverID); if (waterSupplier == null) waterSupplier = EntitiesManager.Instance.GetEntityByID(SupplierID); if (waterReceiver) { if (waterReceiver.GetComponent().waterlinelist.Contains(GetComponent().gameObjID)) { waterReceiver.GetComponent().waterlinelist.Remove(GetComponent().gameObjID); } } if (waterReceiver && waterReceiver.GetComponent()) { waterReceiver.GetComponent().hasSupplier = false; WaterConnectionData data = new WaterConnectionData(); GetWaterSourceData(false, data); //通知水源变更 MessageDispatcher.SendMessage("WaterSourceChanged", data); AddRecordWaterLineDelet(data); } break; default: break; } } private void AddRecordWaterLineDelet(WaterConnectionData data) { if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) { var eventData = new EventData(); eventData.time = RecordManager.Instance.RecordTimer; eventData.cloneObjType = GetComponent().gameObjType; eventData.eventType = RecordEventType.WaterLineDele; string json = JsonUtility.ToJson(data); eventData.json = json; RecordManager.Instance.jsonData.eventDataList.Add(eventData); } } private void ReplayWaterLineDelet(IMessage obj) { var eventData = (EventData)obj.Data; if(eventData.eventType == RecordEventType.WaterLineDele) { WaterConnectionData data = JsonUtility.FromJson(eventData.json); var thisID = GetComponent().gameObjID; if (data.waterLineID == thisID) { //通知水源变更 MessageDispatcher.SendMessage("WaterSourceChanged", data); } } } public long SupplierID { get { return supplierID; } set { if (value == -1) return; switch (state) { case ConnectState.none: supplierID = value; waterSupplier = EntitiesManager.Instance.GetEntityByID(supplierID); state = ConnectState.hasSupplier; break; case ConnectState.hasSupplier: //已经连接水源,不能有多个水源 break; case ConnectState.hasReceiver: supplierID = value; waterSupplier = EntitiesManager.Instance.GetEntityByID(supplierID); if (waterSupplier != null) { waterReceiver.GetComponent().hasSupplier = true; } if (waterSupplier) { if (!waterSupplier.GetComponent().waterLineInfos.Contains(GetComponent().gameObjID)) { waterSupplier.GetComponent().waterLineInfos.Add(GetComponent().gameObjID); } } if (waterReceiver) { if (!waterReceiver.GetComponent().waterlinelist.Contains(GetComponent().gameObjID)) { waterReceiver.GetComponent().waterlinelist.Add(GetComponent().gameObjID); } } state = ConnectState.both; WaterConnectionData data = new WaterConnectionData(); GetWaterSourceData(true, data); MessageDispatcher.SendMessage("WaterSourceChanged", data); /*if ((ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) || ReplaySetting.PlayStatus ==PlayStatus.normal) ResourceLoadWindow.Instance.LoadTextHintWindow("连接管线成功", 2);*/ if (ReplaySetting.PlayStatus != PlayStatus.isReplay && tipFlag) { ResourceLoadWindow.Instance.LoadTextHintWindow("连接管线成功", 2); } MessageDispatcher.SendMessage("CANCEL_CLONEBTN_SELECTED_COMMAND"); break; case ConnectState.both: break; default: break; } } } public long ReceiverID { get { return receiverID; } set { if (value == -1) return; switch (state) { case ConnectState.none: receiverID = value; waterReceiver = EntitiesManager.Instance.GetEntityByID(receiverID); if (waterReceiver != null && waterReceiver.GetComponent()) { waterReceiver.GetComponent().enabled = false; } //用水设备连接管线后不能拖拽 state = ConnectState.hasReceiver; break; case ConnectState.hasSupplier: receiverID = value; waterReceiver = EntitiesManager.Instance.GetEntityByID(receiverID); if (waterReceiver != null) { waterReceiver.GetComponent().hasSupplier = true; if (waterReceiver.GetComponent()) { waterReceiver.GetComponent().enabled = false; }//用水设备连接管线后不能拖拽 if (!waterReceiver.GetComponent(). waterlinelist.Contains(GetComponent().gameObjID)) { waterReceiver.GetComponent(). waterlinelist.Add(GetComponent().gameObjID); } } if (waterSupplier != null) { if (!waterSupplier.GetComponent(). waterLineInfos.Contains(GetComponent().gameObjID)) { waterSupplier.GetComponent(). waterLineInfos.Add(GetComponent().gameObjID); } } state = ConnectState.both; WaterConnectionData data = new WaterConnectionData(); GetWaterSourceData(true, data); MessageDispatcher.SendMessage("WaterSourceChanged", data); /*if ((ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) || ReplaySetting.PlayStatus == PlayStatus.normal)*/ if(ReplaySetting.PlayStatus != PlayStatus.isReplay && tipFlag) { ResourceLoadWindow.Instance.LoadTextHintWindow("连接管线成功", 2); } MessageDispatcher.SendMessage("CANCEL_CLONEBTN_SELECTED_COMMAND"); break; case ConnectState.hasReceiver: //已经连接了用水设备不再连接其他 break; case ConnectState.both: //已经连接了用水设备不再连接其他 break; default: break; } } } /// /// 解决帧回放时多余提示 /// public bool tipFlag = true; private void GetWaterSourceData(bool value,WaterConnectionData data) { data.waterLineID = GetComponent().gameObjID; data.connected = value; data.supplierID = this.supplierID; data.receiverID = this.receiverID; waterSupplier = EntitiesManager.Instance.GetEntityByID(supplierID); if(waterSupplier != null) { //确定水源类型 var info = waterSupplier.GetComponent(); //switch (info.gameObjType) //{ // case CloneObjType.FoamTruck: // data.type = WaterType.both; // break; // case CloneObjType.WaterTanker: // data.type = WaterType.water; // break; // case CloneObjType.UHWSVehicle: // data.type = WaterType.water; // break; // case CloneObjType.WaterSupplyRepairCar: // data.type = WaterType.water; // break; // case CloneObjType.XHS: // data.type = WaterType.water; // break; // case CloneObjType.GDFSQ: // data.type = WaterType.both; // break; // default: // break; //} data.type = waterSupplier.GetComponent().WaterReceiverType; } else { data.type = WaterType.none; } } public GameObject GetWaterSupplier() { if (waterSupplier == null) waterSupplier = EntitiesManager.Instance.GetEntityByID(SupplierID); return waterSupplier; } public GameObject GetWaterReceiver() { if (waterReceiver == null) waterReceiver = EntitiesManager.Instance.GetEntityByID(ReceiverID); return waterReceiver; } } public enum ConnectState { /// /// 没有连接 /// none, /// /// 连接水源 /// hasSupplier, /// /// 连接用水设备 /// hasReceiver, /// /// 既连接水源又连接用水设备 /// both } [Serializable] public class WaterConnectionData { public long waterLineID; public long supplierID; public long receiverID; public bool connected; public WaterType type; } [Serializable] public enum WaterType { none=0, water=1, foam=2, both=3 }