网上演练贵港万达广场(人员密集)
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.
 
 
 

1040 lines
43 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using AX.MessageSystem;
using AX.InputSystem;
using UnityEngine.UI;
public class LayWaterHose : MonoBehaviour
{
private string parentName;
public GameObject WaterHoses;
private string bandtype = "OrdinaryHose";
// public GameObject waterhose;
private int num = 1;
private Dictionary<int, GameObject> hoseDic = new Dictionary<int, GameObject>();
private Dictionary<int, float> lengthDic = new Dictionary<int, float>();
private NavMeshAgent agent;
private bool flag = false;
private List<Vector3> allInits = new List<Vector3>();
private Vector3[] path = null;
private Dictionary<int, Vector3[]> pathCorners = new Dictionary<int, Vector3[]>();
private float time = 0;
//private FireManMessage fireManMessage;
private NavMeshPath NavMeshPath;
private Vector3 InitPoint;
private Vector3 endPoint; //记录水带用完的点
private Vector3 checkPoint;
private int pathIndex = 0;
private Dictionary<int, List<int>> pathMap = new Dictionary<int, List<int>>(); //第几次路线包含哪几段
private Transform shuiqiang;
private bool spraying = false;
//private List<MyEquipObject> equips; //保存消防员所有的装备
// private MyEquipObject equipedHoses; //保存消防员装备的水带
private GameObject group;
private List<GameObject> groupMembers;
private bool canreinit = true;
private int groupEquipedNum = 0; //保存组内一共装备的盘数
private int groupConsumedNum = 0; //保存组内一共消耗的盘数
private int selfEquipedNum = 0; //保存个人携带的盘数
private int selfConsumedNum = 0; //保存个人消耗的盘数
// public float LayLenght;//本次铺设长度
public float remainlenght;//该消防员剩余水带
public GameObject ParentLayHosePrefabs;
/// <summary>
///铺设水带的父物体
/// </summary>
public GameObject ParentLayHose;
/// <summary>
/// 是否是捡起来继续铺
/// </summary>
public bool IsTackUp;
/// <summary>
/// 捡起的水带
/// </summary>
public GameObject TackHose;
/// <summary>
/// 如果是本客户端
/// </summary>
public bool IsselfCurrent = true;
private int creatnum = 1;
// private bool setInitpoint;
// public float LastLenght;
//private float LastLayLenght;
private NavMeshQueryFilter filter;
// Use this for initialization
void Start()
{
NavMeshPath = new NavMeshPath();
agent = GetComponent<NavMeshAgent>();
//fireManMessage = GetComponent<FireManMessage>();
shuiqiang = TransformHelper.FindChild(transform, "shuiqiang");
//生成所有水带的父物体
parentName = name;//GetComponent<BaseGameObjInfo>().gameObjID.ToString();
GameObject AllParent = GameObject.Find("P_AllParent/P_FireSkill/P_FollowFireHose");
if (!AllParent.transform.Find(parentName))
{
WaterHoses = Instantiate(Resources.Load<GameObject>("Lines/WaterHoses"));
WaterHoses.transform.parent = AllParent.transform;
WaterHoses.name = parentName;
}
else
{
WaterHoses = AllParent.transform.Find(parentName).gameObject;
}
if (ParentLayHosePrefabs == null)
{
ParentLayHosePrefabs = Resources.Load<GameObject>("LineParent/ParentLayWaterHose");
}
filter = new NavMeshQueryFilter();
filter.agentTypeID = agent.agentTypeID;
filter.areaMask = agent.areaMask;
}
/// <summary>
/// 获取组内总装备数,没有组就获取自己的装备数
/// </summary>
private int GetEquipedNum()
{
selfEquipedNum = GetComponent<FireManWaterHoseManager>().NowRemainWaterHose;
return selfEquipedNum;
}
/// <summary>
/// 获取组内已被占用的水带盘数,如果没有组就获取自己占用的盘数
/// </summary>
/// <returns>自己或所在组占用的水带盘数</returns>
private int GetConsumedNum()
{
selfConsumedNum = GetSelfConsumedNum();
// if (UpdateEquipedHoses())
{
//equipedHoses.conNum = selfConsumedNum; //设置自己背包中水带的消耗量
}
return selfConsumedNum;
}
/// <summary>
/// 获取自己还可以铺设的长度
/// </summary>
/// <returns>自己或所在组剩余的水带长度</returns>
private float GetRestAvailableLength()
{
// GetConsumedNum(); //更新自己的消耗数
return GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain;//GetEquipedNum() * 20 - GetSelfConsumedLength();
}
/// <summary>
/// 获取自己铺设水带的长度, lengthDic.Clear()清空后该长度会清0
/// </summary>
/// <returns></returns>
private float GetSelfConsumedLength()
{
float length = 0;
if (lengthDic.Count > 0)
{
foreach (float l in lengthDic.Values)
{
length += l;
}
}
return length;
}
/// <summary>
/// 获取自己消耗的盘数
/// </summary>
/// <returns></returns>
public int GetSelfConsumedNum()
{
float consumedlength = GetSelfConsumedLength();
int consumednum = (int)(consumedlength / 20);
if (consumedlength % 20 > 0)
{
consumednum += 1;
}
return consumednum;
}
// Update is called once per frame
void Update()
{
if (!flag)
{
return;
}
//Debug.Log(flag+"//"+ agent.velocity.magnitude );
if (flag && agent.velocity.magnitude > 0) //开启“铺设水带”,并且开始寻路时才会执行
{
remainlenght = GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain;
if (remainlenght<=0)
{
return;
}
endPoint = transform.position;
//LayLenght= GetSelfConsumedLength();
if (remainlenght > 0 && remainlenght <= 0.5f) //临界带
{
agent.SetDestination(transform.position);
endPoint = transform.position;
if (IsselfCurrent)
{
LoadPromptWin.Instance.LoadTextPromptWindow("水带用完", 1f);
}
}
DrawByTimespan();//按更新的铺设路线画一次水带
}
if (flag)
{
if (spraying) //&& agent.velocity.magnitude==0)
{
DrawTail();
}
else
{
DestroyTail();
}
}
}
/// <summary>
/// 画线方法
/// </summary>
/// <param name="position1">画线起始位置</param>
/// <param name="position2">画线结束位置</param>
/// <param name="number">线的名称序号</param>
private void DrawHoseLine(Vector3 position1, Vector3 position2, int number)
{
Vector3 midPosition = (position1 + position2) / 2;
midPosition = new Vector3(midPosition.x, midPosition.y + 0.1f, midPosition.z);
string linename = "waterhose-" + number;
GameObject hose;
if (!ParentLayHose.transform.Find(linename))
{
hose = Instantiate(Resources.Load<GameObject>("Lines/" + bandtype), midPosition, Quaternion.identity) as GameObject;
hose.name = linename;
}
else
{
hose = ParentLayHose.transform.Find(linename).gameObject;
hose.transform.position = midPosition;
}
hose.transform.parent = ParentLayHose.transform;
hose.transform.forward = (position2 - position1).normalized;//改变朝向
if (!hose.GetComponent<BoxCollider>())
{
hose.AddComponent<BoxCollider>();
}
float distance = Vector3.Distance(position2, position1);
hose.transform.localScale = new Vector3(25, 25, distance * 107);//延长线条,连接两点
// hose.transform.position = hose.transform.position + Vector3.up * 0.5f;
SetHoseFloorInfo(hose.transform.parent.gameObject, position2);
UpdateHoseDic(number, hose);
UpdateLength(position1, position2, number);
List<int> intlist = pathMap[pathIndex];
if (!intlist.Contains(number))
{
pathMap[pathIndex].Add(number); //第pathIndex条路线包括水带段number
}
}
/// <summary>
/// 更新已用水带的长度
/// </summary>
/// <param name="position1"></param>
/// <param name="position2"></param>
/// <param name="number"></param>
private void UpdateLength(Vector3 position1, Vector3 position2, int number)
{
if (lengthDic.ContainsKey(number)) //如果字典里已包含此序号段水带的长度
{
lengthDic[number] = Vector3.Distance(position1, position2);//就更新长度
}
else //如果不包含此序号段水带的长度
{
lengthDic.Add(number, Vector3.Distance(position1, position2));//就添加长度
}
}
/// <summary>
/// 更新消防员装备的水带物体
/// </summary>
//private bool UpdateEquipedHoses()
//{
// equips = GetComponent<Bag>().equips;
// if (equips.Count > 0)
// {
// foreach (MyEquipObject equip in equips)
// {
// if (equip.equipName == "消防高压水带")
// {
// equipedHoses = equip;
// return true;
// }
// }
// return false;
// }
// return false;
//}
/// <summary>
/// 保存新生成的水带段
/// </summary>
/// <param name="number"></param>
/// <param name="hose"></param>
private void UpdateHoseDic(int number, GameObject hose)
{
if (hoseDic.ContainsKey(number))
{
hoseDic[number] = hose;
}
else
{
hoseDic.Add(number, hose);
}
}
/// <summary>
/// 检测水带是否还有剩余
/// </summary>
/// <returns></returns>
private void HasHose()
{
float remain = GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain;
if (remain > 0.5f)
{
endPoint = transform.position; //记录末点位置
canreinit = true; //可以更新InitPoint
return;
}
else if (remain > 0 && remain <= 0.5f) //临界带
{
canreinit = false;
if (IsselfCurrent)
{
LoadPromptWin.Instance.LoadTextPromptWindow("水带用完", 1f);
}
return;
}
/* else
{
if(agent.velocity.magnitude > 0)
{
ResourceLoadWindow.Instance.LoadTextHintWindow("已无可用水带", 1);
}
transform.position = endPoint;
agent.SetDestination(endPoint);
canreinit = false; //即时超过20也不更新InitPoint
return;
}*/
}
/// <summary>
/// 开始铺设水带
/// </summary>
public void StartLay(bool issync = false)
{
agent.SetDestination(transform.position);
//if (GetComponent<FireManWaterHoseManager>().OverLenght > 0)
//{
// GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain =
// GetComponent<FireManWaterHoseManager>().NowRemainWaterHose * 20 + GetComponent<FireManWaterHoseManager>().OverLenght;
//}
//如果当前起始位置与上一次铺设的末点距离较近,则认为此次铺设是上一次铺设的继续
if (endPoint != Vector3.zero && Vector3.Distance(transform.position, endPoint) < 5)
{
if (ParentLayHose)
{
//如果放下期间已经被别人捡起,重新铺设
if (ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFireman != null)
{
lengthDic.Clear();
if (GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain <= 0)
{
if (IsselfCurrent)
{
LoadPromptWin.Instance.LoadTextPromptWindow("未装备水带或水带已用完", 1f);
}
return;
}
//ParentLayHose = EntitiesManager.Instance.CreateObj(ParentLayHosePrefabs, Vector3.zero,
// WaterHoses.transform, EntitiesManager.Instance.CreateObjID(CurrentUserInfo.mySelf.Id)); // Instantiate(ParentLayHosePrefabs, WaterHoses.transform);
ParentLayHose = Instantiate(ParentLayHosePrefabs, WaterHoses.transform);
//ParentLayHose.GetComponent<BaseGameObjInfo>().gameObjID = EntitiesManager.Instance.CreateObjID(CurrentUserInfo.mySelf.Id);
ParentLayHose.name = "LayWaterHose" + creatnum;
creatnum++;
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFireman = gameObject;
allInits.Clear();
AddInit();
endPoint = transform.position;
if (!GetComponent<AgentController>().pathFindEnable)
{
GetComponent<AgentController>().pathFindEnable = true;
}
flag = true;
}
//如果放下期间没有被别人捡起,继续铺设
else
{
//if (ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().LineLenght==0)
//{//开启铺设又立马关闭,一段水带没有使用
// ParentLayHose = Instantiate(ParentLayHosePrefabs, WaterHoses.transform);
// ParentLayHose.name = "LayWaterHose" + creatnum;
// creatnum++;
// ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFireman = gameObject;
//}
//更新消防员可用水带
if (ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().RemainLenght > 0)
{
//if((GetComponent<FireManWaterHoseManager>().OverLenght==0))
{
//GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain =
// GetComponent<FireManWaterHoseManager>().NowRemainWaterHose * 20 + ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().RemainLenght+GetComponent<FireManWaterHoseManager>().OverLenght;
//GetComponent<FireManWaterHoseManager>().NowRemainWaterHose = GetComponent<FireManWaterHoseManager>().NowRemainWaterHose + ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().UseNum;
GetComponent<FireManWaterHoseManager>().CalculateBeforelay(ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().RemainLenght, ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().UseNum);
}
}
//更新消防员水源信息
if (ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().WaterSource != null)
{
if (issync == false)
{
gameObject.GetComponent<FireManWaterHoseManager>().ResetWaterSourceConnectInfo
(true, ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectWater,
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFoam, ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().WaterSource,
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectWaterHose);
if (/*FindObjectOfType<FireManSkillPanelController>()*/FireManSkillPanelController.Instance)
{
FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = true;
}
}
}
else
{
if (issync == false)
{
gameObject.GetComponent<FireManWaterHoseManager>().ResetWaterSourceConnectInfo(false, false, false, null, null);
}
}
if (!GetComponent<AgentController>().pathFindEnable)
{
GetComponent<AgentController>().pathFindEnable = true;
}
flag = true;
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFireman = gameObject;
}
//AddInit();
}
}
//如果当前起始位置与上一次铺设的末点距离较远,则认为开始一段新的铺设,不会收回上一次铺设的管线
else
{
lengthDic.Clear();
if (GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain <= 0)
{
if (IsselfCurrent)
{
LoadPromptWin.Instance.LoadTextPromptWindow("未装备水带或水带已用完", 1f);
}
//如果链接水源,不能移动
if (GetComponent<FireManWaterHoseManager>().ConnentSource!=null)
{
GetComponent<AgentController>().pathFindEnable = false;
}
allInits.Clear();
AddInit();
endPoint = Vector3.zero;
flag = false;
return;
}
else
{
ParentLayHose = Instantiate(ParentLayHosePrefabs, WaterHoses.transform);
ParentLayHose.name = "LayWaterHose" + creatnum;
creatnum++;
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFireman = gameObject;
//GetComponent<FireManWaterHoseManager>().TackUpLenght = 0;
//如果铺设时消防员被管线连接,给该水带赋值水源信息
if (GetComponent<FireManWaterHoseManager>().IsConnentWaterLine)
{
FireManWaterHoseManager thisFireman = GetComponent<FireManWaterHoseManager>();
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().BindWaterSource(thisFireman.hasWaterConnect, thisFireman.hasFoamConnect, thisFireman.ConnentSource, thisFireman.WaterLineConnent);
}
allInits.Clear();
AddInit();
endPoint = transform.position;
if (!GetComponent<AgentController>().pathFindEnable)
{
GetComponent<AgentController>().pathFindEnable = true;
}
flag = true;
}
}
}
/// <summary>
/// 有水源后,设置喷水起始点
/// </summary>
public void SetInitPoint()
{
allInits.Clear(); //与之前铺设的水带切断联系
AddInit(); //将当前位置作为起点
endPoint = Vector3.zero;//transform.position;
//setInitpoint = true;
}
/// <summary>
/// 消防员喷水、泡沫时铺设水带
/// </summary>
public void StartSprayingLay(bool issync = false)
{
agent.SetDestination(transform.position);
//if (!GetComponent<AgentController>().pathFindEnable)
{
GetComponent<AgentController>().pathFindEnable = true;
}
if (GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain <= 0)
{
if (IsselfCurrent)
{
if (!(GetComponent<FireManControl>().workType == FireManSkills.SprayFoam||
GetComponent<FireManControl>().workType == FireManSkills.SprayWater))
{
LoadPromptWin.Instance.LoadTextPromptWindow("还未装备水带", 1);
}
}
}
if (endPoint != Vector3.zero && Vector3.Distance(transform.position, endPoint) < 5)
{
if (ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().RemainLenght > 0)
{
//if((GetComponent<FireManWaterHoseManager>().OverLenght==0))
{
//GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain =
// GetComponent<FireManWaterHoseManager>().NowRemainWaterHose * 20 + ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().RemainLenght+GetComponent<FireManWaterHoseManager>().OverLenght;
//GetComponent<FireManWaterHoseManager>().NowRemainWaterHose = GetComponent<FireManWaterHoseManager>().NowRemainWaterHose + ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().UseNum;
GetComponent<FireManWaterHoseManager>().CalculateBeforelay(ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().RemainLenght, ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().UseNum);
}
}
if (ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().WaterSource != null)
{
if (issync == false)
{
gameObject.GetComponent<FireManWaterHoseManager>().ResetWaterSourceConnectInfo
(true, ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectWater,
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFoam, ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().WaterSource,
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectWaterHose);
}
if (/*FindObjectOfType<FireManSkillPanelController>()*/FireManSkillPanelController.Instance)
{
FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = true;
}
}
else
{
if (issync == false)
{
gameObject.GetComponent<FireManWaterHoseManager>().ResetWaterSourceConnectInfo(false, false, false, null, null);
}
}
//GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain =
// GetComponent<FireManWaterHoseManager>().NowRemainWaterHose * 20 + ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().RemainLenght;//+ GetComponent<FireManWaterHoseManager>().OverLenght;
// GetComponent<FireManWaterHoseManager>().NowRemainWaterHose = GetComponent<FireManWaterHoseManager>().NowRemainWaterHose + ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().UseNum;
GetComponent<FireManWaterHoseManager>().CalculateBeforelay(ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().RemainLenght, ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().UseNum);
flag = true;
GetComponent<AgentController>().pathFindEnable = true;
}
else
{
ParentLayHose = Instantiate(ParentLayHosePrefabs, WaterHoses.transform);
ParentLayHose.name = "LayWaterHose" + creatnum;
creatnum++;
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFireman = gameObject;
allInits.Clear(); //与之前铺设的水带切断联系
AddInit(); //将当前位置作为起点
endPoint = transform.position;
lengthDic.Clear();
remainlenght = GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain;
if (remainlenght <= 0)
{
GetComponent<AgentController>().pathFindEnable = false;
}
else
{
GetComponent<AgentController>().pathFindEnable = true;
}
}
// GetComponent<AgentController>().pathFindEnable = true;
canreinit = false;
flag = true;
spraying = true;
}
/// <summary>
/// 结束铺设,放下水带
/// </summary>
public void EndLay(bool issync = false, bool isstoplayskill = true)
{
//endlay();
if (flag)
{
flag = false;
agent.SetDestination(transform.position); //停止移动
SetLayHoseInfo(issync,isstoplayskill);
//lengthDic.Clear();//清空本次绘制存储的线
//IsTackUp = false;
//TackHose = null;
}
if (spraying)
{
spraying = false;
DestroyTail();
}
// Debug.Log(endPoint+"//"+transform.position);
}
/// <summary>
/// 结束铺设时设置该铺设管线信息
/// </summary>
void SetLayHoseInfo(bool issync = false,bool isstoplayskill=true)
{
// LastLenght = GetSelfConsumedLength() - ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().LineLenght;
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().LineLenght = GetSelfConsumedLength();
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().UseNum = Mathf.CeilToInt(GetSelfConsumedLength() / 20);
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().CreatFireman = gameObject;
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().RemainLenght = Mathf.CeilToInt(GetSelfConsumedLength() / 20) * 20 - GetSelfConsumedLength();
GetComponent<FireManWaterHoseManager>().UpdateRemain(GetSelfConsumedLength());
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectWaterHose = GetComponent<FireManWaterHoseManager>().WaterLineConnent;
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().EndPoint = transform.position;
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFireman = null;
//如果结束铺设时消防员被管线连接,更新水带水源信息,防止在铺设过程中消防员连接的管线被删除,造成的信息更改
if (GetComponent<FireManWaterHoseManager>().IsConnentWaterSource)
{
FireManWaterHoseManager thisFireman = GetComponent<FireManWaterHoseManager>();
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().BindWaterSource(thisFireman.hasWaterConnect, thisFireman.hasFoamConnect, thisFireman.ConnentSource, thisFireman.WaterLineConnent);
}
else
{
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().BindWaterSource(false, false, null, null);
}
if (GetComponent<FireManControl>().workType == FireManSkills.SprayFoam ||
GetComponent<FireManControl>().workType == FireManSkills.SprayWater)
{
GetComponent<AgentController>().pathFindEnable = false;
remainlenght = GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain;
if (remainlenght <= 0&& GetSelfConsumedLength()<1f)
{
allInits.Clear(); //与之前铺设的水带切断联系
AddInit(); //将当前位置作为起点
endPoint = Vector3.zero;
lengthDic.Clear();
}
}
// StartCoroutine(closespraytoggle());
//if (!(endPoint != Vector3.zero && Vector3.Distance(transform.position, endPoint) < 5))
//{
// if (FireManSkillPanelController.Instance)
// {
// FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().isOn = false;
// FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = false;
// }
//}
if (issync==false)
{
GetComponent<FireManWaterHoseManager>().Resert();
}
}
IEnumerator closespraytoggle()
{
Debug.Log("closespraytoggle----"+false);
yield return new WaitForSeconds(0.2f);
if (GetComponent<FireManControl>().WorkType!=FireManSkills.SprayFoam&&
GetComponent<FireManControl>().WorkType != FireManSkills.SprayWater ||
!FireManSkillPanelController.Instance.extinguishantSelect.gameObject.activeSelf)
{
//if (FireManSkillPanelController.Instance)
{
FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().isOn = false;
FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = false;
}
}
}
/// <summary>
/// 收起水带
/// </summary>
public void Pack()
{
foreach (GameObject hose in hoseDic.Values)
{
Destroy(hose);//删除所有已生成的水带段
}
hoseDic.Clear(); //水带段字典清空
lengthDic.Clear(); //已用水带长度清空
pathMap.Clear();
num = 1;
path = null;
pathIndex = 0;
flag = false;
spraying = false;
InitPoint = default(Vector3);
endPoint = default(Vector3);
checkPoint = default(Vector3);
canreinit = true;
//if (equipedHoses != null)
{
//equipedHoses.conNum = 0;
}
allInits.Clear();
pathCorners.Clear();
GetConsumedNum();
DestroyTail();
}
public void DeleteParent()
{
if (WaterHoses)
{
Destroy(WaterHoses);
}
}
/// <summary>
/// 从起始点到角色当前位置获取铺设路线
/// </summary>
private void GetPath()
{
NavMesh.CalculatePath(InitPoint, transform.position, filter, NavMeshPath);
path = NavMeshPath.corners;
//path = CheckPath(path);
if (pathCorners.ContainsKey(pathIndex))
{
pathCorners[pathIndex] = path;
}
else
{
pathCorners.Add(pathIndex, path);
}
List<int> intList = pathMap[pathIndex];
num = intList[0];
int endnum = intList[intList.Count - 1];
if (lengthDic.Count > 0 && hoseDic.Count > 0) //删除第pathIndex段水带上一次生成的所有子段
{
for (int i = num; i <= endnum; i++)
{
lengthDic.Remove(i);
}
}
float thispartlength = 0; //记录此次路线生成水带的长度,如果超出20,就更新InitPoint
if (path.Length > 1)
{
for (int i = 1; i < path.Length; i++)
{
DrawHoseLine(path[i - 1], path[i], num);
thispartlength += lengthDic[num];
num += 1;
}
}
if (num - 1 < hoseDic.Count) //删除多余的水带段
{
for (int i = hoseDic.Count; i > num - 1; i--)
{
if (hoseDic.ContainsKey(i))
{
Destroy(hoseDic[i]);
hoseDic.Remove(i);
}
}
}
//此次路线生成水带的长度如果超出20,或者就更新InitPoint
//if (GetComponent<FireManWaterHoseManager>().OverLenght == 0)
{
if (canreinit && path.Length > 1 && Vector3.Distance(transform.position, path[path.Length - 2]) > 0.5f && (thispartlength > 20))
{
AddInit();
}
}
//if (GetComponent<FireManWaterHoseManager>().OverLenght > 0)
//{
// if (canreinit && path.Length > 1 && Vector3.Distance(transform.position, path[path.Length - 2]) > 0.5f && (thispartlength > GetComponent<FireManWaterHoseManager>().OverLenght))
// {
// AddInit();
// }
//}
}
/// <summary>
/// 每帧更新铺设路线
/// </summary>
private void DrawByTimespan()
{
GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain = GetComponent<FireManWaterHoseManager>().NowRemainWaterHose * 20 - GetSelfConsumedLength();// + GetComponent<FireManWaterHoseManager>().OverLenght;
if (GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain > 0) //如果装备了水带,并且有水带可用
{
HasHose();
GetBackCheck();
GetPath();
}
//else if (GetEquipedNum() > 0 && GetRestAvailableLength() <= 0) //装备了水带,但无水带可用,别人都用完了
//{
// transform.position = endPoint;
// if (agent.destination != transform.position)
// {
// //ResourceLoadWindow.Instance.LoadTextHintWindow("已无可用水带", 1);
// agent.SetDestination(endPoint);
// }
// canreinit = false; //即时超过20也不更新InitPoint
// GetBackCheck();
// GetPath();
//}
else //没装备就原地不动
{
transform.position = endPoint;
if (agent.destination != transform.position)
{
//ResourceLoadWindow.Instance.LoadTextHintWindow("已无可用水带", 1);
agent.SetDestination(endPoint);
}
canreinit = false; //即时超过20也不更新InitPoint
GetBackCheck();
GetPath();
}
// GetComponent<FireManWaterHoseManager>().WaterHoseLenghtRemain-=GetConsumedNum();
}
/// <summary>
/// 喷水、喷泡沫时创建水带末端到消防员手上水枪部位的连接段
/// </summary>
private void DrawTail()
{
Vector3 midPosition = (transform.position + shuiqiang.position) / 2;
midPosition = new Vector3(midPosition.x, midPosition.y + 0.1f, midPosition.z);
string linename = "waterhose-tail";
GameObject hose;
if (!WaterHoses.transform.Find(linename))
{
hose = Instantiate(Resources.Load<GameObject>("Lines/" + bandtype), midPosition, Quaternion.identity) as GameObject;
hose.name = linename;
}
else
{
hose = WaterHoses.transform.Find(linename).gameObject;
hose.transform.position = midPosition;
}
hose.transform.parent = WaterHoses.transform;
hose.transform.forward = (shuiqiang.position - transform.position).normalized;//改变朝向
float distance = Vector3.Distance(transform.position, shuiqiang.position);
hose.transform.localScale = new Vector3(25,25, distance * 78);//延长线条,连接两点
}
/// <summary>
/// 不喷水、泡沫时删除水带末端到消防员手上水枪部位的连接段
/// </summary>
private void DestroyTail()
{
if (WaterHoses.transform.Find("waterhose-tail"))
{
Destroy(WaterHoses.transform.Find("waterhose-tail").gameObject);
}
}
/// <summary>
/// 根据组内已用盘数设置组员水带设备的已消耗数量
/// </summary>
/// <param name="consumedlength">组内已经消耗的水带长度</param>
//private void SetGroupConsumed(int groupconsumednum)
//{
// for (int i = 0; i < groupMembers.Count; i++) //查找每一个组员的背包
// {
// List<MyEquipObject> memberEquips = groupMembers[i].GetComponent<Bag>().equips; //获取该组员背包里的装备
// if (memberEquips != null && memberEquips.Count > 0)
// {
// foreach (MyEquipObject equip in memberEquips)
// {
// if (equip.equipName == "消防高压水带" && equip.selNum > 0) //找到装备中的水带装备
// {
// if (groupconsumednum > 0) //如果消耗量还没设置完,就继续在该组员身上设置消耗量
// {
// if (groupconsumednum > equip.selNum) //总消耗量 > 该组员携带量
// {
// equip.conNum = equip.selNum; //该组员的携带量全用完
// groupconsumednum -= equip.selNum;
// }
// else //consumednum <= equip.selNum //总消耗量 <= 该组员携带量
// {
// equip.conNum = groupconsumednum; //设置该组员消耗量为总消耗量
// groupconsumednum = 0; //总共消耗量为0
// }
// }
// else if (groupconsumednum == 0) //如果消耗量已经全部设置完
// {
// equip.conNum = 0; //则该组员的水带装备消耗量为0
// }
// break; //不用再翻该组员的背包了,直接跳回for循环开始查找下一个组员的背包
// }
// }
// }
// }
//}
private void GetBackCheck()
{
if (allInits.Count > 1)
{
int i = allInits.Count - 1;
if (pathCorners.ContainsKey(pathIndex - 1))
{
Vector3[] lastPath = pathCorners[pathIndex - 1];
if (lastPath.Length > 1)
{
checkPoint = lastPath[lastPath.Length - 2]; //上一段路线的倒数第二点
float dc1 = Vector3.Distance(checkPoint, allInits[i]);
float dcp = Vector3.Distance(checkPoint, transform.position);
Vector3 _ic = checkPoint - allInits[i];
Vector3 _ip = transform.position - allInits[i];
float angle = Vector3.Angle(_ic, _ip);
if (angle < 15 || dcp < dc1)
{
//删除最后一个InitPoint为起点画的线,即第pathIndex段水带
List<int> intlist = pathMap[pathIndex];
foreach (int k in intlist)
{
if (hoseDic.ContainsKey(k))
{
Destroy(hoseDic[k]);
hoseDic.Remove(k);
}
lengthDic.Remove(k);
}
pathMap.Remove(pathIndex);
pathCorners.Remove(pathIndex);
pathIndex -= 1;
InitPoint = allInits[i - 1]; //InitPoint退回上一个点
allInits.RemoveAt(i); //删除最后一个InitPoint
canreinit = false;
}
}
}
}
}
private void AddInit()
{
InitPoint = transform.position;
allInits.Add(InitPoint);
pathIndex += 1;
pathMap.Add(pathIndex, new List<int> { num });
}
private Vector3[] CheckPath(Vector3[] path)
{
List<Vector3> corners = new List<Vector3>();
foreach (Vector3 point in path)
{
corners.Add(point);
}
for (int i = 0; i < corners.Count - 1; i++)
{
for (int k = corners.Count - 2; k > i; k--)
{
float distance = Vector3.Distance(corners[i], corners[k]);//计算两点的距离
if (distance < 0.3f)
{
for (int j = k; j > i; j--)
{
corners.RemoveAt(j);
}
break;
}
}
}
Vector3[] newpath = new Vector3[corners.Count];
for (int j = 0; j < newpath.Length; j++)
{
newpath[j] = corners[j];
}
return newpath;
}
/// <summary>
/// 获取自己手中持有的水带数量,包括已铺设的数量和携带的未消耗的数量
/// </summary>
/// <returns></returns>
public int SelfGotNum()
{
int selfallnum = 0;
//if (UpdateEquipedHoses())
{
//selfallnum += equipedHoses.selNum - equipedHoses.conNum; //计算自己携带的剩余可用的数量
}
selfallnum += GetSelfConsumedNum(); //加上自己已铺设的数量
return selfallnum; //自己手中一共拥有的数量,解组时重新设定自己的selNum
}
/// <summary>
/// 根据管线所在位置设定管线的层信息
/// </summary>
/// <param name="hose"></param>
public void SetHoseFloorInfo(GameObject hose, Vector3 pos2)
{
Vector3 adPos2 = new Vector3(pos2.x, pos2.y + 0.2f, pos2.z);
Ray ray = new Ray(adPos2, -Vector3.up);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast(ray, out hit, LayerMask.NameToLayer("PathFinding")))
{
if (hit.transform.gameObject.GetComponent<CloneGameObjInfo>() && hit.transform.gameObject.GetComponent<CloneGameObjInfo>().gameObjType == CloneObjType.staticGameObject)
{
CloneGameObjInfo hoseinfo = hose.GetComponent<CloneGameObjInfo>();
CloneGameObjInfo hitinfo = hit.transform.gameObject.GetComponent<CloneGameObjInfo>();
hoseinfo.buildNum = hitinfo.buildNum;
hoseinfo.floorNum = hitinfo.floorNum;
hoseinfo.interlayerNum = hitinfo.interlayerNum;
//hoseinfo.UpdateFloorEnabled(GlobalVariable.CurrentFloor);
return;
}
}
}
public void ResertEndPoint()
{
endPoint = Vector3.zero;
}
public void SetWaterInfoWhileSpray()
{
if (ParentLayHose!=null&& ParentLayHose.GetComponent<ParentLayWaterHoseMsg>()!=null)
{
if (ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().WaterSource != null)
{
if ((endPoint != Vector3.zero && Vector3.Distance(transform.position, endPoint) < 5))
{
gameObject.GetComponent<FireManWaterHoseManager>().ResetWaterSourceConnectInfo
(true, ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectWater,
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectFoam, ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().WaterSource,
ParentLayHose.GetComponent<ParentLayWaterHoseMsg>().ConnectWaterHose);
if (/*FindObjectOfType<FireManSkillPanelController>()*/FireManSkillPanelController.Instance)
{
FireManSkillPanelController.Instance.SprayWater.GetComponent<Toggle>().interactable = true;
DrawByTimespan();
}
}
else
{
// LoadPromptWin.Instance.LoadTextPromptWindow("距离放下水带太远,无法自动拿起管线,请靠近当前放下管线或者重新连接水源", 1f);
}
}
}
}
}