using AX.MessageSystem; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 水源,如消火栓 /// public class WaterSupplier:MonoBehaviour { public WaterType WaterReceiverType; private Vector3 connectPos; public Transform connectPoint; public List waterLineInfos = new List(); private void Start() { connectPoint = transform.Find("ConnectPoint"); if (connectPoint != null) { connectPos = connectPoint.position; } else { connectPos = transform.position; } MessageDispatcher.AddListener("WaterSourceChanged", WaterLineChanged); MessageDispatcher.AddListener("ReplayEvent", ReplayEvent); } private void OnDestroy() { MessageDispatcher.RemoveListener("WaterSourceChanged", WaterLineChanged); MessageDispatcher.RemoveListener("ReplayEvent", ReplayEvent); } public Vector3 ConnectPos { get { if (connectPoint != null) { connectPos = connectPoint.position; } else { connectPos = transform.position; } return connectPos; } } public void AddWaterLineInfo(long waterLineID) { if (!waterLineInfos.Contains(waterLineID)) { waterLineInfos.Add(waterLineID); AddRecordAddEvent(waterLineID); } } public void DeleWaterLineInfo(long waterLineID) { if (waterLineInfos.Contains(waterLineID)) { waterLineInfos.Remove(waterLineID); AddRecordDeleteEvent(waterLineID); } } private void AddRecordAddEvent(long waterLineID) { 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.WaterSupplierAddLine; RecordWaterSupplierInfo data = new RecordWaterSupplierInfo(); data.supplierID = GetComponent().gameObjID; data.waterLineID = waterLineID; eventData.json = JsonUtility.ToJson(data); RecordManager.Instance.jsonData.eventDataList.Add(eventData); } } private void WaterLineChanged(IMessage obj) { var data = (WaterConnectionData)obj.Data; if (data.connected == false) { DeleWaterLineInfo(data.waterLineID); } } private void AddRecordDeleteEvent(long waterLineID) { 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.WaterSupplierDelLine; RecordWaterSupplierInfo data = new RecordWaterSupplierInfo(); data.supplierID = GetComponent().gameObjID; data.waterLineID = waterLineID; eventData.json = JsonUtility.ToJson(data); RecordManager.Instance.jsonData.eventDataList.Add(eventData); } } private void ReplayEvent(IMessage obj) { var eventData = (EventData)obj.Data; if (eventData.eventType == RecordEventType.WaterSupplierAddLine) { var jsonData = JsonUtility.FromJson(eventData.json); if(jsonData.supplierID == GetComponent().gameObjID) { //AddWaterLineInfo(jsonData.waterLineID); } } else if (eventData.eventType == RecordEventType.WaterSupplierDelLine) { var jsonData = JsonUtility.FromJson(eventData.json); if (jsonData.supplierID == GetComponent().gameObjID) { DeleWaterLineInfo(jsonData.waterLineID); } } } } public class RecordWaterSupplierInfo { public long supplierID; public long waterLineID; }