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.
2459 lines
115 KiB
2459 lines
115 KiB
4 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using AX.MessageSystem;
|
||
|
using System;
|
||
|
using AX.InputSystem;
|
||
|
using UnityEngine.UI;
|
||
|
using AX.NetworkSystem;
|
||
|
|
||
|
public class WaterHoseEndDo
|
||
|
{
|
||
|
public GameObject ConnectHose;//连接的管线
|
||
|
public long StartId;//连接管线的起点Id
|
||
|
public long EndId;//连接管线的终点物体Id
|
||
|
public int ConnectInPoint;//连接的进水口
|
||
|
}
|
||
|
public class TruckBindWaterSource : MonoBehaviour
|
||
|
{
|
||
|
public List<GameObject> allConnectWaterCurtainHose = new List<GameObject>();//水源车上连接的所有水幕水带
|
||
|
|
||
|
public List<GameObject> allConnectWaterHose = new List<GameObject>();
|
||
|
//注:本车辆的两个进水口直接连接水源即为两条进水路线的第0个索引值
|
||
|
private List<List<long>> waterSourceLine1 = new List<List<long>>();//当前水源车辆进水口线路1
|
||
|
private List<List<long>> waterSourceLine2 = new List<List<long>>();//当前水源车辆进水口线路1
|
||
|
|
||
|
public List<List<long>> WaterSourceLine1
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
return waterSourceLine1;
|
||
|
}
|
||
|
|
||
|
set
|
||
|
{
|
||
|
waterSourceLine1 = value;
|
||
|
//水源信息修改后其出水端连接的对象水源信息也要修改(出水口水源跟着修改)
|
||
|
checkOutAndChangeWaterInfo();
|
||
|
//if (connectWaterHose1 != null)
|
||
|
//{
|
||
|
// connectWaterHose1.GetComponent<ParentLinesMessage>().WaterSourceConnect = value;
|
||
|
//}
|
||
|
//for (int i = 0; i < WaterSourceLine1.Count; i++)
|
||
|
//{
|
||
|
// for (int j = 0; j < WaterSourceLine1[i].Count; j++)
|
||
|
// {
|
||
|
// Debug.Log(name + "水源" + EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[i][j]).name);
|
||
|
// }
|
||
|
//}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public List<List<long>> WaterSourceLine2
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
return waterSourceLine2;
|
||
|
}
|
||
|
|
||
|
set
|
||
|
{
|
||
|
waterSourceLine2 = value;
|
||
|
checkOutAndChangeWaterInfo();
|
||
|
//if (connectWaterHose2 != null)
|
||
|
//{
|
||
|
// connectWaterHose2.GetComponent<ParentLinesMessage>().WaterSourceConnect = value;
|
||
|
//}
|
||
|
//for (int i = 0; i < WaterSourceLine1.Count; i++)
|
||
|
//{
|
||
|
// for (int j = 0; j < WaterSourceLine1[i].Count; j++)
|
||
|
// {
|
||
|
// Debug.Log(name + "水源" + EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[i][j]).name);
|
||
|
// }
|
||
|
//}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public KeyValuePair<GameObject, int> DirectConnectObj1;//key当前水源车出水口1连接的物体,value为连接的出水车辆的哪个进水口,1为进水口1,2为进水口2,0则只有一个进水口
|
||
|
public KeyValuePair<GameObject, int> DirectConnectObj2;//key当前水源车出水口2连接的物体,value为连接的出水车辆的哪个进水口,1为进水口1,2为进水口2,0则只有一个进水口
|
||
|
private GameObject outtWaterHose1;//出水口1连接的管线
|
||
|
private GameObject outWaterHose2;//出水口2连接的管线
|
||
|
private GameObject inWaterHose1;//进水口1连接的管线
|
||
|
private GameObject inWaterHose2;//进水口2连接的管线
|
||
|
|
||
|
public bool ConnectWater;
|
||
|
public bool ConnectFoam;
|
||
|
public Transform Hose;
|
||
|
// public GameObject WaterStraightPrefabs;
|
||
|
// public GameObject FrothPrefabs;
|
||
|
public GameObject ConnentWaterSource;//连接的直接水源,用来判断能不能供泡沫
|
||
|
public float ParticleSize = 0.7f;//出水粒子大小
|
||
|
public bool waterrunoutof = false;//水是否用完
|
||
|
|
||
|
public SprayMode spraymode;//计算消耗的类型
|
||
|
|
||
|
public float flow;
|
||
|
/// <summary>
|
||
|
/// 剩余时间
|
||
|
/// </summary>
|
||
|
public int RemainTime;
|
||
|
/// <summary>
|
||
|
/// 剩余水量
|
||
|
/// </summary>
|
||
|
public float RemainWater;
|
||
|
|
||
|
private BaseGameObjInfo gameobjinfo;
|
||
|
|
||
|
private float timer = 1f;
|
||
|
|
||
|
public float Flow
|
||
|
{
|
||
|
get
|
||
|
{
|
||
|
return flow;
|
||
|
}
|
||
|
|
||
|
set
|
||
|
{
|
||
|
// float prve = flow;
|
||
|
flow = value;
|
||
|
//if (inWaterHose1)
|
||
|
//{
|
||
|
// inWaterHose1.GetComponent<ParentLinesMessage>().HasWaterCross = value > 0 ? true : false;
|
||
|
//}
|
||
|
//if (inWaterHose2)
|
||
|
//{
|
||
|
// inWaterHose2.GetComponent<ParentLinesMessage>().HasWaterCross = value > 0 ? true : false;
|
||
|
//}
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{//如果自己是水源,加到自己上
|
||
|
GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, flow);
|
||
|
}
|
||
|
else
|
||
|
{//自己不是水源,加到直接水源上
|
||
|
#region
|
||
|
//流量改变重新分流
|
||
|
// 要根据水源的出水物体集合找到对应的物体然后改变
|
||
|
// 检查供水线路是不是还有水
|
||
|
float remainwater1 = checkWaterRemain(WaterSourceLine1);
|
||
|
float remainwater2 = checkWaterRemain(WaterSourceLine2);
|
||
|
if (WaterSourceLine1.Count > 0 && WaterSourceLine2.Count > 0)
|
||
|
{//有两个水源给本车供水
|
||
|
|
||
|
GameObject dir1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]);
|
||
|
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]);
|
||
|
WaterSource ws1 = dir1.GetComponent<WaterSource>();
|
||
|
WaterSource ws2 = dir2.GetComponent<WaterSource>();
|
||
|
if (GetComponentInChildren<ParticleControlOfType>() &&
|
||
|
GetComponentInChildren<ParticleControlOfType>().particleType == SprayParticleType.Froth)
|
||
|
{//出的是泡沫,判断消耗哪边的水,泡沫不平均分配,updata里消耗的时候在传参计算
|
||
|
//float foamFlow = (Flow / 0.97f) * 0.03f;//泡沫流量
|
||
|
if (ws1.foam && (ws1.TotalFoam == -100 || (ws1.TotalFoam - ws1.AllUserFoam) > 0) && ws1.HasWaterSelfAndLine)
|
||
|
{//直接水源1是泡沫车并且有泡沫,且有水
|
||
|
if (ws2.foam && (ws2.TotalFoam == -100 || (ws2.TotalFoam - ws2.AllUserFoam) > 0 && ws2.HasWaterSelfAndLine))
|
||
|
{//直接水源2是泡沫车并且有泡沫,且有水
|
||
|
//水平分
|
||
|
ws1.TotalFlowChange(gameobjinfo.gameObjID, flow / 2);
|
||
|
ws2.TotalFlowChange(gameobjinfo.gameObjID, flow / 2);
|
||
|
}
|
||
|
else
|
||
|
{//直接水源2不是泡沫车或者没泡沫了,全摊到水源1上
|
||
|
ws1.TotalFlowChange(gameobjinfo.gameObjID, flow);
|
||
|
ws2.TotalFlowChange(gameobjinfo.gameObjID, 0);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (ws2.foam && (ws2.TotalFoam == -100 || (ws2.TotalFoam - ws2.AllUserFoam) > 0 && ws2.HasWaterSelfAndLine))
|
||
|
{
|
||
|
ws2.TotalFlowChange(gameobjinfo.gameObjID, flow);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log(name + "连接的水源没有泡沫");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//出的是水
|
||
|
if (ws1 && (remainwater1 > 0 || remainwater1 == -100))
|
||
|
{//如果进水口1直接连接的是车,并且进水口1有水
|
||
|
if (remainwater2 > 0 || remainwater2 == -100)
|
||
|
{//供水线路2也有水,两者平摊
|
||
|
ws1.TotalFlowChange(gameobjinfo.gameObjID, flow / 2);
|
||
|
ws2.TotalFlowChange(gameobjinfo.gameObjID, flow / 2);
|
||
|
}
|
||
|
}
|
||
|
else if (ws1 && !(remainwater1 > 0 || remainwater1 == -100))
|
||
|
{//进水口1直接水源是水源车但是没有水了
|
||
|
|
||
|
ws1.TotalFlowChange(gameobjinfo.gameObjID, 0);
|
||
|
if (remainwater2 > 0 || remainwater2 == -100)
|
||
|
{//供水线路2有水,全摊到2上
|
||
|
|
||
|
ws2.TotalFlowChange(gameobjinfo.gameObjID, flow);
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{//线路2也没水了
|
||
|
ws2.TotalFlowChange(gameobjinfo.gameObjID, 0);
|
||
|
}
|
||
|
}
|
||
|
else if (!dir1.GetComponent<TruckMessage>())
|
||
|
{//线路1直接水源时消防设施
|
||
|
if (remainwater2 > 0 || remainwater2 == -100)
|
||
|
{//水源2有水,两条线路平摊
|
||
|
ws1.TotalFlowChange(gameobjinfo.gameObjID, flow / 2);
|
||
|
|
||
|
ws2.TotalFlowChange(gameobjinfo.gameObjID, flow / 2);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (WaterSourceLine1.Count > 0 && WaterSourceLine2.Count <= 0)
|
||
|
{//只有一个水源给本车供水,且连在线路1上
|
||
|
GameObject dir1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]);
|
||
|
|
||
|
if (remainwater1 > 0 || remainwater1 == -100)
|
||
|
{
|
||
|
dir1.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, flow);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log(name + " 没水了");
|
||
|
}
|
||
|
}
|
||
|
if (WaterSourceLine1.Count <= 0 && WaterSourceLine2.Count > 0)
|
||
|
{//只有一个水源给本车供水,且连在线路2上
|
||
|
// Debug.Log("没用出水口1,直接用的2?");可能先连上又把1删掉了。。。
|
||
|
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]);
|
||
|
if (remainwater2 > 0 || remainwater2 == -100)
|
||
|
{
|
||
|
dir2.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, flow);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log(name + " 没水了");
|
||
|
}
|
||
|
}
|
||
|
if (WaterSourceLine1.Count <= 0 && WaterSourceLine2.Count <= 0)
|
||
|
{//没有水源给本车供水
|
||
|
|
||
|
}
|
||
|
#endregion
|
||
|
}
|
||
|
|
||
|
//流量改变流量同步
|
||
|
FlowChangeData arg = new FlowChangeData
|
||
|
{
|
||
|
SenderId = CurrentUserInfo.mySelf.Id,
|
||
|
GameObjId = GetComponent<BaseGameObjInfo>().gameObjID,
|
||
|
Flow = value,
|
||
|
};
|
||
|
NetworkManager.Default.SendAsync("FLOW_CHANGE_SYNC", arg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
gameobjinfo = GetComponent<BaseGameObjInfo>();
|
||
|
if (gameobjinfo.gameObjType == CloneObjType.HighSprayingTruck)
|
||
|
{
|
||
|
spraymode = SprayMode.PS30;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
spraymode = SprayMode.PS20;
|
||
|
}
|
||
|
Hose = TransformHelper.FindChild(transform, "Hose");
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{
|
||
|
ConnectWater = GetComponent<WaterSource>().water;
|
||
|
ConnectFoam = GetComponent<WaterSource>().foam;
|
||
|
ConnentWaterSource = gameObject;
|
||
|
}
|
||
|
//if (WaterStraightPrefabs == null)
|
||
|
//{
|
||
|
// WaterStraightPrefabs = Resources.Load<GameObject>("Particle/WaterStraight");
|
||
|
//}
|
||
|
//if (FrothPrefabs == null)
|
||
|
//{
|
||
|
// FrothPrefabs = Resources.Load<GameObject>("Particle/Froth");
|
||
|
//}
|
||
|
MessageDispatcher.AddListener("SPRAY_WATER", Changeflow);
|
||
|
MessageDispatcher.AddListener("RUN_OUR_OF_WATER", CloseSpray);
|
||
|
|
||
|
GetRealtimeConsume.getAllRealtimeConsume += addMyRealtimeConsume; //统计实时流量
|
||
|
}
|
||
|
|
||
|
void Update()
|
||
|
{
|
||
|
if (GetComponent<TruckMessage>().NowSkill == TruckSkills.喷水 ||
|
||
|
GetComponent<TruckMessage>().NowSkill == TruckSkills.喷泡沫)
|
||
|
{
|
||
|
if (Flow > 0)
|
||
|
{
|
||
|
timer -= Time.deltaTime;
|
||
|
if (timer <= 0)
|
||
|
{
|
||
|
KeyValuePair<int, float> remain = GetWaterAndTimeRemain(WaterSourceLine1, WaterSourceLine2);
|
||
|
RemainTime = remain.Key;
|
||
|
RemainWater = remain.Value;
|
||
|
if (RemainWater != -100)
|
||
|
{
|
||
|
if (RemainTime <= 0 || RemainWater <= 0)
|
||
|
{//没水了
|
||
|
stopspraywaterorform();
|
||
|
}
|
||
|
}
|
||
|
#region 泡沫消耗
|
||
|
if (GetComponent<TruckMessage>().NowSkill == TruckSkills.喷泡沫)
|
||
|
{
|
||
|
if (GetComponent<WaterSource>() && GetComponent<WaterSource>().foam)
|
||
|
{//泡沫车
|
||
|
WaterSource ws = GetComponent<WaterSource>();
|
||
|
if (ws.TotalFoam > ws.AllUserFoam)
|
||
|
{
|
||
|
GetComponent<WaterSource>().UserFoam((Flow / 0.97f) * 0.03f);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// LoadPromptWin.Instance.LoadTextPromptWindow("泡沫量不足",1f);
|
||
|
stopspraywaterorform();
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//非水源车
|
||
|
float remianfoam = CheckFoamRemain();
|
||
|
if (remianfoam == -100 || remianfoam > 0)
|
||
|
{//有泡沫
|
||
|
if (WaterSourceLine1.Count > 0)
|
||
|
{
|
||
|
GameObject dir1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]);
|
||
|
WaterSource ws1 = dir1.GetComponent<WaterSource>();
|
||
|
if (ws1.foam)
|
||
|
{
|
||
|
if (ws1.TotalFoam == -100 || ws1.TotalFoam - ws1.AllUserFoam > 0)
|
||
|
{//水源1有泡沫
|
||
|
if (WaterSourceLine2.Count > 0)
|
||
|
{//线路2有链接
|
||
|
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]);
|
||
|
WaterSource ws2 = dir2.GetComponent<WaterSource>();
|
||
|
if (ws2.foam && (ws2.TotalFoam == -100 || ws2.TotalFoam - ws2.AllUserFoam > 0))
|
||
|
{//水源2有泡沫,两水源平分
|
||
|
ws1.UserFoam((Flow / 0.97f) * 0.03f / 2);
|
||
|
ws2.UserFoam((Flow / 0.97f) * 0.03f / 2);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ws1.UserFoam((Flow / 0.97f) * 0.03f);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ws1.UserFoam((Flow / 0.97f) * 0.03f);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{//线路1没泡沫
|
||
|
if (WaterSourceLine2.Count > 0)
|
||
|
{//线路2有链接
|
||
|
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]);
|
||
|
WaterSource ws2 = dir2.GetComponent<WaterSource>();
|
||
|
if (ws2.foam && (ws2.TotalFoam == -100 || ws2.TotalFoam - ws2.AllUserFoam > 0))
|
||
|
{//水源2有泡沫
|
||
|
ws2.UserFoam((Flow / 0.97f) * 0.03f);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log("没泡沫");
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log("没泡沫");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (WaterSourceLine2.Count > 0)
|
||
|
{
|
||
|
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]);
|
||
|
WaterSource ws2 = dir2.GetComponent<WaterSource>();
|
||
|
if (ws2.foam && (ws2.TotalFoam == -100 || ws2.TotalFoam - ws2.AllUserFoam > 0))
|
||
|
{//水源2有泡沫
|
||
|
ws2.UserFoam((Flow / 0.97f) * 0.03f);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log("没泡沫");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//没泡沫
|
||
|
//LoadPromptWin.Instance.LoadTextPromptWindow("泡沫量不足", 1f);
|
||
|
stopspraywaterorform();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
timer = 1f;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
public void OnEnable()
|
||
|
{
|
||
|
//Todo 监听连接水源(有消耗)的水量
|
||
|
// MessageDispatcher.AddListener("WATERHOSECONNECT", AddWaterHose);
|
||
|
// MessageDispatcher.AddListener("DelectWaterHose", DestoryWaterHose);
|
||
|
MessageDispatcher.AddListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectControl);
|
||
|
|
||
|
MessageDispatcher.AddListener("WATERCAR_BIND_CURTAINHOSE", AddWaterCurtainHose);
|
||
|
MessageDispatcher.AddListener("WATERCAR_DESTORY_CURTAINHOSE", DestoryWaterCurtainHose);
|
||
|
MessageDispatcher.AddListener("StartConnectDone", EndConnectDo);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public void OnDestroy()
|
||
|
{
|
||
|
//MessageDispatcher.RemoveListener("WATERHOSECONNECT", AddWaterHose);
|
||
|
// MessageDispatcher.RemoveListener("DelectWaterHose", DestoryWaterHose);
|
||
|
|
||
|
MessageDispatcher.RemoveListener("SPRAY_WATER", Changeflow);
|
||
|
MessageDispatcher.RemoveListener("RUN_OUR_OF_WATER", CloseSpray);
|
||
|
|
||
|
MessageDispatcher.RemoveListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectControl);
|
||
|
|
||
|
MessageDispatcher.RemoveListener("WATERCAR_BIND_CURTAINHOSE", AddWaterCurtainHose);
|
||
|
MessageDispatcher.RemoveListener("WATERCAR_DESTORY_CURTAINHOSE", DestoryWaterCurtainHose);
|
||
|
MessageDispatcher.RemoveListener("StartConnectDone", EndConnectDo);
|
||
|
|
||
|
//销毁所有所连接的管线
|
||
|
for (int i = 0; i < allConnectWaterHose.Count; i++)
|
||
|
{
|
||
|
if (allConnectWaterHose[i] != null)
|
||
|
{
|
||
|
EntitiesManager.Instance.DeleteObj(allConnectWaterHose[i]);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
GetRealtimeConsume.getAllRealtimeConsume -= addMyRealtimeConsume;
|
||
|
}
|
||
|
|
||
|
private FloatData addMyRealtimeConsume(FloatData data)
|
||
|
{
|
||
|
data.value += Flow;
|
||
|
return data;
|
||
|
}
|
||
|
|
||
|
public void OnDisable()
|
||
|
{
|
||
|
//MessageDispatcher.RemoveListener("WATERHOSECONNECT", AddWaterHose);
|
||
|
//MessageDispatcher.RemoveListener("DelectWaterHose", DestoryWaterHose);
|
||
|
|
||
|
MessageDispatcher.RemoveListener("SPRAY_WATER", Changeflow);
|
||
|
MessageDispatcher.RemoveListener("RUN_OUR_OF_WATER", CloseSpray);
|
||
|
|
||
|
MessageDispatcher.RemoveListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectControl);
|
||
|
|
||
|
MessageDispatcher.RemoveListener("WATERCAR_BIND_CURTAINHOSE", AddWaterCurtainHose);
|
||
|
MessageDispatcher.RemoveListener("WATERCAR_DESTORY_CURTAINHOSE", DestoryWaterCurtainHose);
|
||
|
MessageDispatcher.RemoveListener("StartConnectDone", EndConnectDo);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 连接管线处理完起点之后再处理终点,防止连接终点比起点先接受连接管线信息导致DirectConnectObj没有赋值信息,然后不能正确对其设置水源信息,仅处理连接
|
||
|
/// </summary>
|
||
|
/// <param name="obj"></param>
|
||
|
private void EndConnectDo(IMessage obj)
|
||
|
{
|
||
|
WaterHoseEndDo data = (WaterHoseEndDo)obj.Data;
|
||
|
if (gameobjinfo.gameObjID == data.EndId)
|
||
|
{
|
||
|
GameObject ws = EntitiesManager.Instance.GetEntityByID(data.StartId);
|
||
|
//GameObject hose = EntitiesManager.Instance.GetEntityByID(data.HoseId);
|
||
|
// GameObject anther = hose.GetComponent<ParentLinesMessage>().GetAnotherGameObj(gameobjinfo.gameObjID);
|
||
|
if (data.ConnectInPoint == 1)
|
||
|
{//进水口1未使用,连接进水口1
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>())
|
||
|
// {//如果连接起点为水源车,因为起点必定是水源就没加watersource的判断
|
||
|
ChangeWaterSourceLineInfo(data.StartId, 1);
|
||
|
inWaterHose1 = data.ConnectHose;
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{//如果自己是水源车
|
||
|
if (GetComponent<WaterSource>().HasWaterSelfAndLine == false)
|
||
|
{//自己以及线上没水了
|
||
|
float remain = checkWaterRemain(WaterSourceLine1);
|
||
|
if (remain > 0 || remain == -100)
|
||
|
{//新水源有水
|
||
|
GetComponent<WaterSource>().HasWaterSelfAndLine = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
//如果起点为消防设施,分流处理,(起点为水源车辆已经在水源车辆连接起点处理)
|
||
|
if (!ws.GetComponent<TruckMessage>())
|
||
|
{//连接水源为非车辆
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{//如果自身是水源车
|
||
|
if (GetComponent<WaterSource>().TotalFlow > 0)
|
||
|
{//本身所在网络在出水 注:自己在出水网络但是自己作为最终供水端已经没有水可用即TotalFlow为0,会在HasWaterSelfAndLine中处理
|
||
|
if (WaterSourceLine2.Count > 0)
|
||
|
{//线路2有链接
|
||
|
GameObject ws2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]);
|
||
|
float remain2 = checkWaterRemain(WaterSourceLine2);
|
||
|
if (remain2 == -100 || remain2 > 0)
|
||
|
{//线路2 有水
|
||
|
ws.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
ws2.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ws.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//自身为非水源车
|
||
|
if (Flow > 0)
|
||
|
{//本身在出水
|
||
|
if (WaterSourceLine2.Count > 0)
|
||
|
{//线路2有链接,自身为非水源又在出水,线路2肯定有连接且有水。。。
|
||
|
GameObject ws2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]);
|
||
|
float remain2 = checkWaterRemain(WaterSourceLine2);
|
||
|
if (remain2 == -100 || remain2 > 0)
|
||
|
{//线路2 有水
|
||
|
ws.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
ws2.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ws.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else if (data.ConnectInPoint == 2)
|
||
|
{
|
||
|
if (WaterSourceLine2.Count <= 0)
|
||
|
{//进水口2未使用,连接进水口2
|
||
|
//if (anther.GetComponent<TruckBindWaterSource>())
|
||
|
//{//如果连接起点为水源车,因为起点必定是水源就没加watersource的判断
|
||
|
inWaterHose2 = data.ConnectHose;
|
||
|
ChangeWaterSourceLineInfo(data.StartId, 2);
|
||
|
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{//如果自己是水源车
|
||
|
if (GetComponent<WaterSource>().HasWaterSelfAndLine == false)
|
||
|
{//自己以及线上没水了
|
||
|
float remain = checkWaterRemain(WaterSourceLine2);
|
||
|
if (remain > 0 || remain == -100)
|
||
|
{//新水源有水
|
||
|
GetComponent<WaterSource>().HasWaterSelfAndLine = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//}
|
||
|
|
||
|
if (!ws.GetComponent<TruckMessage>())
|
||
|
{//连接水源为非车辆
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{//如果自身是水源车
|
||
|
if (GetComponent<WaterSource>().TotalFlow > 0)
|
||
|
{//本身所在网络在出水 注:自己在出水网络但是自己作为最终供水端已经没有水可用即TotalFlow为0,会在HasWaterSelfAndLine中处理
|
||
|
if (WaterSourceLine1.Count > 0)
|
||
|
{//线路1有链接
|
||
|
GameObject ws1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]);
|
||
|
float remain1 = checkWaterRemain(WaterSourceLine1);
|
||
|
if (remain1 == -100 || remain1 > 0)
|
||
|
{//线路2 有水
|
||
|
ws.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
ws1.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ws.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//自身为非水源车
|
||
|
if (Flow > 0)
|
||
|
{//本身在出水
|
||
|
if (WaterSourceLine1.Count > 0)
|
||
|
{//线路2有链接,自身为非水源又在出水,线路1肯定有连接且有水。。。
|
||
|
GameObject ws1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]);
|
||
|
float remain1 = checkWaterRemain(WaterSourceLine1);
|
||
|
if (remain1 == -100 || remain1 > 0)
|
||
|
{//线路2 有水
|
||
|
ws.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
ws1.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ws.GetComponent<WaterSource>().TotalFlowChange(gameobjinfo.gameObjID, GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log(name + "没有更多进水口,检查连接逻辑");
|
||
|
}
|
||
|
}
|
||
|
if (!GetComponent<WaterSource>())
|
||
|
{//非水源车辆直接水源赋值及UI显示
|
||
|
// ConnentWaterSource = anther;
|
||
|
ConnectWater = true;
|
||
|
if (!ConnectFoam)
|
||
|
{
|
||
|
ConnectFoam = EntitiesManager.Instance.GetEntityByID(data.StartId).GetComponent<WaterSource>().foam;
|
||
|
}
|
||
|
RefreshUI(ConnectWater, ConnectFoam);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
//同步的管线连接到该车辆或者连接在该车辆的管线同步删除时,移动控制
|
||
|
private void ConnectOrDelectControl(IMessage obj)
|
||
|
{
|
||
|
HoseConnectOrDelectData data = (HoseConnectOrDelectData)obj.Data;
|
||
|
if (data.StartId == gameobjinfo.gameObjID ||
|
||
|
data.EndId == gameobjinfo.gameObjID)
|
||
|
{
|
||
|
GameObject hose = EntitiesManager.Instance.GetEntityByID(data.HoseId);
|
||
|
//移动处理
|
||
|
if (data.Isconnect)
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = false;
|
||
|
if (!allConnectWaterHose.Contains(hose))
|
||
|
{
|
||
|
allConnectWaterHose.Add(hose);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
|
||
|
if (allConnectWaterHose.Contains(hose))
|
||
|
{
|
||
|
allConnectWaterHose.Remove(hose);
|
||
|
}
|
||
|
if (allConnectWaterHose.Count <= 0 && allConnectWaterCurtainHose.Count <= 0)
|
||
|
{
|
||
|
if (!GetComponent<TruckMessage>().IsFixedSupport)
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = true;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//水源信息处理
|
||
|
GameObject anther = hose.GetComponent<ParentLinesMessage>().GetAnotherGameObj(gameobjinfo.gameObjID);
|
||
|
//管线连接
|
||
|
if (data.Isconnect)
|
||
|
{
|
||
|
if (gameobjinfo.gameObjID == data.StartId)
|
||
|
{//为连接起点,起点必定是水源
|
||
|
//if (DirectConnectObj1.Key != null && DirectConnectObj2.Key != null && (hose != outtWaterHose1 || hose != outWaterHose2))
|
||
|
//{
|
||
|
// Debug.Log(name + " 两个出水口都被占用,检查连接逻辑,没限制住");
|
||
|
//}
|
||
|
if (DirectConnectObj1.Key == null)
|
||
|
{//出水口1空闲
|
||
|
outtWaterHose1 = hose;
|
||
|
DirectConnectObj1 = Directionconnect(anther, data.EndId, data.StartId, DirectConnectObj1, hose);
|
||
|
Debug.Log(name + "连接进水口1,连接的" + anther.name);
|
||
|
|
||
|
#region
|
||
|
//if (anther.GetComponent<TruckBindWaterSource>())
|
||
|
//{//另一端为可出水车辆
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count <= 0)
|
||
|
// {//另一端进水口1没有被占用,连接进水口1
|
||
|
// DirectConnectObj1 = new KeyValuePair<GameObject, int>(anther, 1);
|
||
|
|
||
|
// //连接了一个出水的网络
|
||
|
// if (anther.GetComponent<WaterSource>())
|
||
|
// {//有watersource必为水源车,因为消防设施不能为连接终点
|
||
|
// if (anther.GetComponent<WaterSource>().TotalFlow > 0)
|
||
|
// {//连接的网络正在出水,修改流量信息
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count > 0)
|
||
|
// {//另一条进水口有水源,另一端连接的肯定为进水口2
|
||
|
// float remain = anther.GetComponent<TruckBindWaterSource>().checkWaterRemain(
|
||
|
// anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2);
|
||
|
// if (remain > 0 || remain == -100)
|
||
|
// {//另一端水源有水
|
||
|
// GetComponent<WaterSource>().TotalFlowChange(data.EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
// GameObject antherdir2 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2[0][0]);
|
||
|
// antherdir2.GetComponent<WaterSource>().TotalFlowChange(data.EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
// }
|
||
|
// else
|
||
|
// {//另一端水源没水了但是在出水可能是消耗自己的水
|
||
|
// //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑
|
||
|
// GetComponent<WaterSource>().TotalFlowChange(data.EndId, anther.GetComponent<WaterSource>().TotalFlow);
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// else if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count <= 0)
|
||
|
// {
|
||
|
// //另一端进水口2没有被占用,连接进水口2
|
||
|
// DirectConnectObj1 = new KeyValuePair<GameObject, int>(anther, 2);
|
||
|
|
||
|
// //连接了一个出水的网络
|
||
|
// if (anther.GetComponent<WaterSource>())
|
||
|
// {//有watersource必为水源车,因为消防设施不能为连接终点
|
||
|
// if (anther.GetComponent<WaterSource>().TotalFlow > 0)
|
||
|
// {//连接的网络正在出水,修改流量信息
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count > 0)
|
||
|
// {//另一条进水口有水源,另一端连接的肯定为进水口1
|
||
|
// float remain = anther.GetComponent<TruckBindWaterSource>().checkWaterRemain(
|
||
|
// anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1);
|
||
|
// if (remain > 0 || remain == -100)
|
||
|
// {//另一端水源有水
|
||
|
// GetComponent<WaterSource>().TotalFlowChange(data.EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
// GameObject antherdir1 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1[0][0]);
|
||
|
// antherdir1.GetComponent<WaterSource>().TotalFlowChange(data.EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
// }
|
||
|
// else
|
||
|
// {//另一端水源没水了但是在出水可能是消耗自己的水
|
||
|
// //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑
|
||
|
// GetComponent<WaterSource>().TotalFlowChange(data.EndId, anther.GetComponent<WaterSource>().TotalFlow);
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// Debug.Log(anther.name + " 没有更多进水口,检查连接逻辑");
|
||
|
// }
|
||
|
//}
|
||
|
//else
|
||
|
//{//另一端为非车辆,则只有一个进水口,并且如果另一端不是车辆则一定没有在出水,因为只有一个进水口
|
||
|
// DirectConnectObj1 = new KeyValuePair<GameObject, int>(anther, 0);
|
||
|
//}
|
||
|
#endregion
|
||
|
}
|
||
|
else
|
||
|
{//出水口1被占用
|
||
|
if (hose == outtWaterHose1)
|
||
|
{//还是同一条水带的连接
|
||
|
DirectConnectObj1 = Directionconnect(anther, data.EndId, data.StartId, DirectConnectObj1, hose);
|
||
|
Debug.Log(name + "连接进水口1,连接的" + anther.name);
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (DirectConnectObj2.Key == null)
|
||
|
{//出水口2空闲
|
||
|
outWaterHose2 = hose;
|
||
|
DirectConnectObj2 = Directionconnect(anther, data.EndId, data.StartId, DirectConnectObj2, hose);
|
||
|
Debug.Log(name + "连接进水口2,连接的" + anther.name);
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (hose == outWaterHose2)
|
||
|
{
|
||
|
DirectConnectObj2 = Directionconnect(anther, data.EndId, data.StartId, DirectConnectObj2, hose);
|
||
|
Debug.Log(name + "连接进水口2,连接的" + anther.name);
|
||
|
//WaterHoseEndDo arg = new WaterHoseEndDo
|
||
|
//{
|
||
|
// ConnectHose = hose,
|
||
|
// StartId = gameobjinfo.gameObjID,
|
||
|
// ConnectInPoint = 2,
|
||
|
// EndId = data.EndId,
|
||
|
//};
|
||
|
//MessageDispatcher.SendMessage("StartConnectDone", arg);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log(name + "没有更多进水口");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
#region
|
||
|
//else
|
||
|
//{//该车辆为连接终点
|
||
|
// if (WaterSourceLine1.Count <= 0)
|
||
|
// {//进水口1未使用,连接进水口1
|
||
|
// // if (anther.GetComponent<TruckBindWaterSource>())
|
||
|
// // {//如果连接起点为水源车,因为起点必定是水源就没加watersource的判断
|
||
|
// ChangeWaterSourceLineInfo(anther.GetComponent<BaseGameObjInfo>().gameObjID, 1);
|
||
|
// inWaterHose1 = hose;
|
||
|
// if (GetComponent<WaterSource>())
|
||
|
// {//如果自己是水源车
|
||
|
// if (GetComponent<WaterSource>().HasWaterSelfAndLine == false)
|
||
|
// {//自己以及线上没水了
|
||
|
// float remain = checkWaterRemain(WaterSourceLine1);
|
||
|
// if (remain > 0 || remain == -100)
|
||
|
// {//新水源有水
|
||
|
// GetComponent<WaterSource>().HasWaterSelfAndLine = true;
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {//连接起点为设施
|
||
|
|
||
|
// // }
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// if (WaterSourceLine2.Count <= 0)
|
||
|
// {//进水口2未使用,连接进水口2
|
||
|
// //if (anther.GetComponent<TruckBindWaterSource>())
|
||
|
// //{//如果连接起点为水源车,因为起点必定是水源就没加watersource的判断
|
||
|
// inWaterHose2 = hose;
|
||
|
// ChangeWaterSourceLineInfo(anther.GetComponent<BaseGameObjInfo>().gameObjID, 2);
|
||
|
|
||
|
// if (GetComponent<WaterSource>())
|
||
|
// {//如果自己是水源车
|
||
|
// if (GetComponent<WaterSource>().HasWaterSelfAndLine == false)
|
||
|
// {//自己以及线上没水了
|
||
|
// float remain = checkWaterRemain(WaterSourceLine2);
|
||
|
// if (remain > 0 || remain == -100)
|
||
|
// {//新水源有水
|
||
|
// GetComponent<WaterSource>().HasWaterSelfAndLine = true;
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
// //}
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// Debug.Log(name + "没有更多进水口,检查连接逻辑");
|
||
|
// }
|
||
|
// }
|
||
|
// if (!GetComponent<WaterSource>())
|
||
|
// {//非水源车辆直接水源赋值及UI显示
|
||
|
// // ConnentWaterSource = anther;
|
||
|
// ConnectWater = true;
|
||
|
// if (!ConnectFoam)
|
||
|
// {
|
||
|
// ConnectFoam = anther.GetComponent<WaterSource>().foam;
|
||
|
// }
|
||
|
// RefreshUI(ConnectWater, ConnectFoam);
|
||
|
// }
|
||
|
//}
|
||
|
#endregion
|
||
|
#region 原来代码
|
||
|
// if (!GetComponent<WaterSource>())
|
||
|
// {
|
||
|
// if (anther.GetComponent<WaterSource>())
|
||
|
// {//如果另一端是水源
|
||
|
|
||
|
// //Todo:连接多个水源
|
||
|
// //假设已经连接了水源,又连接了水源,水源及消耗按老的
|
||
|
// if (ConnentWaterSource != null)
|
||
|
// {//Todo:多水源处理
|
||
|
// //LoadPromptWin.Instance.LoadTextPromptWindow("暂未处理多水源信息",1f);
|
||
|
// Debug.Log("暂未处理多水源信息");
|
||
|
// return;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// ConnectWater = anther.GetComponent<WaterSource>().water;
|
||
|
// ConnectFoam = anther.GetComponent<WaterSource>().foam;
|
||
|
// ConnentWaterSource = anther;
|
||
|
// //如果练了一个没水的水源
|
||
|
// if (anther.GetComponent<WaterSource>().hasover)
|
||
|
// {
|
||
|
// waterrunoutof = true;
|
||
|
// }
|
||
|
// //如果别人连接时 本客户端刚好选中当前车辆
|
||
|
// if (TruckSkillPanelController.GetInstance)
|
||
|
// {//UI控制
|
||
|
// if (TruckSkillPanelController.GetInstance.NowBindTruck == GetComponent<TruckMessage>())
|
||
|
// {
|
||
|
// TruckSkillPanelController.GetInstance.SprayFoam.GetComponent<Toggle>().interactable = ConnectFoam;
|
||
|
// TruckSkillPanelController.GetInstance.SprayWater.GetComponent<Toggle>().interactable = ConnectWater;
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
|
||
|
// if (anther.GetComponent<FireManWaterHoseManager>())
|
||
|
// {
|
||
|
// //Todo:
|
||
|
// //如果连接的是消防员,还要同步消防员的水源信息(因为这条管线本身就是别的客户端连的,所以要把水源信息返回去)
|
||
|
// //LoadPromptWin.Instance.LoadTextPromptWindow("暂未处理消防员连接非本客户端非水源车的处理", 1f);
|
||
|
// Debug.Log("暂未处理消防员连接非本客户端非水源车的处理");
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// ConnectWater = GetComponent<WaterSource>().water;
|
||
|
// ConnectFoam = GetComponent<WaterSource>().foam;
|
||
|
// ConnentWaterSource = gameObject;
|
||
|
// }
|
||
|
//}
|
||
|
////管线删除
|
||
|
//else
|
||
|
//{
|
||
|
// //TODO:
|
||
|
// //因为现在消耗是按旧水源处理,所以如果删除的是非旧水源的管线,暂不处理
|
||
|
// if (anther.GetComponent<WaterSource>())
|
||
|
// {//另一端是水源
|
||
|
// if (GetComponent<WaterSource>())
|
||
|
// {
|
||
|
// return;
|
||
|
// }
|
||
|
// if (ConnentWaterSource != null)
|
||
|
// {
|
||
|
// if (anther.GetComponent<BaseGameObjInfo>().gameObjID != ConnentWaterSource.GetComponent<BaseGameObjInfo>().gameObjID)
|
||
|
// {
|
||
|
// //
|
||
|
// LoadPromptWin.Instance.LoadTextPromptWindow("暂未处理多水源的管线删除处理", 1f);
|
||
|
// Debug.Log("暂未处理多水源的管线删除处理");
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// Resert();
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {//另一端不是水源
|
||
|
// if (anther.GetComponent<FireManWaterHoseManager>())
|
||
|
// {
|
||
|
// anther.GetComponent<FireManWaterHoseManager>().Resert();
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
//}
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
//删除管线
|
||
|
else
|
||
|
{
|
||
|
if (gameobjinfo.gameObjID == data.StartId)
|
||
|
{//如果本车为该删除管线的起点,只把出水口信息清空,接水口水源信息由接水口接收的地方处理
|
||
|
|
||
|
if (hose == outtWaterHose1)
|
||
|
{//删除的是出水口1的管线
|
||
|
DirectConnectObj1 = new KeyValuePair<GameObject, int>();
|
||
|
outtWaterHose1 = null;
|
||
|
}
|
||
|
else if (hose == outWaterHose2)
|
||
|
{
|
||
|
DirectConnectObj2 = new KeyValuePair<GameObject, int>();
|
||
|
outWaterHose2 = null;
|
||
|
}
|
||
|
//if (DirectConnectObj1.Key != null && DirectConnectObj1.Key.GetComponent<BaseGameObjInfo>().gameObjID == data.EndId)
|
||
|
//{//出水口1不为空且出水口1就是管线终点所连接物体
|
||
|
// DirectConnectObj1 = new KeyValuePair<GameObject, int>();
|
||
|
// outtWaterHose1 = null;
|
||
|
//}
|
||
|
//if (DirectConnectObj2.Key != null && DirectConnectObj2.Key.GetComponent<BaseGameObjInfo>().gameObjID == data.EndId)
|
||
|
//{//出水口2不为空且出水口2就是管线终点所连接物体
|
||
|
// DirectConnectObj2 = new KeyValuePair<GameObject, int>();
|
||
|
// outWaterHose2 = null;
|
||
|
//}
|
||
|
}
|
||
|
else
|
||
|
{//如果为终点
|
||
|
|
||
|
if (inWaterHose1 == hose)
|
||
|
{//进水口1有链接并且直接水源为删除管线的起点
|
||
|
WaterSourceLine1 = new List<List<long>>();
|
||
|
|
||
|
inWaterHose1 = null;
|
||
|
//WaterSourceLine1.Clear();
|
||
|
}
|
||
|
else if (inWaterHose2 == hose)
|
||
|
{//进水口2有链接并且直接水源为删除管线的起点
|
||
|
WaterSourceLine2 = new List<List<long>>();
|
||
|
inWaterHose2 = null;
|
||
|
// WaterSourceLine2.Clear();
|
||
|
}
|
||
|
}
|
||
|
if (!GetComponent<WaterSource>())
|
||
|
{//非水源车辆直接水源赋值及UI显示
|
||
|
// ConnentWaterSource = anther;
|
||
|
CheckWaterHose();
|
||
|
//RefreshUI(ConnectWater, ConnectFoam);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void Changeflow(IMessage obj)
|
||
|
{
|
||
|
var info = (flowchangeinfo)obj.Data;
|
||
|
if (info.ChangObjId == gameobjinfo.gameObjID)
|
||
|
{
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{
|
||
|
GetComponent<WaterSource>().SetTotalFlow(new KeyValuePair<GameObject, float>(gameObject, Flow), info.IsAdd);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (ConnentWaterSource != null)
|
||
|
{
|
||
|
ConnentWaterSource.GetComponent<WaterSource>().SetTotalFlow(new KeyValuePair<GameObject, float>(gameObject, Flow), info.IsAdd);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
private void CloseSpray(IMessage obj)
|
||
|
{
|
||
|
if (GetComponent<TruckMessage>().NowSkill == TruckSkills.喷水 || GetComponent<TruckMessage>().NowSkill == TruckSkills.喷泡沫)
|
||
|
{
|
||
|
long watersourceId = (long)obj.Data;
|
||
|
long thiswaterid = -1;
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{
|
||
|
thiswaterid = GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (ConnentWaterSource != null)
|
||
|
{
|
||
|
thiswaterid = ConnentWaterSource.GetComponent<WaterSource>().GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
if (watersourceId == thiswaterid)
|
||
|
{
|
||
|
waterrunoutof = true;
|
||
|
GetComponent<TruckMessage>().NowSkill = TruckSkills.待命;
|
||
|
Flow = 0;
|
||
|
if (TruckSkillPanelController.GetInstance)
|
||
|
{
|
||
|
if (TruckSkillPanelController.GetInstance.NowBindTruck == GetComponent<TruckMessage>())
|
||
|
{
|
||
|
TruckSkillPanelController.GetInstance.SprayFoam.GetComponent<Toggle>().isOn = false;
|
||
|
TruckSkillPanelController.GetInstance.SprayWater.GetComponent<Toggle>().isOn = false;
|
||
|
}
|
||
|
}
|
||
|
for (int i = 0; i < Hose.childCount; i++)
|
||
|
{
|
||
|
//Destroy(Hose.GetChild(i).gameObject);
|
||
|
Hose.GetChild(i).gameObject.SetActive(false);
|
||
|
}
|
||
|
SpraySyncData spraysync = new SpraySyncData();
|
||
|
spraysync.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
spraysync.IsOn = false;
|
||
|
spraysync.gameObjID = gameobjinfo.gameObjID;
|
||
|
NetworkManager.Default.SendAsync(/*CurrentUserInfo.mySelf.Id,*/ "SPRAY_WATER_SYNC", spraysync);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// Todo:连接多个水源问题,牵扯水量消耗
|
||
|
/// 有管线连接到车上,现在连接多个水源按老的
|
||
|
/// </summary>
|
||
|
/// <param name="obj"></param>
|
||
|
private void AddWaterHose(IMessage obj)
|
||
|
{
|
||
|
|
||
|
var data = ((HoseConnectOrDelectData)obj.Data);
|
||
|
var waterhose = EntitiesManager.Instance.GetEntityByID(data.HoseId);// data.SelectHoseWater;
|
||
|
GameObject anthersider = waterhose.GetComponent<ParentLinesMessage>().GetAnotherGameObj(gameObject);
|
||
|
//如果该物体是管线的起点
|
||
|
if (GetComponent<BaseGameObjInfo>().gameObjID == data.StartId)
|
||
|
{
|
||
|
if (!allConnectWaterHose.Contains(waterhose))
|
||
|
{
|
||
|
allConnectWaterHose.Add(waterhose);
|
||
|
}
|
||
|
//禁用寻路
|
||
|
if (allConnectWaterHose.Count > 0)
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = false;
|
||
|
}
|
||
|
|
||
|
//水源车出水口使用状况,用以判断能否再其他连接管线
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{
|
||
|
if (DirectConnectObj1.Key == null)
|
||
|
{//如果进水口1空闲
|
||
|
if (anthersider.GetComponent<TruckBindWaterSource>())
|
||
|
{//另一端为车辆
|
||
|
if (anthersider.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count <= 0)
|
||
|
{//另一端进水口1没有被占用,连接进水口1
|
||
|
DirectConnectObj1 = new KeyValuePair<GameObject, int>(anthersider, 1);
|
||
|
}
|
||
|
else if (anthersider.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count <= 0)
|
||
|
{
|
||
|
//另一端进水口2没有被占用,连接进水口1
|
||
|
DirectConnectObj1 = new KeyValuePair<GameObject, int>(anthersider, 2);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log(anthersider.name + "没有更多进水口,检查连接逻辑");
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//另一端为非车辆
|
||
|
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//进水口1被占用
|
||
|
if (DirectConnectObj2.Key == null)
|
||
|
{//进水口二未被占用
|
||
|
//DirectConnectObj2 = anthersider;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
if (!GetComponent<WaterSource>())
|
||
|
{
|
||
|
var endObj = EntitiesManager.Instance.GetEntityByID(data.EndId);
|
||
|
if (ConnentWaterSource != null)
|
||
|
{
|
||
|
//ToDo连接多个水源问题
|
||
|
return;
|
||
|
}
|
||
|
if (endObj.GetComponent<WaterSource>())
|
||
|
{
|
||
|
if (endObj.GetComponent<WaterSource>().water)
|
||
|
{
|
||
|
ConnectWater = true;
|
||
|
}
|
||
|
if (endObj.GetComponent<WaterSource>().foam)
|
||
|
{
|
||
|
ConnectFoam = true;
|
||
|
}
|
||
|
ConnentWaterSource = endObj;
|
||
|
RefreshUI(ConnectWater, ConnectFoam);
|
||
|
}
|
||
|
}
|
||
|
//如果该车是非水源车辆并连接了消防员,重设消防员的水源信息
|
||
|
//if (!GetComponent<WaterSource>())
|
||
|
//{
|
||
|
// for (int i = 0; i < allConnectWaterHose.Count; i++)
|
||
|
// {
|
||
|
// GameObject otherside = allConnectWaterHose[i].GetComponent<ParentLinesMessage>().GetAnotherGameObj(gameObject);
|
||
|
// RefushFiremanWaterInfo(otherside);
|
||
|
// }
|
||
|
//}
|
||
|
|
||
|
|
||
|
//TruckWaterMessageSyncData arg = new TruckWaterMessageSyncData();
|
||
|
//arg.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
//arg.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
//arg.ConnectWaterHose = waterhose.GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
//arg.IsConncet = true;
|
||
|
//NetworkManager.Default.SendAsync("TRUCK_WATER_MESSAGE_SYNC", arg);
|
||
|
|
||
|
}
|
||
|
//如果该物体是管线的终点
|
||
|
if (GetComponent<BaseGameObjInfo>().gameObjID == data.EndId)
|
||
|
{
|
||
|
if (!allConnectWaterHose.Contains(waterhose))
|
||
|
{
|
||
|
allConnectWaterHose.Add(waterhose);
|
||
|
}
|
||
|
//禁用寻路
|
||
|
if (allConnectWaterHose.Count > 0)
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = false;
|
||
|
}
|
||
|
|
||
|
//ToDo:
|
||
|
//绑定水源信息
|
||
|
|
||
|
//
|
||
|
//
|
||
|
if (!GetComponent<WaterSource>())
|
||
|
{
|
||
|
var startObj = EntitiesManager.Instance.GetEntityByID(data.StartId);
|
||
|
if (startObj.GetComponent<WaterSource>())
|
||
|
{
|
||
|
if (ConnentWaterSource != null)
|
||
|
{
|
||
|
//ToDo连接多个水源问题
|
||
|
return;
|
||
|
}
|
||
|
if (startObj.GetComponent<WaterSource>().water)
|
||
|
{
|
||
|
ConnectWater = true;
|
||
|
}
|
||
|
if (startObj.GetComponent<WaterSource>().foam)
|
||
|
{
|
||
|
ConnectFoam = true;
|
||
|
}
|
||
|
ConnentWaterSource = startObj;
|
||
|
RefreshUI(ConnectWater, ConnectWater);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
//如果该车是非水源车辆并连接了消防员,重设消防员的水源信息
|
||
|
//if (!GetComponent<WaterSource>())
|
||
|
//{
|
||
|
// for (int i = 0; i < allConnectWaterHose.Count; i++)
|
||
|
// {
|
||
|
// GameObject otherside = allConnectWaterHose[i].GetComponent<ParentLinesMessage>().GetAnotherGameObj(gameObject);
|
||
|
// RefushFiremanWaterInfo(otherside);
|
||
|
// }
|
||
|
//}
|
||
|
|
||
|
|
||
|
//TruckWaterMessageSyncData arg = new TruckWaterMessageSyncData();
|
||
|
//arg.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
//arg.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
//arg.ConnectWaterHose = waterhose.GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
//arg.IsConncet = true;
|
||
|
//NetworkManager.Default.SendAsync("TRUCK_WATER_MESSAGE_SYNC", arg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 绑定连接到水源车上的水幕水带
|
||
|
/// </summary>
|
||
|
/// <param name="obj"></param>
|
||
|
private void AddWaterCurtainHose(IMessage obj)
|
||
|
{
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{//因此脚本水源车及出水车上都绑定了,所以需判断是否是水源车。水源车才需要绑定
|
||
|
|
||
|
var info = (WaterCarBindCurtainHose)obj.Data;
|
||
|
|
||
|
if (info.WaterSourceObjId == GetComponent<BaseGameObjInfo>().gameObjID)
|
||
|
{//判断水幕水带连接的车的是否是此脚本所挂载的对象本身
|
||
|
|
||
|
if (DirectConnectObj1.Key == null)
|
||
|
{
|
||
|
DirectConnectObj1 = new KeyValuePair<GameObject, int>(info.WaterCurtainHose, 0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (DirectConnectObj1.Key == info.WaterCurtainHose)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
if (DirectConnectObj2.Key == null)
|
||
|
{
|
||
|
DirectConnectObj2 = new KeyValuePair<GameObject, int>(info.WaterCurtainHose, 0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (DirectConnectObj2.Key == info.WaterCurtainHose)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log("没有更多出水口,检查连接逻辑");
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
if (info.isConnect && !allConnectWaterCurtainHose.Contains(info.WaterCurtainHose))
|
||
|
{
|
||
|
allConnectWaterCurtainHose.Add(info.WaterCurtainHose);
|
||
|
}
|
||
|
|
||
|
//禁用寻路
|
||
|
if (allConnectWaterCurtainHose.Count > 0)
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 删除连接的管线
|
||
|
/// </summary>
|
||
|
/// <param name="obj"></param>
|
||
|
private void DestoryWaterHose(IMessage obj)
|
||
|
{
|
||
|
var data = ((WaterHoseDelectCmdArgs)obj.Data);
|
||
|
//把管线从本车的管线列表中移除
|
||
|
var waterhose = data.SelectHoseWater;
|
||
|
|
||
|
if (gameobjinfo.gameObjID == data.StartObjId ||
|
||
|
gameobjinfo.gameObjID == data.EndObjId)
|
||
|
{
|
||
|
GameObject antherside = waterhose.GetComponent<ParentLinesMessage>().GetAnotherGameObj(gameObject);
|
||
|
if (gameobjinfo.gameObjID == data.StartObjId && GetComponent<WaterSource>())
|
||
|
{//水源车并且为连接起点,清除其出水口
|
||
|
//if (DirectConnectObj1==antherside)
|
||
|
//{
|
||
|
// DirectConnectObj1 = null;
|
||
|
//}
|
||
|
//if (DirectConnectObj2==antherside)
|
||
|
//{
|
||
|
// DirectConnectObj2 = null;
|
||
|
//}
|
||
|
}
|
||
|
|
||
|
allConnectWaterHose.Remove(waterhose);
|
||
|
//启用寻路
|
||
|
if (allConnectWaterHose.Count < 1)
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = true;
|
||
|
|
||
|
}
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
CheckWaterHose();
|
||
|
if (allConnectWaterHose.Count <= 0)
|
||
|
{
|
||
|
//水源信息同步
|
||
|
TruckWaterMessageSyncData arg = new TruckWaterMessageSyncData();
|
||
|
arg.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
arg.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
arg.ConnectWaterHose = waterhose.GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
arg.IsConncet = false;
|
||
|
NetworkManager.Default.SendAsync("TRUCK_WATER_MESSAGE_SYNC", arg);
|
||
|
}
|
||
|
//因为出水时不能删除管线所以下边没用了
|
||
|
//如果是非水源车,而且在出水,同步出水
|
||
|
if (!GetComponent<WaterSource>())
|
||
|
{
|
||
|
if ((!ConnectWater && GetComponent<TruckMessage>().NowSkill == TruckSkills.喷水) ||
|
||
|
(!ConnectFoam && GetComponent<TruckMessage>().NowSkill == TruckSkills.喷泡沫))
|
||
|
{
|
||
|
for (int i = 0; i < Hose.childCount; i++)
|
||
|
{
|
||
|
Destroy(Hose.GetChild(i).gameObject);
|
||
|
}
|
||
|
SpraySyncData spraysync = new SpraySyncData();
|
||
|
spraysync.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
spraysync.IsOn = false;
|
||
|
spraysync.gameObjID = gameobjinfo.gameObjID;
|
||
|
NetworkManager.Default.SendAsync("SPRAY_WATER_SYNC", spraysync);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
////如果这个车连接了消防员,修改消防员水原信息
|
||
|
//if (!GetComponent<WaterSource>())
|
||
|
//{
|
||
|
// if (allConnectWaterHose.Count > 0)
|
||
|
// {
|
||
|
// for (int i = 0; i < allConnectWaterHose.Count; i++)
|
||
|
// {
|
||
|
// GameObject otherside = allConnectWaterHose[i].GetComponent<ParentLinesMessage>().GetAnotherGameObj(gameObject);
|
||
|
// RefushFiremanWaterInfo(otherside);
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
//}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 删除连接在本车上的水幕水带
|
||
|
/// </summary>
|
||
|
/// <param name="obj"></param>
|
||
|
private void DestoryWaterCurtainHose(IMessage obj)
|
||
|
{
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{//因此脚本水源车及出水车上都绑定了,所以需判断是否是水源车。水源车才需要绑定
|
||
|
|
||
|
var info = (WaterCarBindCurtainHose)obj.Data;
|
||
|
|
||
|
if (info.WaterSourceObjId == GetComponent<BaseGameObjInfo>().gameObjID)
|
||
|
{//判断水幕水带连接的车的是否是此脚本所挂载的对象本身
|
||
|
|
||
|
if (DirectConnectObj1.Key == info.WaterCurtainHose)
|
||
|
{
|
||
|
DirectConnectObj1 = new KeyValuePair<GameObject, int>();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (DirectConnectObj2.Key == info.WaterCurtainHose)
|
||
|
{
|
||
|
DirectConnectObj2 = new KeyValuePair<GameObject, int>();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log("两个出水口都没有连接该水幕水带");
|
||
|
}
|
||
|
}
|
||
|
if (!info.isConnect && allConnectWaterCurtainHose.Contains(info.WaterCurtainHose))
|
||
|
{
|
||
|
allConnectWaterCurtainHose.Remove(info.WaterCurtainHose);
|
||
|
}
|
||
|
|
||
|
//禁用寻路
|
||
|
if (allConnectWaterCurtainHose.Count <= 0)
|
||
|
{
|
||
|
if (allConnectWaterHose.Count <= 0)
|
||
|
{
|
||
|
if (!GetComponent<TruckMessage>().IsFixedSupport)
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 刷新消防车出水UI
|
||
|
/// </summary>
|
||
|
private void RefreshUI(bool water, bool foam)
|
||
|
{
|
||
|
if (SelectedObjs.selectedObj == gameObject)
|
||
|
{
|
||
|
if (TruckSkillPanelController.GetInstance)
|
||
|
{//如果当前选中为该车辆且UI面板显示
|
||
|
// TruckSkillPanelController.GetInstance.SprayWater.gameObject.SetActive(water);
|
||
|
TruckSkillPanelController.GetInstance.SprayWater.GetComponent<Toggle>().interactable = water;//.gameObject.SetActive(value);
|
||
|
// TruckSkillPanelController.GetInstance.SprayFoam.gameObject.SetActive(foam);
|
||
|
TruckSkillPanelController.GetInstance.SprayFoam.GetComponent<Toggle>().interactable = foam;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 删除管线后检查是否依旧连接水源
|
||
|
/// </summary>
|
||
|
private void CheckWaterHose()
|
||
|
{
|
||
|
bool haswater = false;
|
||
|
bool hasfoam = false;
|
||
|
for (int i = 0; i < allConnectWaterHose.Count; i++)
|
||
|
{
|
||
|
var antherObj = allConnectWaterHose[i].GetComponent<ParentLinesMessage>().GetAnotherGameObj(gameObject);
|
||
|
//如果另一端有水源
|
||
|
if (antherObj.GetComponent<WaterSource>())
|
||
|
{
|
||
|
if (antherObj.GetComponent<WaterSource>().water)
|
||
|
{
|
||
|
haswater = true;
|
||
|
}
|
||
|
if (antherObj.GetComponent<WaterSource>().foam)
|
||
|
{
|
||
|
hasfoam = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
ConnectFoam = hasfoam;
|
||
|
ConnectWater = haswater;
|
||
|
RefreshUI(ConnectWater, ConnectFoam);
|
||
|
}
|
||
|
|
||
|
//非水源消防车连接水源后更新该车连接的消防员的水源信息
|
||
|
private void RefushFiremanWaterInfo(GameObject otherside)
|
||
|
{
|
||
|
if (otherside.GetComponent<FireManWaterHoseManager>())
|
||
|
{
|
||
|
otherside.GetComponent<FireManWaterHoseManager>().ResetWaterSourceConnectInfo(ConnectWater, ConnectFoam);
|
||
|
otherside.GetComponent<FireManWaterHoseManager>().ConnentSource = ConnentWaterSource;
|
||
|
if (otherside == SkillTollPanel.Instance.SelectObj)
|
||
|
{
|
||
|
//该消防员UI出水按钮可选显示
|
||
|
if (FireManSkillPanelController.Instance)
|
||
|
{
|
||
|
if (ConnectWater || ConnectFoam)
|
||
|
{
|
||
|
if (!FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable)
|
||
|
{
|
||
|
FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = true;
|
||
|
}
|
||
|
}
|
||
|
if (!ConnectWater && !ConnectFoam)
|
||
|
{
|
||
|
if (FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable)
|
||
|
{
|
||
|
FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 喷水
|
||
|
/// </summary>
|
||
|
public void SparyWater()
|
||
|
{
|
||
|
Hose.gameObject.SetActive(true);
|
||
|
for (int i = 0; i < Hose.childCount; i++)
|
||
|
{
|
||
|
//Destroy(Hose.GetChild(i).gameObject);
|
||
|
if (Hose.GetChild(i).gameObject.name == "WaterStraight")
|
||
|
{
|
||
|
if (!Hose.GetChild(i).gameObject.activeInHierarchy)
|
||
|
{
|
||
|
Hose.GetChild(i).gameObject.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Hose.GetChild(i).gameObject.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
//GameObject water = Instantiate(WaterStraightPrefabs, Hose.transform);
|
||
|
Hose.GetComponentInChildren<ParticleControlOfType>().SetScaleValue(0.7f);
|
||
|
ParticleSize = 0.7f;
|
||
|
JudeHightCarSpray();
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 高喷车出水内置判断
|
||
|
/// </summary>
|
||
|
private void JudeHightCarSpray()
|
||
|
{
|
||
|
if (GetComponent<CloneGameObjInfo>().gameObjType == CloneObjType.HighSprayingTruck)
|
||
|
{
|
||
|
bool isconnecttwo = true;
|
||
|
if (waterSourceLine1.Count < 1 || waterSourceLine2.Count < 1)
|
||
|
{//如果有一条线路没链接,内置判断为错
|
||
|
isconnecttwo = false;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
long con1 = waterSourceLine1[0][0];//路线1 直接水源id
|
||
|
long con2 = waterSourceLine2[0][0];//路线2 直接水源id
|
||
|
if (con1 == con2)
|
||
|
{//两个直接水源一样,则连在一个水源车上,内置判断为错
|
||
|
isconnecttwo = false;
|
||
|
}
|
||
|
}
|
||
|
if (!isconnecttwo)
|
||
|
{
|
||
|
//发送错误报告同步信息
|
||
|
ReportErroeSyncData arg = new ReportErroeSyncData();
|
||
|
// (GetComponent<TIME_SYNC>())
|
||
|
{
|
||
|
arg.Time = TIME_SYNC.time;
|
||
|
}
|
||
|
arg.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
arg.errorset = CurrentUserInfo.role.ToString();
|
||
|
arg.describe = "高喷车出水只连接一个水源";
|
||
|
NetworkManager.Default.SendAsync("REPORT_ERROR_SYNC", arg);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 喷泡沫
|
||
|
/// </summary>
|
||
|
public void SparyFoam()
|
||
|
{
|
||
|
Hose.gameObject.SetActive(true);
|
||
|
for (int i = 0; i < Hose.childCount; i++)
|
||
|
{
|
||
|
if (Hose.GetChild(i).gameObject.name == "Froth")
|
||
|
{
|
||
|
if (!Hose.GetChild(i).gameObject.activeInHierarchy)
|
||
|
{
|
||
|
Hose.GetChild(i).gameObject.SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Hose.GetChild(i).gameObject.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
// GameObject froth = Instantiate(FrothPrefabs, Hose.transform);
|
||
|
Hose.GetComponentInChildren<ParticleControlOfType>().SetScaleValue(1f);
|
||
|
ParticleSize = 1f;
|
||
|
}
|
||
|
public void StopSpray()
|
||
|
{
|
||
|
Hose.gameObject.SetActive(false);
|
||
|
for (int i = 0; i < Hose.childCount; i++)
|
||
|
{
|
||
|
Hose.GetChild(i).gameObject.SetActive(false);
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 重置水源信息跟出水状态
|
||
|
/// </summary>
|
||
|
public void Resert()
|
||
|
{
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{
|
||
|
ConnectWater = GetComponent<WaterSource>().water;
|
||
|
ConnectFoam = GetComponent<WaterSource>().foam;
|
||
|
ConnentWaterSource = gameObject;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ConnectWater = false;
|
||
|
ConnectFoam = false;
|
||
|
ConnentWaterSource = null;
|
||
|
}
|
||
|
StopSpray();
|
||
|
SpraySyncData spraysync = new SpraySyncData();
|
||
|
spraysync.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
spraysync.IsOn = false;
|
||
|
spraysync.gameObjID = gameobjinfo.gameObjID;
|
||
|
NetworkManager.Default.SendAsync("SPRAY_WATER_SYNC", spraysync);
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 连接水源。删除管线时造成的水源信息修改
|
||
|
/// </summary>
|
||
|
/// <param name="watersourcevalue">直接水源上的两条线路信息总和</param>
|
||
|
/// <param name="directionId">直接水源id</param>
|
||
|
/// <param name="linenum">连接的哪条线路</param>
|
||
|
public void ChangeWaterSourceLineInfo(long directionId, int linenum)
|
||
|
{
|
||
|
List<List<long>> go = CloneBySerialize.Clone(GetDirectWaterSourceInfo(directionId));
|
||
|
go.Insert(0, new List<long> { directionId });
|
||
|
if (linenum == 1)
|
||
|
{
|
||
|
WaterSourceLine1 = go;
|
||
|
}
|
||
|
else if (linenum == 2)
|
||
|
{
|
||
|
WaterSourceLine2 = go;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 获取直接水源上的所有水源信息
|
||
|
/// </summary>
|
||
|
/// <param name="directtionId">直接水源ID</param>
|
||
|
/// <returns></returns>
|
||
|
public List<List<long>> GetDirectWaterSourceInfo(long directtionId)
|
||
|
{
|
||
|
List<List<long>> go = new List<List<long>>();
|
||
|
GameObject dirobj = EntitiesManager.Instance.GetEntityByID(directtionId);
|
||
|
if (dirobj.GetComponent<TruckBindWaterSource>())
|
||
|
{
|
||
|
TruckBindWaterSource dirTBC = dirobj.GetComponent<TruckBindWaterSource>();
|
||
|
List<List<long>> line1 = CloneBySerialize.Clone(dirTBC.WaterSourceLine1);
|
||
|
List<List<long>> line2 = CloneBySerialize.Clone(dirTBC.WaterSourceLine2);
|
||
|
line1.Reverse();
|
||
|
line2.Reverse();
|
||
|
int count = line1.Count >= line2.Count ? line1.Count : line2.Count;
|
||
|
//List<List<long>> go = new List<List<long>>(count);
|
||
|
for (int i = 0; i < count; i++)
|
||
|
{
|
||
|
List<long> depth = new List<long>();
|
||
|
if (i < line1.Count)
|
||
|
{
|
||
|
for (int j = 0; j < line1[i].Count; j++)
|
||
|
{
|
||
|
depth.Add(line1[i][j]);
|
||
|
}
|
||
|
}
|
||
|
if (i < line2.Count)
|
||
|
{
|
||
|
for (int j = 0; j < line2[i].Count; j++)
|
||
|
{
|
||
|
depth.Add(line2[i][j]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
go.Add(depth);
|
||
|
}
|
||
|
go.Reverse();
|
||
|
}
|
||
|
else
|
||
|
{//消防设施没有进水口,所以直接返回go
|
||
|
}
|
||
|
|
||
|
return go;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 检查出水口连接并更改出水口连接物体的水源信息
|
||
|
/// </summary>
|
||
|
void checkOutAndChangeWaterInfo()
|
||
|
{
|
||
|
if (DirectConnectObj1.Key != null)
|
||
|
{
|
||
|
checkandchange(DirectConnectObj1);
|
||
|
}
|
||
|
if (DirectConnectObj2.Key != null)
|
||
|
{
|
||
|
checkandchange(DirectConnectObj2);
|
||
|
}
|
||
|
}
|
||
|
void checkandchange(KeyValuePair<GameObject, int> target)
|
||
|
{
|
||
|
if (target.Key.GetComponent<TruckBindWaterSource>())
|
||
|
{
|
||
|
// TruckBindWaterSource tbws = target.Key.GetComponent<TruckBindWaterSource>();
|
||
|
//if (tbws.WaterSourceLine1[0][0] == gameobjinfo.gameObjID)
|
||
|
// {//如果线路1连接的本车辆
|
||
|
target.Key.GetComponent<TruckBindWaterSource>().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, target.Value);
|
||
|
// }
|
||
|
// else if (tbws.WaterSourceLine2[0][0] == gameobjinfo.gameObjID)
|
||
|
// {
|
||
|
//如果线路2连接的本车辆
|
||
|
//target.Key.GetComponent<TruckBindWaterSource>().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 2);
|
||
|
//}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
CloneObjType type = target.Key.GetComponent<BaseGameObjInfo>().gameObjType;
|
||
|
|
||
|
if (type == CloneObjType.fireman)
|
||
|
{
|
||
|
target.Key.GetComponent<FireManControl>().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 0);
|
||
|
}
|
||
|
else if (type == CloneObjType.FirefightingRobot)
|
||
|
{
|
||
|
target.Key.GetComponent<FireRobotController>().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 0);
|
||
|
}
|
||
|
else if (type == CloneObjType.SnowCannon)
|
||
|
{
|
||
|
target.Key.GetComponent<SnowConnonController>().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 0);
|
||
|
}
|
||
|
else if (type == CloneObjType.WaterCannon)
|
||
|
{
|
||
|
target.Key.GetComponent<WaterConnonController>().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取车辆上的所有水源车辆,有重复添加(若任意线路上任意连接点进水口1跟2连接的同一水源,则重复)
|
||
|
/// 不能根据末尾计算消耗,因为当某水源节点两个进水口连接同一水源但是水源线长度不同,则会出现末尾可能出现在前边
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public List<List<long>> GetAllWaterSource()
|
||
|
{
|
||
|
List<List<long>> go = new List<List<long>>();
|
||
|
List<List<long>> line1 = CloneBySerialize.Clone(WaterSourceLine1);
|
||
|
List<List<long>> line2 = CloneBySerialize.Clone(WaterSourceLine2);
|
||
|
line1.Reverse();
|
||
|
line2.Reverse();
|
||
|
int count = line1.Count >= line2.Count ? line1.Count : line2.Count;
|
||
|
//List<List<long>> go = new List<List<long>>(count);
|
||
|
for (int i = 0; i < count; i++)
|
||
|
{
|
||
|
List<long> depth = new List<long>();
|
||
|
if (i < line1.Count)
|
||
|
{
|
||
|
for (int j = 0; j < line1[i].Count; j++)
|
||
|
{
|
||
|
depth.Add(line1[i][j]);
|
||
|
}
|
||
|
}
|
||
|
if (i < line2.Count)
|
||
|
{
|
||
|
for (int j = 0; j < line2[i].Count; j++)
|
||
|
{
|
||
|
depth.Add(line2[i][j]);
|
||
|
}
|
||
|
}
|
||
|
go.Add(depth);
|
||
|
}
|
||
|
go.Reverse();
|
||
|
return go;
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 检查某条线路上是否有水
|
||
|
/// </summary>
|
||
|
/// <param name="watersouce"></param>
|
||
|
/// <returns></returns>
|
||
|
public float checkWaterRemain(List<List<long>> watersouce)
|
||
|
{
|
||
|
float allremain = 0;
|
||
|
|
||
|
for (int i = 0; i < watersouce.Count; i++)
|
||
|
{
|
||
|
for (int j = 0; j < watersouce[i].Count; j++)
|
||
|
{
|
||
|
|
||
|
if (EntitiesManager.Instance.GetEntityByID(watersouce[i][j])
|
||
|
&& EntitiesManager.Instance.GetEntityByID(watersouce[i][j]).GetComponent<WaterSource>())
|
||
|
{
|
||
|
WaterSource ws = EntitiesManager.Instance.GetEntityByID(watersouce[i][j]).GetComponent<WaterSource>();
|
||
|
if (ws.TotalWater != -100)
|
||
|
{
|
||
|
allremain += (ws.TotalWater - ws.AllUserWater);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
allremain = -100;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
return allremain;
|
||
|
}
|
||
|
KeyValuePair<GameObject, int> Directionconnect(GameObject anther, long EndId, long StartId, KeyValuePair<GameObject, int> target, GameObject hose)
|
||
|
{
|
||
|
target = new KeyValuePair<GameObject, int>();
|
||
|
if (anther.GetComponent<TruckBindWaterSource>())
|
||
|
{//另一端为可出水车辆
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count <= 0)
|
||
|
{//另一端进水口1没有被占用,连接进水口1
|
||
|
target = new KeyValuePair<GameObject, int>(anther, 1);
|
||
|
WaterHoseEndDo arg = new WaterHoseEndDo
|
||
|
{
|
||
|
ConnectHose = hose,
|
||
|
StartId = gameobjinfo.gameObjID,
|
||
|
ConnectInPoint = 1,
|
||
|
EndId = EndId,
|
||
|
};
|
||
|
MessageDispatcher.SendMessage("StartConnectDone", arg);
|
||
|
Debug.Log(name + "出水口占用" + anther.name + "的进水口1");
|
||
|
//连接了一个出水的网络
|
||
|
|
||
|
if (anther.GetComponent<WaterSource>())
|
||
|
{//有watersource必为水源车,因为消防设施不能为连接终点
|
||
|
//注:考虑喷泡沫的情况,如果另一端为水源车,如果出泡沫,则泡沫值消耗其自身泡沫量,连接供水网络跟泡沫无关
|
||
|
|
||
|
//注:这里存在因为自身及自身供水端没有水的情况而导致水流量为0(即直接连接物体没有水、不出水,但是其下属连接可能存在出水情况,也是连接的出水网络)
|
||
|
//此时watersource脚本的HasWaterSelfAndLine为false,修改这个值.HasWaterSelfAndLine为false修改后会逐级修改下一级的HasWaterSelfAndLine为false值,
|
||
|
//当遇到出水的车辆时(若为其他,单干线),会根据出水车辆的流量进行分流,分流后又会主逐级上找,修改TotalFlow
|
||
|
if (GetComponent<WaterSource>().HasWaterSelfAndLine)
|
||
|
{//自己本身有水
|
||
|
if (anther.GetComponent<WaterSource>().HasWaterSelfAndLine == false)
|
||
|
{
|
||
|
anther.GetComponent<WaterSource>().HasWaterSelfAndLine = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (anther.GetComponent<WaterSource>().TotalFlow > 0)
|
||
|
{//连接的网络正在出水,修改流量信息 ,泡沫消耗自己的,不考虑泡沫的分配
|
||
|
|
||
|
if (!GetComponent<WaterSource>().HasWaterSelfAndLine)
|
||
|
{//自身没水
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{//自身有水,分流
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count > 0)
|
||
|
{//另一条进水口有水源,另一端连接的肯定为进水口2
|
||
|
|
||
|
float remain = anther.GetComponent<TruckBindWaterSource>().checkWaterRemain(
|
||
|
anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2);
|
||
|
|
||
|
if (remain > 0 || remain == -100)
|
||
|
{//另一端水源有水
|
||
|
|
||
|
if (gameobjinfo.gameObjID == anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2[0][0])
|
||
|
{//另一端连接的是自己,不更改流量信息
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
GameObject antherdir2 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2[0][0]);
|
||
|
antherdir2.GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{//另一端水源没水了但是在出水可能是消耗自己的水
|
||
|
//另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count <= 0)
|
||
|
{//另一点没水源
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//连接的是单一物体或非水源车辆
|
||
|
if (!GetComponent<WaterSource>().HasWaterSelfAndLine)
|
||
|
{//自身没水
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{//自己有水
|
||
|
if (anther.GetComponent<TruckBindWaterSource>())
|
||
|
{//连接的是可出水车辆
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().Flow > 0)
|
||
|
{//出水车辆在出水,分流
|
||
|
|
||
|
//出的是泡沫,分流注意
|
||
|
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count > 0)
|
||
|
{//另一条进水口有水源,另一端连接的肯定为进水口2
|
||
|
float remain = anther.GetComponent<TruckBindWaterSource>().checkWaterRemain(
|
||
|
anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2);
|
||
|
if (remain > 0 || remain == -100)
|
||
|
{//另一端水源有水
|
||
|
|
||
|
if (gameobjinfo.gameObjID == anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2[0][0])
|
||
|
{//另一端连接的是自己
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GameObject antherdir2 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2[0][0]);
|
||
|
if (anther.GetComponentInChildren<ParticleControlOfType>().particleType == SprayParticleType.Froth)
|
||
|
{//如果出的是泡沫
|
||
|
WaterSource waters = GetComponent<WaterSource>();
|
||
|
if (waters.foam && (waters.AllUserFoam == -100 || (waters.TotalFoam - waters.AllUserFoam) > 0))
|
||
|
{//本车有泡沫
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow / 2);
|
||
|
antherdir2.GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow / 2);
|
||
|
}
|
||
|
else
|
||
|
{//本身没泡沫啥也不干
|
||
|
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//出的不是泡沫
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow / 2);
|
||
|
antherdir2.GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow / 2);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{//另一端没水了也就不用考虑是不是泡沫的问题
|
||
|
//另一端水源没水了但是在出水可能是消耗自己的水
|
||
|
//另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑
|
||
|
Debug.Log(anther + " 水源没有水还在继续出水");
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count <= 0)
|
||
|
{//另一条没连水源,也就是之前没水源,也就没有在出水
|
||
|
Debug.Log(anther + "没有连接水源还在出水,流量未分配");
|
||
|
// GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//消防员、水泡、机器人、雪炮,肯定没有在出水,不处理
|
||
|
//因为上边判断了含有truckbindwater脚本,所以这里不会走
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//另一端进水口1被占用
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1[0][0] == StartId)
|
||
|
{//占用另一端进水口的是自己
|
||
|
Debug.Log(name + "出水口//已经//占用" + anther.name + "的进水口1");
|
||
|
//target = new KeyValuePair<GameObject, int>(anther, 1);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count <= 0)
|
||
|
{
|
||
|
//另一端进水口2没有被占用,连接进水口2
|
||
|
target = new KeyValuePair<GameObject, int>(anther, 2);
|
||
|
WaterHoseEndDo arg = new WaterHoseEndDo
|
||
|
{
|
||
|
ConnectHose = hose,
|
||
|
StartId = gameobjinfo.gameObjID,
|
||
|
ConnectInPoint = 2,
|
||
|
EndId = EndId,
|
||
|
};
|
||
|
MessageDispatcher.SendMessage("StartConnectDone", arg);
|
||
|
Debug.Log(name + "出水口占用" + anther.name + "的进水口2");
|
||
|
//连接了一个出水的网络
|
||
|
if (anther.GetComponent<WaterSource>())
|
||
|
{//有watersource必为水源车,因为消防设施不能为连接终点
|
||
|
|
||
|
if (GetComponent<WaterSource>().HasWaterSelfAndLine)
|
||
|
{//自己本身有水
|
||
|
if (anther.GetComponent<WaterSource>().HasWaterSelfAndLine == false)
|
||
|
{
|
||
|
anther.GetComponent<WaterSource>().HasWaterSelfAndLine = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (anther.GetComponent<WaterSource>().TotalFlow > 0)
|
||
|
{//连接的网络正在出水,修改流量信息
|
||
|
|
||
|
|
||
|
float line1remain = checkWaterRemain(WaterSourceLine1);
|
||
|
float line2remain = checkWaterRemain(WaterSourceLine2);
|
||
|
//if (!((line1remain > 0 || line1remain == -100) || (line2remain > 0 || line2remain == -100) ||
|
||
|
// (GetComponent<WaterSource>().AllUserWater < GetComponent<WaterSource>().TotalWater)))
|
||
|
if (!GetComponent<WaterSource>().HasWaterSelfAndLine)
|
||
|
{//自身没水不修改流量信息
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count > 0)
|
||
|
{//另一条进水口有水源,另一端连接的肯定为进水口1
|
||
|
float remain = anther.GetComponent<TruckBindWaterSource>().checkWaterRemain(
|
||
|
anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1);
|
||
|
if (remain > 0 || remain == -100)
|
||
|
{//另一端水源有水
|
||
|
|
||
|
if (gameobjinfo.gameObjID == anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1[0][0])
|
||
|
{//另一端就是自己
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
GameObject antherdir1 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1[0][0]);
|
||
|
antherdir1.GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//另一端水源没水了但是在出水可能是消耗自己的水
|
||
|
//另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
}
|
||
|
else if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count <= 0)
|
||
|
{//另一端空着,没连水源
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//连接的是单一物体或可出水车辆
|
||
|
|
||
|
if (!GetComponent<WaterSource>().HasWaterSelfAndLine)
|
||
|
{//自身没水不修改流量信息
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (anther.GetComponent<TruckBindWaterSource>())
|
||
|
{//连接的是可出水车辆
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().Flow > 0)
|
||
|
{//出水车辆在出水,分流
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count > 0)
|
||
|
{//另一条进水口有水源,另一端连接的肯定为进水口2
|
||
|
float remain = anther.GetComponent<TruckBindWaterSource>().checkWaterRemain(
|
||
|
anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1);
|
||
|
if (remain > 0 || remain == -100)
|
||
|
{//另一端水源有水
|
||
|
|
||
|
if (gameobjinfo.gameObjID == anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1[0][0])
|
||
|
{//另一端连接的自己
|
||
|
GameObject antherdir1 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1[0][0]);
|
||
|
if (anther.GetComponentInChildren<ParticleControlOfType>().particleType == SprayParticleType.Froth)
|
||
|
{//出水端出的泡沫
|
||
|
WaterSource waters = GetComponent<WaterSource>();
|
||
|
if (waters.foam && (waters.AllUserFoam == -100 || (waters.TotalFoam - waters.AllUserFoam) > 0))
|
||
|
{//本车有泡沫
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow / 2);
|
||
|
antherdir1.GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow / 2);
|
||
|
}
|
||
|
else
|
||
|
{//本身没泡沫啥也不干
|
||
|
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow / 2);
|
||
|
antherdir1.GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<TruckBindWaterSource>().Flow / 2);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//另一端水源没水了但是在出水可能是消耗自己的水
|
||
|
//另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑
|
||
|
GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count <= 0)
|
||
|
{//另一条线没水
|
||
|
Debug.Log(anther + "没有连接水源还在出水,流量未分配");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{//消防员、水泡、机器人、雪炮,肯定没有在出水,不处理
|
||
|
//这里不会走
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2[0][0] == StartId)
|
||
|
{
|
||
|
//target = new KeyValuePair<GameObject, int>(anther, 2);
|
||
|
Debug.Log(name + "出水口//已经//占用" + anther.name + "的进水口2");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Debug.Log(anther.name + " 没有更多进水口,检查连接逻辑");
|
||
|
// target = new KeyValuePair<GameObject, int>(anther, 0);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
target = new KeyValuePair<GameObject, int>(anther, 0);
|
||
|
}
|
||
|
return target;
|
||
|
}
|
||
|
#region
|
||
|
//void Direction2conncet(GameObject anther, long EndId, long StartId)
|
||
|
//{
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>())
|
||
|
// {//另一端为可出水车辆
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count <= 0)
|
||
|
// {//另一端进水口1没有被占用,连接进水口1
|
||
|
// DirectConnectObj2 = new KeyValuePair<GameObject, int>(anther, 1);
|
||
|
|
||
|
// //连接了一个出水的网络
|
||
|
// if (anther.GetComponent<WaterSource>())
|
||
|
// {//有watersource必为水源车,因为消防设施不能为连接终点
|
||
|
// if (anther.GetComponent<WaterSource>().TotalFlow > 0)
|
||
|
// {//连接的网络正在出水,修改流量信息
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count > 0)
|
||
|
// {//另一条进水口有水源,另一端连接的肯定为进水口2
|
||
|
// float remain = anther.GetComponent<TruckBindWaterSource>().checkWaterRemain(
|
||
|
// anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2);
|
||
|
// if (remain > 0 || remain == -100)
|
||
|
// {//另一端水源有水
|
||
|
// GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
// GameObject antherdir2 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2[0][0]);
|
||
|
// antherdir2.GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
// }
|
||
|
// else
|
||
|
// {//另一端水源没水了但是在出水可能是消耗自己的水
|
||
|
// //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑
|
||
|
// GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow);
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
// else
|
||
|
// {//另一端进水口1被占用
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1[0][0] == StartId)
|
||
|
// {//占用另一端进水口的是自己
|
||
|
// Debug.Log(name + "出水口2占用" + anther.name + "的进水口1");
|
||
|
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2.Count <= 0)
|
||
|
// {
|
||
|
// //另一端进水口2没有被占用,连接进水口2
|
||
|
// DirectConnectObj2 = new KeyValuePair<GameObject, int>(anther, 2);
|
||
|
|
||
|
// //连接了一个出水的网络
|
||
|
// if (anther.GetComponent<WaterSource>())
|
||
|
// {//有watersource必为水源车,因为消防设施不能为连接终点
|
||
|
// if (anther.GetComponent<WaterSource>().TotalFlow > 0)
|
||
|
// {//连接的网络正在出水,修改流量信息
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1.Count > 0)
|
||
|
// {//另一条进水口有水源,另一端连接的肯定为进水口1
|
||
|
// float remain = anther.GetComponent<TruckBindWaterSource>().checkWaterRemain(
|
||
|
// anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1);
|
||
|
// if (remain > 0 || remain == -100)
|
||
|
// {//另一端水源有水
|
||
|
// GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
// GameObject antherdir1 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent<TruckBindWaterSource>().WaterSourceLine1[0][0]);
|
||
|
// antherdir1.GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow / 2);
|
||
|
// }
|
||
|
// else
|
||
|
// {//另一端水源没水了但是在出水可能是消耗自己的水
|
||
|
// //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑
|
||
|
// GetComponent<WaterSource>().TotalFlowChange(EndId, anther.GetComponent<WaterSource>().TotalFlow);
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// if (anther.GetComponent<TruckBindWaterSource>().WaterSourceLine2[0][0] == StartId)
|
||
|
// {
|
||
|
// Debug.Log(name + "出水口2占用" + anther.name + "的进水口2");
|
||
|
// }
|
||
|
// else
|
||
|
// Debug.Log(anther.name + " 没有更多进水口,检查连接逻辑");
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {//另一端为非车辆,则只有一个进水口
|
||
|
// DirectConnectObj2 = new KeyValuePair<GameObject, int>(anther, 0);
|
||
|
// }
|
||
|
//}
|
||
|
#endregion
|
||
|
/// <summary>
|
||
|
/// 获取车辆可持续出水时间跟剩余水量
|
||
|
/// </summary>
|
||
|
/// <param name="waterline"></param>
|
||
|
/// <returns></returns>
|
||
|
public KeyValuePair<int, float> GetWaterAndTimeRemain(List<List<long>> waterline1, List<List<long>> waterline2)
|
||
|
{
|
||
|
KeyValuePair<int, float> timewater = new KeyValuePair<int, float>();
|
||
|
// float allflow = 0f;//整个网络的中出水流量
|
||
|
float remainwater = 0f;
|
||
|
List<long> allwatersource = new List<long>();
|
||
|
for (int i = 0; i < waterline1.Count; i++)
|
||
|
{
|
||
|
for (int j = 0; j < waterline1[i].Count; j++)
|
||
|
{
|
||
|
if (!allwatersource.Contains(waterline1[i][j]))
|
||
|
{
|
||
|
allwatersource.Add(waterline1[i][j]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for (int i = 0; i < waterline2.Count; i++)
|
||
|
{
|
||
|
for (int j = 0; j < waterline2[i].Count; j++)
|
||
|
{
|
||
|
if (!allwatersource.Contains(waterline2[i][j]))
|
||
|
{
|
||
|
allwatersource.Add(waterline2[i][j]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{
|
||
|
allwatersource.Add(GetComponent<BaseGameObjInfo>().gameObjID);
|
||
|
}
|
||
|
for (int i = 0; i < allwatersource.Count; i++)
|
||
|
{
|
||
|
if (EntitiesManager.Instance.GetEntityByID(allwatersource[i]))
|
||
|
{
|
||
|
WaterSource ws = EntitiesManager.Instance.GetEntityByID(allwatersource[i]).GetComponent<WaterSource>();
|
||
|
if (ws.TotalWater != -100)
|
||
|
{
|
||
|
remainwater += (ws.TotalWater - ws.AllUserWater);
|
||
|
//if (ws.GetComponent<TruckBindWaterSource>())
|
||
|
//{
|
||
|
// allflow += ws.GetComponent<TruckBindWaterSource>().Flow;
|
||
|
//}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
remainwater = -100;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
int remaintime = 0;
|
||
|
//allflow += Flow;
|
||
|
if (remainwater == -100)
|
||
|
{
|
||
|
remaintime = -100;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//if (allflow != 0)
|
||
|
// remaintime = Mathf.CeilToInt(remainwater / allflow);
|
||
|
WaterSource dirws1;
|
||
|
if (WaterSourceLine1.Count > 0)
|
||
|
{
|
||
|
if (EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]) &&
|
||
|
EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]).GetComponent<WaterSource>())
|
||
|
{
|
||
|
dirws1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]).GetComponent<WaterSource>();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
dirws1 = null;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
dirws1 = null;
|
||
|
}
|
||
|
WaterSource dirws2;
|
||
|
if (WaterSourceLine2.Count > 0)
|
||
|
{
|
||
|
dirws2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]).GetComponent<WaterSource>();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
dirws2 = null;
|
||
|
}
|
||
|
float dirflow = 0;
|
||
|
//注 :一开始dirws1与dirws2不为空但是dirflow仍然为0,出现情况可能为流量还未分配,水源上的TotalFlow仍然为0
|
||
|
if (dirws1 != null)
|
||
|
{
|
||
|
dirflow += dirws1.TotalFlow;
|
||
|
}
|
||
|
if (dirws2 != null)
|
||
|
dirflow += dirws2.TotalFlow;
|
||
|
float realwatersource = 0;//实际分到的水源
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{//本身是水源车
|
||
|
|
||
|
if (dirflow <= 0)
|
||
|
{//没有连接水源或者连接的水源没有水
|
||
|
if (GetComponent<WaterSource>().TotalFlow != 0)
|
||
|
{
|
||
|
realwatersource =/* (Flow / GetComponent<WaterSource>().TotalFlow) **/ remainwater;
|
||
|
remaintime = Mathf.CeilToInt(realwatersource / GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
remaintime = 0;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//连接水源的总水量
|
||
|
float thiscarwater = (GetComponent<WaterSource>().TotalWater - GetComponent<WaterSource>().AllUserWater);
|
||
|
float watersourcewater = remainwater - thiscarwater;
|
||
|
//注:本身的水源不参与到供水方的流量比来计算分到的真实水源
|
||
|
realwatersource = (GetComponent<WaterSource>().TotalFlow / dirflow) * watersourcewater + thiscarwater;
|
||
|
remaintime = Mathf.CeilToInt(realwatersource / GetComponent<WaterSource>().TotalFlow);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (dirflow != 0)
|
||
|
{
|
||
|
realwatersource = (Flow / dirflow) * remainwater;
|
||
|
remaintime = Mathf.CeilToInt(realwatersource / Flow);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
remaintime = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
timewater = new KeyValuePair<int, float>(remaintime, remainwater);
|
||
|
|
||
|
return timewater;
|
||
|
}
|
||
|
void stopspraywaterorform()
|
||
|
{
|
||
|
|
||
|
Debug.Log(name + "end");
|
||
|
StopSpray();
|
||
|
RemainTime = 0;
|
||
|
RemainWater = 0;
|
||
|
GetComponent<TruckMessage>().NowSkill = TruckSkills.待命;
|
||
|
Flow = 0;
|
||
|
if (TruckSkillPanelController.GetInstance && TruckSkillPanelController.GetInstance.NowBindTruck == GetComponent<TruckMessage>())
|
||
|
{
|
||
|
if (TruckSkillPanelController.GetInstance.SprayWater.GetComponent<Toggle>().isOn)
|
||
|
{
|
||
|
TruckSkillPanelController.GetInstance.SprayWater.GetComponent<Toggle>().isOn = false;
|
||
|
}
|
||
|
if (TruckSkillPanelController.GetInstance.SprayFoam.GetComponent<Toggle>().isOn)
|
||
|
{
|
||
|
TruckSkillPanelController.GetInstance.SprayFoam.GetComponent<Toggle>().isOn = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
SpraySyncData spraysync = new SpraySyncData();
|
||
|
spraysync.SendUserID = CurrentUserInfo.mySelf.Id;
|
||
|
spraysync.IsOn = false;
|
||
|
spraysync.gameObjID = gameobjinfo.gameObjID;
|
||
|
NetworkManager.Default.SendAsync("SPRAY_WATER_SYNC", spraysync);
|
||
|
|
||
|
}
|
||
|
|
||
|
public float CheckFoamRemain()
|
||
|
{
|
||
|
float remain = 0;
|
||
|
if (GetComponent<WaterSource>())
|
||
|
{
|
||
|
WaterSource ws = GetComponent<WaterSource>();
|
||
|
remain = ws.TotalFoam - ws.AllUserFoam;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (WaterSourceLine1.Count > 0)
|
||
|
{
|
||
|
GameObject wsl1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]);
|
||
|
if (!wsl1.GetComponent<TruckMessage>())
|
||
|
{
|
||
|
remain = -100;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
WaterSource ws = wsl1.GetComponent<WaterSource>();
|
||
|
remain += (ws.TotalFoam - ws.AllUserFoam);
|
||
|
}
|
||
|
if (WaterSourceLine2.Count > 0)
|
||
|
{
|
||
|
GameObject wsl2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]);
|
||
|
if (!wsl2.GetComponent<TruckMessage>())
|
||
|
{
|
||
|
remain = -100;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
WaterSource ws = wsl2.GetComponent<WaterSource>();
|
||
|
remain += (ws.TotalFoam - ws.AllUserFoam);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (WaterSourceLine2.Count > 0)
|
||
|
{
|
||
|
GameObject wsl2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]);
|
||
|
if (!wsl2.GetComponent<TruckMessage>())
|
||
|
{
|
||
|
remain = -100;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
WaterSource ws = wsl2.GetComponent<WaterSource>();
|
||
|
remain += (ws.TotalFoam - ws.AllUserFoam);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
return remain;
|
||
|
}
|
||
|
}
|