You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
4.4 KiB
129 lines
4.4 KiB
4 years ago
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
/// <summary>
|
||
|
/// 水源,如消火栓
|
||
|
/// </summary>
|
||
|
public class WaterSupplier:MonoBehaviour
|
||
|
{
|
||
|
public WaterType WaterReceiverType;
|
||
|
private Vector3 connectPos;
|
||
|
public Transform connectPoint;
|
||
|
public List<long> waterLineInfos = new List<long>();
|
||
|
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<BaseGameObjInfo>().gameObjType;
|
||
|
eventData.eventType = RecordEventType.WaterSupplierAddLine;
|
||
|
RecordWaterSupplierInfo data = new RecordWaterSupplierInfo();
|
||
|
data.supplierID = GetComponent<BaseGameObjInfo>().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<BaseGameObjInfo>().gameObjType;
|
||
|
eventData.eventType = RecordEventType.WaterSupplierDelLine;
|
||
|
RecordWaterSupplierInfo data = new RecordWaterSupplierInfo();
|
||
|
data.supplierID = GetComponent<BaseGameObjInfo>().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<RecordWaterSupplierInfo>(eventData.json);
|
||
|
if(jsonData.supplierID == GetComponent<BaseGameObjInfo>().gameObjID)
|
||
|
{
|
||
|
//AddWaterLineInfo(jsonData.waterLineID);
|
||
|
}
|
||
|
}
|
||
|
else if (eventData.eventType == RecordEventType.WaterSupplierDelLine)
|
||
|
{
|
||
|
var jsonData = JsonUtility.FromJson<RecordWaterSupplierInfo>(eventData.json);
|
||
|
if (jsonData.supplierID == GetComponent<BaseGameObjInfo>().gameObjID)
|
||
|
{
|
||
|
DeleWaterLineInfo(jsonData.waterLineID);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public class RecordWaterSupplierInfo
|
||
|
{
|
||
|
public long supplierID;
|
||
|
public long waterLineID;
|
||
|
}
|