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.
295 lines
11 KiB
295 lines
11 KiB
4 years ago
|
using AX.MessageSystem;
|
||
|
using AX.NetworkSystem;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class FireRobotWaterHoseManage : MonoBehaviour
|
||
|
{
|
||
|
public List<List<long>> WaterSourceLine = new List<List<long>>();//进水口线路
|
||
|
|
||
|
public string WaterHoseID = "82";
|
||
|
[Header("一盘水带默认长度")]
|
||
|
public float OneDefaultHoseLenght = 20f;
|
||
|
[Header("是否装备水带")]
|
||
|
public bool HasWaterHose;
|
||
|
/// <summary>
|
||
|
/// 剩余水带长度
|
||
|
/// </summary>
|
||
|
[Header("水带剩余长度")]
|
||
|
public float WaterHoseLenghtRemain;
|
||
|
//[Header("水带初始携带数")]
|
||
|
// public int BeginCarryWaterHose = 5;
|
||
|
/// <summary>
|
||
|
/// 当前剩下盘数
|
||
|
/// </summary>
|
||
|
[Header("当前还剩的盘数")]
|
||
|
public int NowRemainWaterHose = 0;
|
||
|
/// <summary>
|
||
|
/// 当前机器人是否连接水带
|
||
|
/// </summary>
|
||
|
public bool IsConnentWaterLine;
|
||
|
/// <summary>
|
||
|
/// 连接的水带
|
||
|
/// </summary>
|
||
|
public GameObject WaterLineConnent;
|
||
|
/// <summary>
|
||
|
/// 是否连接水源
|
||
|
/// </summary>
|
||
|
public bool IsConnentWaterSource;
|
||
|
/// <summary>
|
||
|
/// 连接的水源
|
||
|
/// </summary>
|
||
|
public GameObject ConnentSource;
|
||
|
public bool hasWaterConnect;
|
||
|
public bool hasFoamConnect;
|
||
|
private BaseGameObjInfo baseinfo;
|
||
|
|
||
|
List<Equip> all;
|
||
|
private long gameobjid;
|
||
|
private FireManControl firemancontrol;
|
||
|
private Bags bagdata;
|
||
|
// public int AllEquipNum;
|
||
|
// Use this for initialization
|
||
|
void Start()
|
||
|
{
|
||
|
baseinfo = GetComponent<BaseGameObjInfo>();
|
||
|
GetComponent<Bags>().OnAddEquip += AddEquip;
|
||
|
WaterHoseLenghtRemain = OneDefaultHoseLenght * NowRemainWaterHose;
|
||
|
all = GetComponent<Bags>().EquipData;
|
||
|
gameobjid = GetComponent<BaseGameObjInfo>().gameObjID;
|
||
|
firemancontrol = GetComponent<FireManControl>();
|
||
|
bagdata = GetComponent<Bags>();
|
||
|
MessageDispatcher.AddListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectControl);
|
||
|
}
|
||
|
|
||
|
public void OnDisable()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectControl);
|
||
|
}
|
||
|
|
||
|
public void OnDestroy()
|
||
|
{
|
||
|
MessageDispatcher.RemoveListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectControl);
|
||
|
}
|
||
|
private void ConnectOrDelectControl(IMessage obj)
|
||
|
{
|
||
|
HoseConnectOrDelectData data = (HoseConnectOrDelectData)obj.Data;
|
||
|
if (data.StartId == baseinfo.gameObjID ||
|
||
|
data.EndId == baseinfo.gameObjID)
|
||
|
{
|
||
|
//移动处理
|
||
|
if (data.Isconnect)
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = false;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = true;
|
||
|
}
|
||
|
//水源信息处理
|
||
|
GameObject connectHose = EntitiesManager.Instance.GetEntityByID(data.HoseId);
|
||
|
|
||
|
GameObject anther = connectHose.GetComponent<ParentLinesMessage>().GetAnotherGameObj(baseinfo.gameObjID);
|
||
|
if (data.Isconnect)
|
||
|
{
|
||
|
if (anther.GetComponent<WaterSource>())
|
||
|
{//另一端是水源
|
||
|
IsConnentWaterLine = true;
|
||
|
WaterLineConnent = connectHose;
|
||
|
IsConnentWaterSource = true;
|
||
|
ConnentSource = anther;
|
||
|
hasWaterConnect = anther.GetComponent<WaterSource>().water;
|
||
|
hasFoamConnect = anther.GetComponent<WaterSource>().foam;
|
||
|
GetComponent<FireRobotController>().ChangeWaterSourceLineInfo(data.StartId,0);
|
||
|
////如果连接了一个没有水的水源
|
||
|
//if (anther.GetComponent<WaterSource>().hasover)
|
||
|
//{
|
||
|
// GetComponent<FireManControl>().waterrunoutof = true;
|
||
|
//}
|
||
|
}
|
||
|
//if (anther.GetComponent<TruckBindWaterSource>() && !anther.GetComponent<WaterSource>())
|
||
|
//{//另一端是非水源出水车辆
|
||
|
// ConnentSource = anther.GetComponent<TruckBindWaterSource>().ConnentWaterSource;
|
||
|
// if (ConnentSource != null)
|
||
|
// {
|
||
|
// IsConnentWaterSource = true;
|
||
|
// hasWaterConnect = anther.GetComponent<TruckBindWaterSource>().ConnectWater;
|
||
|
// hasFoamConnect = anther.GetComponent<TruckBindWaterSource>().ConnectFoam;
|
||
|
|
||
|
// if (ConnentSource.GetComponent<WaterSource>())
|
||
|
// {
|
||
|
// if (ConnentSource.GetComponent<WaterSource>().hasover)
|
||
|
// {
|
||
|
// GetComponent<FireManControl>().waterrunoutof = true;
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
//}
|
||
|
if (FireRobotSkillPanelController.Instance)
|
||
|
{
|
||
|
if (FireRobotSkillPanelController.Instance.SelectRobot == gameObject)
|
||
|
{
|
||
|
FireRobotSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = hasWaterConnect;
|
||
|
FireRobotSkillPanelController.Instance.SprayFroth.GetComponent<Toggle>().interactable = hasFoamConnect;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Resert();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
// Update is called once per frame
|
||
|
void Update()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
public void AddEquip()
|
||
|
{
|
||
|
all = bagdata.EquipData;
|
||
|
if (bagdata.HasEquip("消防高压水带"))
|
||
|
{
|
||
|
for (int i = 0; i < all.Count; i++)
|
||
|
{
|
||
|
if (all[i].ID == WaterHoseID)
|
||
|
{
|
||
|
NowRemainWaterHose = all[i].Number;
|
||
|
// AllEquipNum = all[i].Number;
|
||
|
WaterHoseLenghtRemain = NowRemainWaterHose * OneDefaultHoseLenght;
|
||
|
GetComponent<FireRobotLayWaterHose>().remainlenght= NowRemainWaterHose * OneDefaultHoseLenght;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
NowRemainWaterHose = 0;
|
||
|
GetComponent<FireRobotLayWaterHose>().remainlenght = NowRemainWaterHose * OneDefaultHoseLenght;
|
||
|
// AllEquipNum = 0;
|
||
|
WaterHoseLenghtRemain = NowRemainWaterHose * OneDefaultHoseLenght;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public void FireRobotPickUpLayHose(int use)
|
||
|
{
|
||
|
|
||
|
//Equip hose = EquipManager.Instance.GetEquipByID("82");
|
||
|
// hose.Number += +use;
|
||
|
GetComponent<Bags>().AddEquip("82",use);
|
||
|
NowRemainWaterHose = bagdata.GetEquip("消防高压水带").Number;
|
||
|
|
||
|
// NowRemainWaterHose = AllEquipNum;
|
||
|
WaterHoseLenghtRemain = NowRemainWaterHose * OneDefaultHoseLenght;
|
||
|
}
|
||
|
//继续上次水带铺设前计算可用管线,这里不做管线同步,因为铺设管线的同步是调用的StartLay(),所以各个客户端可能回来发
|
||
|
public void CalculateBeforelay(float remain, int usenum)
|
||
|
{
|
||
|
Equip hose = EquipManager.Instance.GetEquipByID(WaterHoseID);
|
||
|
hose.Number = usenum;
|
||
|
bagdata.AddEquip(hose);
|
||
|
NowRemainWaterHose = bagdata.GetEquip("消防高压水带").Number;
|
||
|
WaterHoseLenghtRemain = NowRemainWaterHose * OneDefaultHoseLenght + remain;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 结束水带铺设时更新剩余水带信息,铺设管线消耗,这里不做管线同步,因为铺设管线的同步是调用的EndtLay(),所以各个客户端可能回来发
|
||
|
/// </summary>
|
||
|
/// <param name="ExpendHoseNum">本次铺设的水带的长度</param>
|
||
|
//public void UpdateRemain(int expendnum)
|
||
|
//{
|
||
|
// if (bagdata.HasEquip("消防高压水带"))
|
||
|
// {
|
||
|
// NowRemainWaterHose = bagdata.GetEquip("消防高压水带").Number;
|
||
|
// }
|
||
|
// if (NowRemainWaterHose>0)
|
||
|
// {
|
||
|
// GetComponent<Bags>().UseEquip("消防高压水带", NowRemainWaterHose);
|
||
|
// }
|
||
|
// //NowRemainWaterHose -= Mathf.CeilToInt(expendlenght / 20);
|
||
|
|
||
|
// Equip hose = EquipManager.Instance.GetEquipByID(WaterHoseID);
|
||
|
// hose.Number = AllEquipNum - expendnum;
|
||
|
// bagdata.AddEquip(hose);
|
||
|
// if (bagdata.HasEquip("消防高压水带"))
|
||
|
// {
|
||
|
// NowRemainWaterHose = bagdata.GetEquip("消防高压水带").Number;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// NowRemainWaterHose = 0;
|
||
|
// }
|
||
|
// // WaterHoseLenghtRemain =AllEquipNum * OneDefaultHoseLenght-expendlenght; //+ OverLenght;
|
||
|
|
||
|
|
||
|
//}
|
||
|
|
||
|
public void ResetWaterSourceConnectInfo(bool connectsource, bool water, bool foam, GameObject watersource, GameObject connecthose)
|
||
|
{
|
||
|
IsConnentWaterSource = connectsource;
|
||
|
hasWaterConnect = water;
|
||
|
hasFoamConnect = foam;
|
||
|
ConnentSource = watersource;
|
||
|
WaterLineConnent = connecthose;
|
||
|
IsConnentWaterLine = false;
|
||
|
if (connecthose != null)
|
||
|
{
|
||
|
IsConnentWaterLine = true;
|
||
|
}
|
||
|
if (watersource==null)
|
||
|
{//如果水源信息为空,如果正在出水,停止出水
|
||
|
if(GetComponentInChildren<ParticleControlOfType>())
|
||
|
{
|
||
|
GetComponent<FireRobotController>().DestoryPartical();
|
||
|
}
|
||
|
}
|
||
|
if (FireRobotSkillPanelController.Instance)
|
||
|
{
|
||
|
if (FireRobotSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable)
|
||
|
{
|
||
|
FireRobotSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = false;
|
||
|
}
|
||
|
if (FireRobotSkillPanelController.Instance.SprayFroth.GetComponent<Toggle>().interactable)
|
||
|
{
|
||
|
FireRobotSkillPanelController.Instance.SprayFroth.GetComponent<Toggle>().interactable = false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
public void Resert()
|
||
|
{
|
||
|
IsConnentWaterLine = false;
|
||
|
WaterLineConnent = null;
|
||
|
IsConnentWaterSource = false;
|
||
|
ConnentSource = null;
|
||
|
hasFoamConnect = false;
|
||
|
hasWaterConnect = false;
|
||
|
WaterSourceLine = new List<List<long>>();
|
||
|
if (!GetComponent<AgentController>().pathFindEnable)
|
||
|
{
|
||
|
GetComponent<AgentController>().pathFindEnable = true;
|
||
|
}
|
||
|
if (FireRobotSkillPanelController.Instance)
|
||
|
{
|
||
|
FireRobotSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().isOn = false;
|
||
|
FireRobotSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = false;
|
||
|
}
|
||
|
if (GetComponent<FireRobotController>())
|
||
|
{
|
||
|
if (GetComponent<FireRobotController>().WorkType == FireRobotSkill.出水 ||
|
||
|
GetComponent<FireRobotController>().WorkType == FireRobotSkill.出泡沫)
|
||
|
{
|
||
|
//停止出水
|
||
|
GetComponent<FireRobotController>().DestoryPartical();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|