海淀天下城电子沙盘单机版
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.
 
 
 
 

325 lines
12 KiB

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<WaterReceiver>().waterlinelist.Contains(GetComponent<CloneGameObjInfo>().gameObjID))
{
waterReceiver.GetComponent<WaterReceiver>().waterlinelist.Remove(GetComponent<CloneGameObjInfo>().gameObjID);
}
}
if (waterReceiver && waterReceiver.GetComponent<WaterReceiver>())
{
waterReceiver.GetComponent<WaterReceiver>().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<BaseGameObjInfo>().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<WaterConnectionData>(eventData.json);
var thisID = GetComponent<BaseGameObjInfo>().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<WaterReceiver>().hasSupplier = true;
}
if (waterSupplier)
{
if (!waterSupplier.GetComponent<WaterSupplier>().waterLineInfos.Contains(GetComponent<CloneGameObjInfo>().gameObjID))
{
waterSupplier.GetComponent<WaterSupplier>().waterLineInfos.Add(GetComponent<CloneGameObjInfo>().gameObjID);
}
}
if (waterReceiver)
{
if (!waterReceiver.GetComponent<WaterReceiver>().waterlinelist.Contains(GetComponent<CloneGameObjInfo>().gameObjID))
{
waterReceiver.GetComponent<WaterReceiver>().waterlinelist.Add(GetComponent<CloneGameObjInfo>().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<ObjDrag>())
{
waterReceiver.GetComponent<ObjDrag>().enabled = false;
} //用水设备连接管线后不能拖拽
state = ConnectState.hasReceiver;
break;
case ConnectState.hasSupplier:
receiverID = value;
waterReceiver = EntitiesManager.Instance.GetEntityByID(receiverID);
if (waterReceiver != null)
{
waterReceiver.GetComponent<WaterReceiver>().hasSupplier = true;
if (waterReceiver.GetComponent<ObjDrag>())
{
waterReceiver.GetComponent<ObjDrag>().enabled = false;
}//用水设备连接管线后不能拖拽
if (!waterReceiver.GetComponent<WaterReceiver>().
waterlinelist.Contains(GetComponent<CloneGameObjInfo>().gameObjID))
{
waterReceiver.GetComponent<WaterReceiver>().
waterlinelist.Add(GetComponent<CloneGameObjInfo>().gameObjID);
}
}
if (waterSupplier != null)
{
if (!waterSupplier.GetComponent<WaterSupplier>().
waterLineInfos.Contains(GetComponent<CloneGameObjInfo>().gameObjID))
{
waterSupplier.GetComponent<WaterSupplier>().
waterLineInfos.Add(GetComponent<CloneGameObjInfo>().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;
}
}
}
/// <summary>
/// 解决帧回放时多余提示
/// </summary>
public bool tipFlag = true;
private void GetWaterSourceData(bool value,WaterConnectionData data)
{
data.waterLineID = GetComponent<BaseGameObjInfo>().gameObjID;
data.connected = value;
data.supplierID = this.supplierID;
data.receiverID = this.receiverID;
waterSupplier = EntitiesManager.Instance.GetEntityByID(supplierID);
if(waterSupplier != null)
{
//确定水源类型
var info = waterSupplier.GetComponent<BaseGameObjInfo>();
//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<WaterSupplier>().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
{
/// <summary>
/// 没有连接
/// </summary>
none,
/// <summary>
/// 连接水源
/// </summary>
hasSupplier,
/// <summary>
/// 连接用水设备
/// </summary>
hasReceiver,
/// <summary>
/// 既连接水源又连接用水设备
/// </summary>
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
}