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 hoseDic = new Dictionary(); private Dictionary lengthDic = new Dictionary(); private NavMeshAgent agent; private bool flag = false; private List allInits = new List(); private Vector3[] path = null; private Dictionary pathCorners = new Dictionary(); 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> pathMap = new Dictionary>(); //第几次路线包含哪几段 private Transform shuiqiang; private bool spraying = false; //private List equips; //保存消防员所有的装备 // private MyEquipObject equipedHoses; //保存消防员装备的水带 private GameObject group; private List 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; /// ///铺设水带的父物体 /// public GameObject ParentLayHose; /// /// 是否是捡起来继续铺 /// public bool IsTackUp; /// /// 捡起的水带 /// public GameObject TackHose; /// /// 如果是本客户端 /// 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(); //fireManMessage = GetComponent(); shuiqiang = TransformHelper.FindChild(transform, "shuiqiang"); //生成所有水带的父物体 parentName = name;//GetComponent().gameObjID.ToString(); GameObject AllParent = GameObject.Find("P_AllParent/P_FireSkill/P_FollowFireHose"); if (!AllParent.transform.Find(parentName)) { WaterHoses = Instantiate(Resources.Load("Lines/WaterHoses")); WaterHoses.transform.parent = AllParent.transform; WaterHoses.name = parentName; } else { WaterHoses = AllParent.transform.Find(parentName).gameObject; } if (ParentLayHosePrefabs == null) { ParentLayHosePrefabs = Resources.Load("LineParent/ParentLayWaterHose"); } filter = new NavMeshQueryFilter(); filter.agentTypeID = agent.agentTypeID; filter.areaMask = agent.areaMask; } /// /// 获取组内总装备数,没有组就获取自己的装备数 /// private int GetEquipedNum() { selfEquipedNum = GetComponent().NowRemainWaterHose; return selfEquipedNum; } /// /// 获取组内已被占用的水带盘数,如果没有组就获取自己占用的盘数 /// /// 自己或所在组占用的水带盘数 private int GetConsumedNum() { selfConsumedNum = GetSelfConsumedNum(); // if (UpdateEquipedHoses()) { //equipedHoses.conNum = selfConsumedNum; //设置自己背包中水带的消耗量 } return selfConsumedNum; } /// /// 获取自己还可以铺设的长度 /// /// 自己或所在组剩余的水带长度 private float GetRestAvailableLength() { // GetConsumedNum(); //更新自己的消耗数 return GetComponent().WaterHoseLenghtRemain;//GetEquipedNum() * 20 - GetSelfConsumedLength(); } /// /// 获取自己铺设水带的长度, lengthDic.Clear()清空后该长度会清0 /// /// private float GetSelfConsumedLength() { float length = 0; if (lengthDic.Count > 0) { foreach (float l in lengthDic.Values) { length += l; } } return length; } /// /// 获取自己消耗的盘数 /// /// 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().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(); } } } /// /// 画线方法 /// /// 画线起始位置 /// 画线结束位置 /// 线的名称序号 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("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()) { hose.AddComponent(); } 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 intlist = pathMap[pathIndex]; if (!intlist.Contains(number)) { pathMap[pathIndex].Add(number); //第pathIndex条路线包括水带段number } } /// /// 更新已用水带的长度 /// /// /// /// 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));//就添加长度 } } /// /// 更新消防员装备的水带物体 /// //private bool UpdateEquipedHoses() //{ // equips = GetComponent().equips; // if (equips.Count > 0) // { // foreach (MyEquipObject equip in equips) // { // if (equip.equipName == "消防高压水带") // { // equipedHoses = equip; // return true; // } // } // return false; // } // return false; //} /// /// 保存新生成的水带段 /// /// /// private void UpdateHoseDic(int number, GameObject hose) { if (hoseDic.ContainsKey(number)) { hoseDic[number] = hose; } else { hoseDic.Add(number, hose); } } /// /// 检测水带是否还有剩余 /// /// private void HasHose() { float remain = GetComponent().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; }*/ } /// /// 开始铺设水带 /// public void StartLay(bool issync = false) { agent.SetDestination(transform.position); //if (GetComponent().OverLenght > 0) //{ // GetComponent().WaterHoseLenghtRemain = // GetComponent().NowRemainWaterHose * 20 + GetComponent().OverLenght; //} //如果当前起始位置与上一次铺设的末点距离较近,则认为此次铺设是上一次铺设的继续 if (endPoint != Vector3.zero && Vector3.Distance(transform.position, endPoint) < 5) { if (ParentLayHose) { //如果放下期间已经被别人捡起,重新铺设 if (ParentLayHose.GetComponent().ConnectFireman != null) { lengthDic.Clear(); if (GetComponent().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().gameObjID = EntitiesManager.Instance.CreateObjID(CurrentUserInfo.mySelf.Id); ParentLayHose.name = "LayWaterHose" + creatnum; creatnum++; ParentLayHose.GetComponent().ConnectFireman = gameObject; allInits.Clear(); AddInit(); endPoint = transform.position; if (!GetComponent().pathFindEnable) { GetComponent().pathFindEnable = true; } flag = true; } //如果放下期间没有被别人捡起,继续铺设 else { //if (ParentLayHose.GetComponent().LineLenght==0) //{//开启铺设又立马关闭,一段水带没有使用 // ParentLayHose = Instantiate(ParentLayHosePrefabs, WaterHoses.transform); // ParentLayHose.name = "LayWaterHose" + creatnum; // creatnum++; // ParentLayHose.GetComponent().ConnectFireman = gameObject; //} //更新消防员可用水带 if (ParentLayHose.GetComponent().RemainLenght > 0) { //if((GetComponent().OverLenght==0)) { //GetComponent().WaterHoseLenghtRemain = // GetComponent().NowRemainWaterHose * 20 + ParentLayHose.GetComponent().RemainLenght+GetComponent().OverLenght; //GetComponent().NowRemainWaterHose = GetComponent().NowRemainWaterHose + ParentLayHose.GetComponent().UseNum; GetComponent().CalculateBeforelay(ParentLayHose.GetComponent().RemainLenght, ParentLayHose.GetComponent().UseNum); } } //更新消防员水源信息 if (ParentLayHose.GetComponent().WaterSource != null) { if (issync == false) { gameObject.GetComponent().ResetWaterSourceConnectInfo (true, ParentLayHose.GetComponent().ConnectWater, ParentLayHose.GetComponent().ConnectFoam, ParentLayHose.GetComponent().WaterSource, ParentLayHose.GetComponent().ConnectWaterHose); if (/*FindObjectOfType()*/FireManSkillPanelController.Instance) { FireManSkillPanelController.Instance.SprayWater.GetComponent().interactable = true; } } } else { if (issync == false) { gameObject.GetComponent().ResetWaterSourceConnectInfo(false, false, false, null, null); } } if (!GetComponent().pathFindEnable) { GetComponent().pathFindEnable = true; } flag = true; ParentLayHose.GetComponent().ConnectFireman = gameObject; } //AddInit(); } } //如果当前起始位置与上一次铺设的末点距离较远,则认为开始一段新的铺设,不会收回上一次铺设的管线 else { lengthDic.Clear(); if (GetComponent().WaterHoseLenghtRemain <= 0) { if (IsselfCurrent) { LoadPromptWin.Instance.LoadTextPromptWindow("未装备水带或水带已用完", 1f); } //如果链接水源,不能移动 if (GetComponent().ConnentSource!=null) { GetComponent().pathFindEnable = false; } allInits.Clear(); AddInit(); endPoint = Vector3.zero; flag = false; return; } else { ParentLayHose = Instantiate(ParentLayHosePrefabs, WaterHoses.transform); ParentLayHose.name = "LayWaterHose" + creatnum; creatnum++; ParentLayHose.GetComponent().ConnectFireman = gameObject; //GetComponent().TackUpLenght = 0; //如果铺设时消防员被管线连接,给该水带赋值水源信息 if (GetComponent().IsConnentWaterLine) { FireManWaterHoseManager thisFireman = GetComponent(); ParentLayHose.GetComponent().BindWaterSource(thisFireman.hasWaterConnect, thisFireman.hasFoamConnect, thisFireman.ConnentSource, thisFireman.WaterLineConnent); } allInits.Clear(); AddInit(); endPoint = transform.position; if (!GetComponent().pathFindEnable) { GetComponent().pathFindEnable = true; } flag = true; } } } /// /// 有水源后,设置喷水起始点 /// public void SetInitPoint() { allInits.Clear(); //与之前铺设的水带切断联系 AddInit(); //将当前位置作为起点 endPoint = Vector3.zero;//transform.position; //setInitpoint = true; } /// /// 消防员喷水、泡沫时铺设水带 /// public void StartSprayingLay(bool issync = false) { agent.SetDestination(transform.position); //if (!GetComponent().pathFindEnable) { GetComponent().pathFindEnable = true; } if (GetComponent().WaterHoseLenghtRemain <= 0) { if (IsselfCurrent) { if (!(GetComponent().workType == FireManSkills.SprayFoam|| GetComponent().workType == FireManSkills.SprayWater)) { LoadPromptWin.Instance.LoadTextPromptWindow("还未装备水带", 1); } } } if (endPoint != Vector3.zero && Vector3.Distance(transform.position, endPoint) < 5) { if (ParentLayHose.GetComponent().RemainLenght > 0) { //if((GetComponent().OverLenght==0)) { //GetComponent().WaterHoseLenghtRemain = // GetComponent().NowRemainWaterHose * 20 + ParentLayHose.GetComponent().RemainLenght+GetComponent().OverLenght; //GetComponent().NowRemainWaterHose = GetComponent().NowRemainWaterHose + ParentLayHose.GetComponent().UseNum; GetComponent().CalculateBeforelay(ParentLayHose.GetComponent().RemainLenght, ParentLayHose.GetComponent().UseNum); } } if (ParentLayHose.GetComponent().WaterSource != null) { if (issync == false) { gameObject.GetComponent().ResetWaterSourceConnectInfo (true, ParentLayHose.GetComponent().ConnectWater, ParentLayHose.GetComponent().ConnectFoam, ParentLayHose.GetComponent().WaterSource, ParentLayHose.GetComponent().ConnectWaterHose); } if (/*FindObjectOfType()*/FireManSkillPanelController.Instance) { FireManSkillPanelController.Instance.SprayWater.GetComponent().interactable = true; } } else { if (issync == false) { gameObject.GetComponent().ResetWaterSourceConnectInfo(false, false, false, null, null); } } //GetComponent().WaterHoseLenghtRemain = // GetComponent().NowRemainWaterHose * 20 + ParentLayHose.GetComponent().RemainLenght;//+ GetComponent().OverLenght; // GetComponent().NowRemainWaterHose = GetComponent().NowRemainWaterHose + ParentLayHose.GetComponent().UseNum; GetComponent().CalculateBeforelay(ParentLayHose.GetComponent().RemainLenght, ParentLayHose.GetComponent().UseNum); flag = true; GetComponent().pathFindEnable = true; } else { ParentLayHose = Instantiate(ParentLayHosePrefabs, WaterHoses.transform); ParentLayHose.name = "LayWaterHose" + creatnum; creatnum++; ParentLayHose.GetComponent().ConnectFireman = gameObject; allInits.Clear(); //与之前铺设的水带切断联系 AddInit(); //将当前位置作为起点 endPoint = transform.position; lengthDic.Clear(); remainlenght = GetComponent().WaterHoseLenghtRemain; if (remainlenght <= 0) { GetComponent().pathFindEnable = false; } else { GetComponent().pathFindEnable = true; } } // GetComponent().pathFindEnable = true; canreinit = false; flag = true; spraying = true; } /// /// 结束铺设,放下水带 /// 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); } /// /// 结束铺设时设置该铺设管线信息 /// void SetLayHoseInfo(bool issync = false,bool isstoplayskill=true) { // LastLenght = GetSelfConsumedLength() - ParentLayHose.GetComponent().LineLenght; ParentLayHose.GetComponent().LineLenght = GetSelfConsumedLength(); ParentLayHose.GetComponent().UseNum = Mathf.CeilToInt(GetSelfConsumedLength() / 20); ParentLayHose.GetComponent().CreatFireman = gameObject; ParentLayHose.GetComponent().RemainLenght = Mathf.CeilToInt(GetSelfConsumedLength() / 20) * 20 - GetSelfConsumedLength(); GetComponent().UpdateRemain(GetSelfConsumedLength()); ParentLayHose.GetComponent().ConnectWaterHose = GetComponent().WaterLineConnent; ParentLayHose.GetComponent().EndPoint = transform.position; ParentLayHose.GetComponent().ConnectFireman = null; //如果结束铺设时消防员被管线连接,更新水带水源信息,防止在铺设过程中消防员连接的管线被删除,造成的信息更改 if (GetComponent().IsConnentWaterSource) { FireManWaterHoseManager thisFireman = GetComponent(); ParentLayHose.GetComponent().BindWaterSource(thisFireman.hasWaterConnect, thisFireman.hasFoamConnect, thisFireman.ConnentSource, thisFireman.WaterLineConnent); } else { ParentLayHose.GetComponent().BindWaterSource(false, false, null, null); } if (GetComponent().workType == FireManSkills.SprayFoam || GetComponent().workType == FireManSkills.SprayWater) { GetComponent().pathFindEnable = false; remainlenght = GetComponent().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().isOn = false; // FireManSkillPanelController.Instance.SprayWater.GetComponent().interactable = false; // } //} if (issync==false) { GetComponent().Resert(); } } IEnumerator closespraytoggle() { Debug.Log("closespraytoggle----"+false); yield return new WaitForSeconds(0.2f); if (GetComponent().WorkType!=FireManSkills.SprayFoam&& GetComponent().WorkType != FireManSkills.SprayWater || !FireManSkillPanelController.Instance.extinguishantSelect.gameObject.activeSelf) { //if (FireManSkillPanelController.Instance) { FireManSkillPanelController.Instance.SprayWater.GetComponent().isOn = false; FireManSkillPanelController.Instance.SprayWater.GetComponent().interactable = false; } } } /// /// 收起水带 /// 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); } } /// /// 从起始点到角色当前位置获取铺设路线 /// 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 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().OverLenght == 0) { if (canreinit && path.Length > 1 && Vector3.Distance(transform.position, path[path.Length - 2]) > 0.5f && (thispartlength > 20)) { AddInit(); } } //if (GetComponent().OverLenght > 0) //{ // if (canreinit && path.Length > 1 && Vector3.Distance(transform.position, path[path.Length - 2]) > 0.5f && (thispartlength > GetComponent().OverLenght)) // { // AddInit(); // } //} } /// /// 每帧更新铺设路线 /// private void DrawByTimespan() { GetComponent().WaterHoseLenghtRemain = GetComponent().NowRemainWaterHose * 20 - GetSelfConsumedLength();// + GetComponent().OverLenght; if (GetComponent().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().WaterHoseLenghtRemain-=GetConsumedNum(); } /// /// 喷水、喷泡沫时创建水带末端到消防员手上水枪部位的连接段 /// 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("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);//延长线条,连接两点 } /// /// 不喷水、泡沫时删除水带末端到消防员手上水枪部位的连接段 /// private void DestroyTail() { if (WaterHoses.transform.Find("waterhose-tail")) { Destroy(WaterHoses.transform.Find("waterhose-tail").gameObject); } } /// /// 根据组内已用盘数设置组员水带设备的已消耗数量 /// /// 组内已经消耗的水带长度 //private void SetGroupConsumed(int groupconsumednum) //{ // for (int i = 0; i < groupMembers.Count; i++) //查找每一个组员的背包 // { // List memberEquips = groupMembers[i].GetComponent().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 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 { num }); } private Vector3[] CheckPath(Vector3[] path) { List corners = new List(); 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; } /// /// 获取自己手中持有的水带数量,包括已铺设的数量和携带的未消耗的数量 /// /// public int SelfGotNum() { int selfallnum = 0; //if (UpdateEquipedHoses()) { //selfallnum += equipedHoses.selNum - equipedHoses.conNum; //计算自己携带的剩余可用的数量 } selfallnum += GetSelfConsumedNum(); //加上自己已铺设的数量 return selfallnum; //自己手中一共拥有的数量,解组时重新设定自己的selNum } /// /// 根据管线所在位置设定管线的层信息 /// /// 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() && hit.transform.gameObject.GetComponent().gameObjType == CloneObjType.staticGameObject) { CloneGameObjInfo hoseinfo = hose.GetComponent(); CloneGameObjInfo hitinfo = hit.transform.gameObject.GetComponent(); 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()!=null) { if (ParentLayHose.GetComponent().WaterSource != null) { if ((endPoint != Vector3.zero && Vector3.Distance(transform.position, endPoint) < 5)) { gameObject.GetComponent().ResetWaterSourceConnectInfo (true, ParentLayHose.GetComponent().ConnectWater, ParentLayHose.GetComponent().ConnectFoam, ParentLayHose.GetComponent().WaterSource, ParentLayHose.GetComponent().ConnectWaterHose); if (/*FindObjectOfType()*/FireManSkillPanelController.Instance) { FireManSkillPanelController.Instance.SprayWater.GetComponent().interactable = true; DrawByTimespan(); } } else { // LoadPromptWin.Instance.LoadTextPromptWindow("距离放下水带太远,无法自动拿起管线,请靠近当前放下管线或者重新连接水源", 1f); } } } } }