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.
1003 lines
39 KiB
1003 lines
39 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using AX.MessageSystem; |
|
using AX.NetworkSystem; |
|
using System; |
|
|
|
public class WaterSourceSyncdata |
|
{ |
|
public long SenderId; |
|
public long GameobjId; |
|
public float AllUserWater; |
|
public float TotalFlow; |
|
public float AllUserFoam; |
|
// public bool hasover; |
|
} |
|
public class FlowValueChangeData |
|
{ |
|
public GameObject gameobj; |
|
public float flow; |
|
} |
|
//[RequireComponent(typeof(WATER_SOURCE_INFO_SYNC))] |
|
public class WaterSource : MonoBehaviour |
|
{ |
|
|
|
//绑定在水源上,喷水时判定是否连接了水源 |
|
public bool water;//有水 |
|
public bool foam;//有泡沫 |
|
public float TotalWater;//水总量(单位:升) |
|
public float AllUserWater;//使用总水量(单位:升) |
|
public bool hasover = false;//是否已经没水了 |
|
|
|
public float TotalFoam;//泡沫总量(单位:升) |
|
public float AllUserFoam;//使用泡沫量 |
|
|
|
/// <summary> |
|
/// 总流量 |
|
/// </summary> |
|
public float totalFlow; |
|
public float TotalFlow |
|
{ |
|
get |
|
{ |
|
return totalFlow; |
|
} |
|
|
|
set |
|
{ |
|
totalFlow = value; |
|
|
|
//分流 |
|
fenliu(value); |
|
//修改连接管线的流量是否有水流通过,用以判断管线能否被删除 |
|
|
|
WaterSourceSyncdata arg = new WaterSourceSyncdata() |
|
{ |
|
SenderId = CurrentUserInfo.mySelf.Id, |
|
GameobjId = GetComponent<BaseGameObjInfo>().gameObjID, |
|
AllUserWater = AllUserWater, |
|
TotalFlow = TotalFlow, |
|
AllUserFoam = AllUserFoam, |
|
//hasover = hasover |
|
}; |
|
|
|
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg); |
|
} |
|
} |
|
//该水源出水口直接或间接连接的所有出水物体集合 |
|
private List<long> outConnectObjIdList = new List<long>(); |
|
public List<long> OutConnectObjIdList |
|
{ |
|
get |
|
{ |
|
return outConnectObjIdList; |
|
} |
|
|
|
set |
|
{ |
|
outConnectObjIdList = value; |
|
//if (GetComponent<TruckMessage>()) |
|
//{//水源车 |
|
// if (GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count > 0) |
|
// { |
|
// long dir1 = GetComponent<TruckBindWaterSource>().WaterSourceLine1[0][0]; |
|
// GameObject dirobj1 = EntitiesManager.Instance.GetEntityByID(dir1); |
|
// dirobj1.GetComponent<WaterSource>().OutConnectObjIdList = GetOutSprayId(baseinfo.gameObjID, connectOrDelect); |
|
// } |
|
// if (GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count > 0) |
|
// { |
|
// long dir2 = GetComponent<TruckBindWaterSource>().WaterSourceLine2[0][0]; |
|
// GameObject dirobj2 = EntitiesManager.Instance.GetEntityByID(dir2); |
|
// dirobj2.GetComponent<WaterSource>().OutConnectObjIdList = GetOutSprayId(baseinfo.gameObjID, connectOrDelect); |
|
// } |
|
//} |
|
} |
|
} |
|
/// <summary> |
|
/// 自己本身以及连接的水源线上有没有水 |
|
/// </summary> |
|
private bool hasWaterSelfAndLine = true; |
|
public bool HasWaterSelfAndLine |
|
{ |
|
get |
|
{ |
|
return hasWaterSelfAndLine; |
|
} |
|
|
|
set |
|
{ |
|
bool prve = hasWaterSelfAndLine; |
|
hasWaterSelfAndLine = value; |
|
if (prve != value) |
|
{ |
|
if (prve == true) |
|
{//在出水,之前有水,现在没了,分流 |
|
if (GetComponent<TruckBindWaterSource>()) |
|
{ |
|
if (GetComponent<TruckBindWaterSource>().DirectConnectObj1.Key!=null) |
|
{ |
|
if (GetComponent<TruckBindWaterSource>().DirectConnectObj1.Key.GetComponent<TruckBindWaterSource>()) |
|
{//出水口1直接连接的是车 |
|
TruckBindWaterSource dircon1 = GetComponent<TruckBindWaterSource>().DirectConnectObj1.Key.GetComponent<TruckBindWaterSource>(); |
|
waterrunout(dircon1); |
|
} |
|
else |
|
{//直接连接bu为车(消防设施),只有一条管线 |
|
|
|
} |
|
} |
|
if(GetComponent<TruckBindWaterSource>().DirectConnectObj2.Key!=null) |
|
{ |
|
if (GetComponent<TruckBindWaterSource>().DirectConnectObj2.Key.GetComponent<TruckBindWaterSource>()) |
|
{//出水口2直接连接的是车 |
|
TruckBindWaterSource dircon2 = GetComponent<TruckBindWaterSource>().DirectConnectObj2.Key.GetComponent<TruckBindWaterSource>(); |
|
waterrunout(dircon2); |
|
} |
|
else |
|
{//直接连接不是车,只有一条管线,不存在分流 |
|
|
|
} |
|
} |
|
} |
|
} |
|
else |
|
{//本来没水了,又链接上了水源 |
|
if (GetComponent<TruckBindWaterSource>()) |
|
{ |
|
if (GetComponent<TruckBindWaterSource>().DirectConnectObj1.Key!=null&& GetComponent<TruckBindWaterSource>().DirectConnectObj1.Key.GetComponent<TruckBindWaterSource>()) |
|
{ |
|
if (GetComponent<TruckBindWaterSource>().DirectConnectObj1.Key.GetComponent<TruckBindWaterSource>()) |
|
{//出水口1直接连接的是车 |
|
TruckBindWaterSource dircon1 = GetComponent<TruckBindWaterSource>().DirectConnectObj1.Key.GetComponent<TruckBindWaterSource>(); |
|
waterConnectWhileNoWater(dircon1); |
|
|
|
} |
|
} |
|
if (GetComponent<TruckBindWaterSource>().DirectConnectObj2.Key != null && GetComponent<TruckBindWaterSource>().DirectConnectObj2.Key.GetComponent<TruckBindWaterSource>()) |
|
{ |
|
if (GetComponent<TruckBindWaterSource>().DirectConnectObj2.Key.GetComponent<TruckBindWaterSource>()) |
|
{//出水口2直接连接的是车 |
|
TruckBindWaterSource dircon2 = GetComponent<TruckBindWaterSource>().DirectConnectObj2.Key.GetComponent<TruckBindWaterSource>(); |
|
waterConnectWhileNoWater(dircon2); |
|
} |
|
} |
|
|
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
public Dictionary<long, float> OutFlowInfoDic = new Dictionary<long, float>(); |
|
/// <summary> |
|
/// 预计剩余时间 |
|
/// </summary> |
|
public int Remiantime; |
|
//连接的所有出水的物体 |
|
//private List<KeyValuePair<GameObject, float>> ConnectSprayKeyValueList = new List<KeyValuePair<GameObject, float>>(); |
|
private Dictionary<GameObject, float> ConnectSprayDic = new Dictionary<GameObject, float>(); |
|
|
|
//连接的所有出水的物体 |
|
// private List<GameObject> ConnectSprayobj = new List<GameObject>(); |
|
|
|
public GameObject ConnectGameObj; |
|
private BaseGameObjInfo baseinfo; |
|
private bool connectOrDelect;//执行的是连接还是删除操作 |
|
private float timer = 1; |
|
private TruckBindWaterSource tbws; |
|
|
|
|
|
void Start() |
|
{ |
|
baseinfo = GetComponent<BaseGameObjInfo>(); |
|
if (GetComponent<TruckBindWaterSource>()) |
|
{ |
|
tbws = GetComponent<TruckBindWaterSource>(); |
|
} |
|
//if (GetComponent<WATER_SOURCE_INFO_SYNC>()) |
|
//{ |
|
// gameObject.AddComponent<WATER_SOURCE_INFO_SYNC>(); |
|
//} |
|
if (GetComponent<TruckMessage>()) |
|
{ |
|
//if(foam) |
|
//{ |
|
// TotalWater = 15000;//15000 |
|
// TotalFoam = 3000;//3000; |
|
|
|
|
|
//} |
|
//else |
|
//TotalWater = 12000; //12000; |
|
|
|
//水源车(水罐车,泡沫车)暂时用产品定的载水量,泡沫量 |
|
//GetComponent<TruckMessage>().MyCarMessage.WaterAmount = (int)(TotalWater / 1000) ;//转换为吨 |
|
//GetComponent<TruckMessage>().MyCarMessage.FoamAmount = (int)(TotalFoam / 1000);//转换为吨 |
|
TotalWater = (float)GetComponent<TruckMessage>().MyCarMessage.WaterAmount * 1000; |
|
TotalFoam = (float)GetComponent<TruckMessage>().MyCarMessage.FoamAmount * 1000; |
|
} |
|
else |
|
{ |
|
if (foam) |
|
{ |
|
TotalFoam = -100; |
|
} |
|
TotalWater = -100; |
|
} |
|
MessageDispatcher.AddListener("WATERCAR_BIND_CURTAINHOSE", ConnectWaterCurtain); |
|
MessageDispatcher.AddListener("WATERCAR_DESTORY_CURTAINHOSE", DelectWaterCurtain); |
|
MessageDispatcher.AddListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectWaterHose); |
|
// MessageDispatcher.AddListener("FLOW_CHANGE", TotalFlowChange); |
|
|
|
//供水关系改为串联,并联等复杂关系后,再在这里统计实时供水总流量不对,转移到各个出水方。 |
|
GetRealtimeConsume.getAllRealtimeConsume += addMyRealtimeConsume; //统计实时流量 |
|
|
|
//GetAllUsed.getAllUsedAmount += addMyUsed; |
|
|
|
WaterUsedValue.getAllUsedWater += addMyUsed; //用水量统计 |
|
} |
|
|
|
|
|
|
|
void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("WATERCAR_BIND_CURTAINHOSE", ConnectWaterCurtain); |
|
MessageDispatcher.RemoveListener("WATERCAR_DESTORY_CURTAINHOSE", DelectWaterCurtain); |
|
MessageDispatcher.RemoveListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectWaterHose); |
|
// MessageDispatcher.RemoveListener("FLOW_CHANGE", TotalFlowChange); |
|
GetRealtimeConsume.getAllRealtimeConsume -= addMyRealtimeConsume; |
|
//GetAllUsed.getAllUsedAmount -= addMyUsed; |
|
WaterUsedValue.getAllUsedWater -= addMyUsed; |
|
} |
|
/// <summary> |
|
/// 删除水幕水带时的处理 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void DelectWaterCurtain(IMessage obj) |
|
{ |
|
if (!GetComponent<TruckMessage>()) |
|
{ |
|
WaterCarBindCurtainHose data = (WaterCarBindCurtainHose)obj.Data; |
|
if (GetComponent<BaseGameObjInfo>().gameObjID == data.WaterSourceObjId) |
|
{ |
|
//if (data.isConnect) |
|
{ |
|
ConnectGameObj = null; |
|
} |
|
} |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 连接水幕水带时水源上的处理,仅处理消防设施,用以判断是否还能再连接 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void ConnectWaterCurtain(IMessage obj) |
|
{ |
|
if (!GetComponent<TruckMessage>()) |
|
{ |
|
WaterCarBindCurtainHose data = (WaterCarBindCurtainHose)obj.Data; |
|
if (GetComponent<BaseGameObjInfo>().gameObjID == data.WaterSourceObjId) |
|
{ |
|
// if (data.isConnect) |
|
{ |
|
ConnectGameObj = data.WaterCurtainHose; |
|
} |
|
} |
|
} |
|
|
|
} |
|
|
|
/// <summary> |
|
/// 连接或删除管线水源上的处理,仅处理消防设施,用以判断是否还能再连接 |
|
/// </summary> |
|
/// <param name="obj"></param> |
|
private void ConnectOrDelectWaterHose(IMessage obj) |
|
{ |
|
if (!GetComponent<TruckMessage>()) |
|
{ |
|
HoseConnectOrDelectData data = (HoseConnectOrDelectData)obj.Data; |
|
if (data.StartId == GetComponent<BaseGameObjInfo>().gameObjID) |
|
{//只处理作为起点的 |
|
connectOrDelect = data.Isconnect; |
|
GameObject hose = EntitiesManager.Instance.GetEntityByID(data.HoseId); |
|
if (data.Isconnect) |
|
{ |
|
ConnectGameObj = hose.GetComponent<ParentLinesMessage>().GetAnotherGameObj(GetComponent<BaseGameObjInfo>().gameObjID); |
|
if (!GetComponent<TruckMessage>()) |
|
{//自己本身是消防设施(水源车辆在truckbindwatersource里处理过了) |
|
GameObject end= EntitiesManager.Instance.GetEntityByID(data.EndId); |
|
|
|
//以下处理连接终端车辆哪个进水口 |
|
if (end.GetComponent<TruckBindWaterSource>()) |
|
{ |
|
TruckBindWaterSource endtbw = end.GetComponent<TruckBindWaterSource>(); |
|
int inpoint = 1; |
|
if (endtbw.WaterSourceLine1.Count <= 0) |
|
{ |
|
inpoint = 1; |
|
} |
|
else |
|
{ |
|
if (endtbw.WaterSourceLine2.Count <= 0) |
|
{ |
|
inpoint = 2; |
|
} |
|
else |
|
{ |
|
Debug.LogError(end.name+"没有更多进水口"); |
|
} |
|
} |
|
WaterHoseEndDo arg = new WaterHoseEndDo |
|
{ |
|
ConnectHose = hose, |
|
StartId = baseinfo.gameObjID, |
|
ConnectInPoint = inpoint, |
|
EndId = data.EndId, |
|
}; |
|
MessageDispatcher.SendMessage("StartConnectDone", arg); |
|
} |
|
|
|
} |
|
|
|
} |
|
else |
|
{ |
|
ConnectGameObj = null; |
|
} |
|
//修改所有连接的出水物体的集合 |
|
//OutConnectObjIdList = GetOutSprayId(data.EndId, data.Isconnect); |
|
} |
|
} |
|
|
|
} |
|
|
|
//通过出水UI修改出水流量引起总流量变化 |
|
private void TotalFlowChange(IMessage obj) |
|
{ |
|
var data = (FlowValueChangeData)obj.Data; |
|
if (ConnectSprayDic.ContainsKey(data.gameobj)) |
|
{ |
|
TotalFlow -= ConnectSprayDic[data.gameobj]; |
|
ConnectSprayDic[data.gameobj] = data.flow; |
|
TotalFlow += ConnectSprayDic[data.gameobj]; |
|
} |
|
//个客户端水源各自计算自己的消耗 |
|
//水源信息同步,当有连接在该水源的物体通过UI改变出水大小时 |
|
WaterSourceSyncdata arg = new WaterSourceSyncdata() |
|
{ |
|
SenderId = CurrentUserInfo.mySelf.Id, |
|
GameobjId = GetComponent<BaseGameObjInfo>().gameObjID, |
|
AllUserWater = AllUserWater, |
|
TotalFlow = TotalFlow, |
|
AllUserFoam=AllUserFoam |
|
// hasover = hasover |
|
}; |
|
|
|
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg); |
|
} |
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
if (TotalFlow > 0) |
|
{ |
|
if (tbws != null) |
|
{//如果是水源车 |
|
if (tbws.GetComponent<BaseGameObjInfo>().UserID==CurrentUserInfo.mySelf.Id) |
|
{ |
|
var connect1 = tbws.WaterSourceLine1; |
|
var connect2 = tbws.WaterSourceLine2; |
|
float remain1 = tbws.checkWaterRemain(connect1); |
|
float remain2 = tbws.checkWaterRemain(connect2); |
|
if ((remain1 > 0 || remain1 == -100) || (remain2 > 0 || remain2 == -100)) |
|
{//上级水源有水 |
|
|
|
} |
|
else |
|
{//上级水源没水消耗自己 |
|
if (hasover == false) |
|
{ |
|
timer -= Time.deltaTime; |
|
if (timer <= 0) |
|
{ |
|
AllUserWater += TotalFlow; |
|
//消耗计算 |
|
|
|
if (AllUserWater >= TotalWater) |
|
{ |
|
AllUserWater = TotalWater; |
|
hasover = true; |
|
HasWaterSelfAndLine = false; |
|
OutFlowInfoDic.Clear(); |
|
TotalFlow = 0; |
|
} |
|
WaterSourceSyncdata arg = new WaterSourceSyncdata() |
|
{ |
|
SenderId = CurrentUserInfo.mySelf.Id, |
|
GameobjId = GetComponent<BaseGameObjInfo>().gameObjID, |
|
AllUserWater = AllUserWater, |
|
TotalFlow = TotalFlow, |
|
AllUserFoam = AllUserFoam |
|
//hasover = hasover |
|
}; |
|
|
|
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg); |
|
timer = 1; |
|
} |
|
} |
|
} |
|
// Debug.Log("tbws"+timer); |
|
} |
|
} |
|
else |
|
{//本身是消防设施 |
|
if (hasover == false) |
|
{ |
|
if (ConnectGameObj!=null) |
|
{ |
|
if ( ConnectGameObj.GetComponent<BaseGameObjInfo>().UserID == CurrentUserInfo.mySelf.Id) |
|
{ |
|
timer -= Time.deltaTime; |
|
if (timer <= 0) |
|
{ |
|
AllUserWater += TotalFlow; |
|
timer = 1; |
|
} |
|
WaterSourceSyncdata arg = new WaterSourceSyncdata() |
|
{ |
|
SenderId = CurrentUserInfo.mySelf.Id, |
|
GameobjId = GetComponent<BaseGameObjInfo>().gameObjID, |
|
AllUserWater = AllUserWater, |
|
TotalFlow = TotalFlow, |
|
AllUserFoam = AllUserFoam |
|
// hasover = hasover |
|
}; |
|
|
|
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg); |
|
} |
|
//Debug.Log("ws" + timer); |
|
} |
|
} |
|
} |
|
|
|
} |
|
} |
|
|
|
public void UserFoam(float use) |
|
{ |
|
if (TotalFoam == -100) |
|
{ |
|
AllUserFoam += use; |
|
TotalFoam = -100; |
|
} |
|
else |
|
{ |
|
if (TotalFoam > AllUserFoam) |
|
{ |
|
AllUserFoam += use; |
|
} |
|
else |
|
{ |
|
AllUserFoam = TotalFoam; |
|
} |
|
|
|
} |
|
WaterSourceSyncdata arg = new WaterSourceSyncdata() |
|
{ |
|
SenderId = CurrentUserInfo.mySelf.Id, |
|
GameobjId = GetComponent<BaseGameObjInfo>().gameObjID, |
|
AllUserWater = AllUserWater, |
|
TotalFlow = TotalFlow, |
|
AllUserFoam = AllUserFoam |
|
// hasover = hasover |
|
}; |
|
|
|
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg); |
|
} |
|
/// <summary> |
|
/// 用水消耗 |
|
/// </summary> |
|
/// <param name="use">每秒消耗量</param> |
|
public void UserWater(float use) |
|
{ |
|
if (TotalWater == -100) |
|
{ |
|
AllUserWater += use; |
|
TotalWater = -100; |
|
} |
|
else |
|
{ |
|
if (hasover == false) |
|
{ |
|
if (TotalWater > AllUserWater) |
|
{ |
|
//TotalWater -= use; |
|
AllUserWater += use; |
|
} |
|
//水用完了 |
|
else |
|
{ |
|
AllUserWater = TotalWater; |
|
hasover = true; |
|
|
|
MessageDispatcher.SendMessage("RUN_OUR_OF_WATER", GetComponent<BaseGameObjInfo>().gameObjID); |
|
TotalFlow = 0; |
|
WaterSourceSyncdata arg = new WaterSourceSyncdata() |
|
{ |
|
SenderId = CurrentUserInfo.mySelf.Id, |
|
GameobjId = GetComponent<BaseGameObjInfo>().gameObjID, |
|
AllUserWater = AllUserWater, |
|
TotalFlow = TotalFlow, |
|
AllUserFoam=AllUserFoam |
|
//hasover = hasover |
|
}; |
|
|
|
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg); |
|
} |
|
} |
|
} |
|
|
|
// 水源信息同步 |
|
//WaterSourceSyncdata arg = new WaterSourceSyncdata() |
|
//{ |
|
// SenderId = CurrentUserInfo.mySelf.Id, |
|
// GameobjId = GetComponent<BaseGameObjInfo>().gameObjID, |
|
// AllUserWater = AllUserWater, |
|
// TotalFlow = TotalFlow, |
|
// hasover = hasover |
|
//}; |
|
|
|
//NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg); |
|
} |
|
/// <summary> |
|
/// 设置当前水源的消耗总流量 |
|
/// </summary> |
|
public void SetTotalFlow(KeyValuePair<GameObject, float> flowinfo, bool IsAdd) |
|
{ |
|
if (!ConnectSprayDic.ContainsKey(flowinfo.Key) && IsAdd) |
|
{ |
|
ConnectSprayDic.Add(flowinfo.Key, flowinfo.Value); |
|
// ConnectSprayobj.Add(flowinfo.Key); |
|
} |
|
if (ConnectSprayDic.ContainsKey(flowinfo.Key) && !IsAdd) |
|
{ |
|
ConnectSprayDic.Remove(flowinfo.Key); |
|
// ConnectSprayobj.Remove(flowinfo.Key); |
|
} |
|
if (TotalFlow < 0) |
|
{ |
|
TotalFlow = 0; |
|
return; |
|
} |
|
else |
|
{ |
|
if (IsAdd) |
|
{ |
|
TotalFlow += flowinfo.Value; |
|
} |
|
else |
|
{ |
|
TotalFlow -= flowinfo.Value; |
|
} |
|
} |
|
//个客户端水源各自计算自己的消耗 |
|
//水源信息同步,当有连接在该水源的物体开始/关闭出水导致流量改变 |
|
WaterSourceSyncdata arg = new WaterSourceSyncdata() |
|
{ |
|
SenderId = CurrentUserInfo.mySelf.Id, |
|
GameobjId = GetComponent<BaseGameObjInfo>().gameObjID, |
|
AllUserWater = AllUserWater, |
|
TotalFlow = TotalFlow, |
|
AllUserFoam=AllUserFoam |
|
// hasover = hasover |
|
}; |
|
|
|
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg); |
|
} |
|
//获取剩余时间及水量 |
|
public KeyValuePair<int, float> GetRemainTimeAndWater() |
|
{ |
|
var timewater = new KeyValuePair<int, float>(); |
|
|
|
if (TotalWater == -100) |
|
{ |
|
timewater = new KeyValuePair<int, float>(-100, -100); |
|
//time = -1; |
|
} |
|
else |
|
{ |
|
float Remainwater = TotalWater - AllUserWater; |
|
int time = Mathf.CeilToInt(Remainwater / TotalFlow); |
|
timewater = new KeyValuePair<int, float>(time, Remainwater); |
|
} |
|
return timewater; |
|
} |
|
private FloatData addMyRealtimeConsume(FloatData data) |
|
{ |
|
if (!GetComponent<TruckMessage>()) |
|
{ |
|
data.value -= TotalFlow; |
|
} |
|
return data; |
|
} |
|
private FloatData addMyUsed(FloatData data) |
|
{ |
|
if (GetComponent<TruckMessage>()) |
|
{ |
|
data.value += AllUserWater; |
|
} |
|
return data; |
|
} |
|
/// <summary> |
|
/// 获取某条出水口上所有连接的物体 |
|
/// </summary> |
|
/// <param name="endid"></param> |
|
/// <param name="isconnect"></param> |
|
/// <returns></returns> |
|
public List<long> GetOutSprayId(long endid, bool isconnect) |
|
{ |
|
List<long> go = CloneBySerialize.Clone(OutConnectObjIdList); |
|
GameObject end = EntitiesManager.Instance.GetEntityByID(endid); |
|
if (end.GetComponent<WaterSource>()) |
|
{ |
|
if (end.GetComponent<TruckBindWaterSource>()) |
|
{ |
|
List<long> endlist = CloneBySerialize.Clone(end.GetComponent<WaterSource>().OutConnectObjIdList); |
|
if (isconnect) |
|
{ |
|
endlist.Add(endid); |
|
for (int i = 0; i < endlist.Count; i++) |
|
{ |
|
if (!go.Contains(endlist[i])) |
|
{ |
|
go.Add(endlist[i]); |
|
} |
|
} |
|
} |
|
else |
|
{ //删除的时候判断两根线是不是(直接或间接)?连着同一条线上的物体 |
|
if (GetComponent<TruckBindWaterSource>().DirectConnectObj1.Key == GetComponent<TruckBindWaterSource>().DirectConnectObj2.Key) |
|
{ |
|
|
|
} |
|
else |
|
{ |
|
for (int i = 0; i < endlist.Count; i++) |
|
{ |
|
if (go.Contains(endlist[i])) |
|
{ |
|
go.Remove(endlist[i]); |
|
} |
|
} |
|
go.Remove(endid); |
|
} |
|
} |
|
} |
|
} |
|
else |
|
{//非水源 |
|
if (isconnect) |
|
{ |
|
go.Add(endid); |
|
|
|
} |
|
else |
|
{ |
|
go.Remove(endid); |
|
} |
|
} |
|
return go; |
|
} |
|
|
|
public void TotalFlowChange(long changeid, float flow) |
|
{ |
|
if (!OutFlowInfoDic.ContainsKey(changeid)) |
|
{ |
|
OutFlowInfoDic.Add(changeid, flow); |
|
TotalFlow += flow; |
|
} |
|
else |
|
{ |
|
TotalFlow = TotalFlow - OutFlowInfoDic[changeid] + flow; |
|
if (TotalFlow<0) |
|
{ |
|
TotalFlow = 0; |
|
} |
|
//TotalFlow += (OutFlowInfoDic[changeid] - flow); |
|
OutFlowInfoDic[changeid] = flow; |
|
} |
|
} |
|
/// <summary> |
|
/// 修改总流量信息,一次连接一个出水网络 |
|
/// </summary> |
|
/// <param name="connectwaternet">直接连接的物体上的出水信息</param> |
|
public void TotalFlowChange(Dictionary<long, float> connectwaternet) |
|
{ |
|
|
|
} |
|
//void SetTotalFlowZero() |
|
//{ |
|
// for (int i = 0; i <OutFlowInfoDic.Count; i++) |
|
// { |
|
// OutFlowInfoDic[i] = 0; |
|
// } |
|
//} |
|
void fenliu(float value) |
|
{ |
|
if (GetComponent<TruckMessage>()) |
|
{ |
|
TruckBindWaterSource tbws = GetComponent<TruckBindWaterSource>(); |
|
float remain1 = tbws.checkWaterRemain(tbws.WaterSourceLine1); |
|
float remain2 = tbws.checkWaterRemain(tbws.WaterSourceLine2); |
|
if (tbws.WaterSourceLine1.Count > 0 && tbws.WaterSourceLine2.Count > 0) |
|
{//两条线都连接水源 |
|
|
|
GameObject dir1 = EntitiesManager.Instance.GetEntityByID(tbws.WaterSourceLine1[0][0]); |
|
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(tbws.WaterSourceLine2[0][0]); |
|
if ((remain1 > 0 || remain1 == -100)) |
|
{//线1有水 |
|
if (remain2 > 0 || remain2 == -100) |
|
{//线2有水,平分 |
|
dir1.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, value / 2); |
|
dir2.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, value / 2); |
|
} |
|
else |
|
{//线2没水,全加到线1上 |
|
dir1.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, value); |
|
dir2.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, 0); |
|
} |
|
} |
|
else |
|
{//线1没水 |
|
if (remain2 > 0 || remain2 == -100) |
|
{//线2有水 |
|
dir2.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, value); |
|
dir1.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, 0); |
|
} |
|
else |
|
{//线2没水 |
|
dir2.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, 0); |
|
dir1.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, 0); |
|
} |
|
} |
|
} |
|
else if (tbws.WaterSourceLine1.Count > 0 && tbws.WaterSourceLine2.Count <= 0) |
|
{//线1有水源,线2没有 |
|
GameObject dir1 = EntitiesManager.Instance.GetEntityByID(tbws.WaterSourceLine1[0][0]); |
|
|
|
if (remain1 > 0 || remain1 == -100) |
|
{//线1有水 |
|
dir1.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, value); |
|
} |
|
else |
|
{ |
|
dir1.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, 0); |
|
} |
|
} |
|
else if (tbws.WaterSourceLine1.Count <= 0 && tbws.WaterSourceLine2.Count > 0) |
|
{//线1没水源,线2有 |
|
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(tbws.WaterSourceLine2[0][0]); |
|
if (remain2 > 0 || remain2 == -100) |
|
{ |
|
dir2.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, value); |
|
} |
|
else |
|
{ |
|
dir2.GetComponent<WaterSource>().TotalFlowChange(baseinfo.gameObjID, 0); |
|
} |
|
} |
|
else if (tbws.WaterSourceLine1.Count <= 0 && tbws.WaterSourceLine2.Count <= 0) |
|
{//两条线都没连接水源 |
|
|
|
} |
|
} |
|
} |
|
void changeHasWaterCross(float value) |
|
{ |
|
if (GetComponent<TruckMessage>()) |
|
{ |
|
List<GameObject> connectwaterhose = GetComponent<TruckBindWaterSource>().allConnectWaterHose; |
|
int count = 0; |
|
for (int i = 0; i < connectwaterhose.Count; i++) |
|
{ |
|
if (connectwaterhose[i].GetComponent<ParentLinesMessage>().EndHitGameObj == gameObject) |
|
{ |
|
count++; |
|
} |
|
} |
|
|
|
|
|
if (count > 0) |
|
{ |
|
for (int i = 0; i < connectwaterhose.Count; i++) |
|
{ |
|
if (connectwaterhose[i].GetComponent<ParentLinesMessage>().EndHitGameObj == gameObject) |
|
{ |
|
//if (value > 0) |
|
//{ |
|
// connectwaterhose[i].GetComponent<ParentLinesMessage>().HasWaterCross = true; |
|
//} |
|
//else |
|
//{ |
|
// connectwaterhose[i].GetComponent<ParentLinesMessage>().HasWaterCross = false; |
|
//} |
|
|
|
} |
|
} |
|
} |
|
|
|
|
|
} |
|
|
|
} |
|
/// <summary> |
|
/// 水用完了流量处理 |
|
/// </summary> |
|
/// <param name="dircon"></param> |
|
void waterrunout(TruckBindWaterSource dircon) |
|
{ |
|
if (dircon.GetComponent<WaterSource>()) |
|
{ |
|
WaterSource dirws = dircon.GetComponent<WaterSource>(); |
|
if (dirws.TotalWater<=dirws.AllUserWater) |
|
{ |
|
dirws.HasWaterSelfAndLine = false; |
|
} |
|
} |
|
// TruckBindWaterSource dircon1 = GetComponent<TruckBindWaterSource>().DirectConnectObj1.Key.GetComponent<TruckBindWaterSource>(); |
|
if (dircon.WaterSourceLine1.Count > 0 && dircon.WaterSourceLine2.Count > 0) |
|
{//两条线都连了水源 |
|
|
|
if (dircon.WaterSourceLine1[0][0] == baseinfo.gameObjID) |
|
{//自己连接的是线路1 |
|
//注:如果线路2连接的也是自己,自己没有水,不会走有水的判断 |
|
float line2water = dircon.checkWaterRemain(dircon.WaterSourceLine2); |
|
if (line2water > 0 || line2water == -100) |
|
{//线路2有水 |
|
GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, 0); |
|
//另一条线路上的直接连接水源分流 |
|
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(dircon.WaterSourceLine2[0][0]); |
|
if (dircon.GetComponent<WaterSource>()) |
|
{//直接连接为水源车 |
|
dir2.GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalFlow); |
|
} |
|
else |
|
{//非水源车 |
|
dir2.GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow); |
|
} |
|
|
|
} |
|
else |
|
{//线路2没水 |
|
|
|
} |
|
|
|
} |
|
else |
|
{//自己连的线路2 |
|
float line1water = dircon.checkWaterRemain(dircon.WaterSourceLine1); |
|
if (line1water > 0 || line1water == -100) |
|
{//线路1有水 |
|
GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, 0); |
|
//另一条线路上的直接连接水源分流 |
|
GameObject dir1 = EntitiesManager.Instance.GetEntityByID(dircon.WaterSourceLine1[0][0]); |
|
if (dircon.GetComponent<WaterSource>()) |
|
{//水源车 |
|
dir1.GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalFlow); |
|
} |
|
else |
|
{//非水源车 |
|
dir1.GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow); |
|
} |
|
} |
|
else |
|
{//线路1没水 |
|
|
|
} |
|
} |
|
} |
|
else |
|
{//只练了一条线路 |
|
|
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 车辆没水时连接水源,连接时分流处理 |
|
/// </summary> |
|
/// <param name="dircon1"></param> |
|
void waterConnectWhileNoWater(TruckBindWaterSource dircon) |
|
{ |
|
if (dircon.GetComponent<WaterSource>()&&dircon.GetComponent<WaterSource>().HasWaterSelfAndLine==false) |
|
{ |
|
dircon.GetComponent<WaterSource>().HasWaterSelfAndLine = true; |
|
} |
|
if (dircon.WaterSourceLine1.Count > 0 && dircon.WaterSourceLine2.Count > 0) |
|
{ //连接的车的两条进水口都连接了 |
|
if (baseinfo.gameObjID == dircon.WaterSourceLine1[0][0] && baseinfo.gameObjID != dircon.WaterSourceLine2[0][0]) |
|
{//自己连在1上 |
|
GameObject Direline2 = EntitiesManager.Instance.GetEntityByID(dircon.WaterSourceLine2[0][0]); |
|
float antherline = dircon.checkWaterRemain(dircon.WaterSourceLine2); |
|
if (antherline > 0 || antherline == -100) |
|
{//另一条有水 |
|
if (dircon.GetComponent<WaterSource>()) |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalFlow / 2); |
|
Direline2.GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalFlow / 2); |
|
} |
|
else |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow / 2); |
|
Direline2.GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow / 2); |
|
} |
|
|
|
} |
|
else |
|
{//另一条没水 |
|
if (dircon.GetComponent<WaterSource>()) |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalFlow); |
|
} |
|
else |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow); |
|
} |
|
} |
|
} |
|
else if (baseinfo.gameObjID == dircon.WaterSourceLine2[0][0] && baseinfo.gameObjID != dircon.WaterSourceLine1[0][0]) |
|
{//自己连在2上 |
|
GameObject Direline1 = EntitiesManager.Instance.GetEntityByID(dircon.WaterSourceLine1[0][0]); |
|
float antherline = dircon.checkWaterRemain(dircon.WaterSourceLine1); |
|
if (antherline > 0 || antherline == -100) |
|
{//另一条有水 |
|
if (dircon.GetComponent<WaterSource>()) |
|
{//连接的是水源车 |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalFlow / 2); |
|
Direline1.GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalFlow / 2); |
|
} |
|
else |
|
{//连接的是非水源车 |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow / 2); |
|
Direline1.GetComponent<WaterSource>().TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow / 2); |
|
} |
|
} |
|
else |
|
{//另一条没水 |
|
if (dircon.GetComponent<WaterSource>()) |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalWater); |
|
} |
|
else |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow); |
|
} |
|
} |
|
} |
|
else if (baseinfo.gameObjID == dircon.WaterSourceLine2[0][0] && baseinfo.gameObjID == dircon.WaterSourceLine1[0][0]) |
|
{//两根都连接的本车辆 |
|
if (dircon.GetComponent<WaterSource>()) |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalWater); |
|
} |
|
else |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow); |
|
} |
|
} |
|
} |
|
else if (dircon.WaterSourceLine1.Count > 0 && dircon.WaterSourceLine2.Count <= 0|| |
|
dircon.WaterSourceLine1.Count <= 0 && dircon.WaterSourceLine2.Count > 0) |
|
{//只连接了一进水口, |
|
if (dircon.GetComponent<WaterSource>()) |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<WaterSource>().TotalFlow); |
|
} |
|
else |
|
{ |
|
TotalFlowChange(dircon.GetComponent<BaseGameObjInfo>().gameObjID, dircon.GetComponent<TruckBindWaterSource>().Flow); |
|
} |
|
} |
|
} |
|
} |
|
|
|
|