diff --git a/Assets/Scene/MainScene_New.unity b/Assets/Scene/MainScene_New.unity index 992c544..7a24ad6 100644 Binary files a/Assets/Scene/MainScene_New.unity and b/Assets/Scene/MainScene_New.unity differ diff --git a/Assets/Scripts/DisasterSetting/FireSpreadCtrl.cs b/Assets/Scripts/DisasterSetting/FireSpreadCtrl.cs index aa14f45..1ece602 100644 --- a/Assets/Scripts/DisasterSetting/FireSpreadCtrl.cs +++ b/Assets/Scripts/DisasterSetting/FireSpreadCtrl.cs @@ -118,6 +118,7 @@ public class FireSpreadCtrl : MonoBehaviour public void OnDestroy() { + MessageDispatcher.SendMessage("DelectSpread",GetComponent().gameObjID); MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventSpreadFire); } public void Reset() @@ -264,6 +265,10 @@ public class FireSpreadCtrl : MonoBehaviour List tempFirePosList = spdFirePositions[index++]; for (int j = 0; j < tempFirePosList.Count; j++) { + if (gameObject.GetComponent().gameObjType==CloneObjType.FireHuge) + { + tempFirePosList[j] = tempFirePosList[j] + Vector3.down * 2.5f; + } GameObject spreadFire = Instantiate(fire, tempFirePosList[j], Quaternion.identity, GameObject.Find("P_AllParent").transform.Find("P_Disaster/P_SpreadFire")) as GameObject; //var spreadedFire = spreadFire.AddComponent(); diff --git a/Assets/Scripts/DisasterSetting/SpreadFire.cs b/Assets/Scripts/DisasterSetting/SpreadFire.cs index 48fab3c..078c13d 100644 --- a/Assets/Scripts/DisasterSetting/SpreadFire.cs +++ b/Assets/Scripts/DisasterSetting/SpreadFire.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using AX.MessageSystem; [Serializable] @@ -28,6 +29,27 @@ public class SpreadFireDestoryData//蔓延出来的火的删除 public class SpreadFire : CloneGameObjInfo { public long SourceId; + + public override void Start() + { + base.Start(); + MessageDispatcher.AddListener("DelectSpread",DelectSpread); + } + public override void OnDestroy() + { + base.OnDestroy(); + MessageDispatcher.RemoveListener("DelectSpread", DelectSpread); + } + + private void DelectSpread(IMessage obj) + { + long id = (long)obj.Data; + if (SourceId==id) + { + Destroy(gameObject); + } + } + public void AddRecordDataCreat(GameObject sourceObj) { SourceId = sourceObj.GetComponent().gameObjID; diff --git a/Assets/Scripts/Power/AgentController.cs b/Assets/Scripts/Power/AgentController.cs index ebbfb83..ca86938 100644 --- a/Assets/Scripts/Power/AgentController.cs +++ b/Assets/Scripts/Power/AgentController.cs @@ -23,6 +23,8 @@ public class AgentController : MonoBehaviour private float speed; private float angularSpeed; public List TargetPoint = new List(); + private float oriStopDis;//初始停止距离 + private void Awake() { pathFindEnable = true; @@ -82,7 +84,7 @@ public class AgentController : MonoBehaviour } void Start() { - + oriStopDis = GetComponent().stoppingDistance; NavMeshPath = new NavMeshPath(); filter = new NavMeshQueryFilter { @@ -179,7 +181,7 @@ public class AgentController : MonoBehaviour if (tag == "Player") { //先判断:是否进入警戒区 - // checkEnterCautionArea(pointhit); + // checkEnterCautionArea(pointhit); FireManMessage mess = GetComponent(); //GetComponent().setLine(); if (mess.workType == FireManSkills.LayLifeSavingFlarePath || @@ -202,11 +204,11 @@ public class AgentController : MonoBehaviour } } } - public static event Func checkCautionAreaEntering; + public static event Func checkCautionAreaEntering; private void checkEnterCautionArea(Vector3 pointhit) { IntData data = new IntData(0); - if(checkCautionAreaEntering != null) + if (checkCautionAreaEntering != null) data = checkCautionAreaEntering(pointhit, data); if (data.value > 0) { @@ -218,7 +220,7 @@ public class AgentController : MonoBehaviour bool clothEquiped = false; //是否装备防化服 bool phoneEquiped = false; //是否装备对讲机 - foreach(Equip equip in bag.EquipList) + foreach (Equip equip in bag.EquipList) { if (equip.Name == "有毒气体探测仪") { @@ -237,8 +239,8 @@ public class AgentController : MonoBehaviour phoneEquiped = true; } } - if(detectEquiped && breathEquiped && clothEquiped && phoneEquiped) - { + if (detectEquiped && breathEquiped && clothEquiped && phoneEquiped) + { //如果按要求装备,就不提示 return; } @@ -255,10 +257,16 @@ public class AgentController : MonoBehaviour warning += " 通信设备"; ResourceLoadWindow.Instance.LoadTipWindow(warning, () => { }, null); AddCautionAreaTipEvent(warning); - } + } } } - + public bool CheckHasPath(Vector3 pointhit) + { + StopAllCoroutines(); + corners.Clear(); + bool flag = setPathCorners(transform.position, pointhit, corners); + return flag; + } private void AddCautionAreaTipEvent(string warning) { if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal) @@ -283,7 +291,7 @@ public class AgentController : MonoBehaviour CautionAreaTipData data = JsonUtility.FromJson(eventData.json); if (data.gameObjID == GetComponent().gameObjID) { - ResourceLoadWindow.Instance.LoadTextHintWindow(data.warning, Mathf.Clamp(2/ GlobalVariable.ReplaySpeed,1,2)); + ResourceLoadWindow.Instance.LoadTextHintWindow(data.warning, Mathf.Clamp(2 / GlobalVariable.ReplaySpeed, 1, 2)); } } } @@ -297,7 +305,52 @@ public class AgentController : MonoBehaviour public void AutoPathFinding(List TargetPoint) { if (pathFindEnable && !FixedArmFlag) - StartCoroutine(PathFinding(TargetPoint)); + { + StopAllCoroutines(); + corners.Clear(); + var templeteCorners = new List(); + for (int i = 0; i < TargetPoint.Count; i++) + { + if (i == 0) + { + templeteCorners.Clear(); + bool flag = setPathCorners(transform.position, TargetPoint[i], templeteCorners); + if (flag) + { + foreach (Vector3 point in templeteCorners) + { + corners.Add(point); + } + + } + else + { + ResourceLoadWindow.Instance.LoadTextHintWindow("不能抵达", 2f); + return; + } + } + else + { + templeteCorners.Clear(); + bool flag = setPathCorners(TargetPoint[i - 1], TargetPoint[i], templeteCorners); + if (flag) + { + foreach (Vector3 point in templeteCorners) + { + corners.Add(point); + } + + } + else + { + ResourceLoadWindow.Instance.LoadTextHintWindow("不能抵达", 2f); + return; + } + } + } + //removeNoMainCorners(corners); + StartCoroutine(GoToDestination()); + } } IEnumerator PathFinding(List TargetPoint) { @@ -326,15 +379,26 @@ public class AgentController : MonoBehaviour yield return true; } } - + public static bool InNavMesh(Vector3 tagent) + { + NavMeshHit hit; + NavMeshQueryFilter filter = new NavMeshQueryFilter(); + var agent = GameObject.Find("CarAgent").GetComponent(); + filter.agentTypeID = agent.agentTypeID; + filter.areaMask = agent.areaMask; + var hasHit = NavMesh.SamplePosition(tagent, out hit, 1, filter); + return hasHit; + } public static List LiSan(Vector3 center, int count, Vector3 size) { List list = new List(); + list.Add(center);//先加入目的地 + int num = 1; while (list.Count < count) { var tagent = new Vector3(center.x, center.y, center.z + size.z * num); - if (InNavMesh(center, tagent)) + if (InNavMesh(tagent)) list.Add(tagent); else { @@ -347,7 +411,7 @@ public class AgentController : MonoBehaviour while (list.Count < count) { var tagent = new Vector3(center.x, center.y, center.z - size.z * num); - if (InNavMesh(center, tagent)) + if (InNavMesh(tagent)) list.Add(tagent); else { @@ -360,7 +424,7 @@ public class AgentController : MonoBehaviour while (list.Count < count) { var tagent = new Vector3(center.x + size.x * num, center.y, center.z); - if (InNavMesh(center, tagent)) + if (InNavMesh(tagent)) list.Add(tagent); else { @@ -373,7 +437,7 @@ public class AgentController : MonoBehaviour while (list.Count < count) { var tagent = new Vector3(center.x - size.x * num, center.y, center.z); - if (InNavMesh(center, tagent)) + if (InNavMesh(tagent)) list.Add(tagent); else { @@ -382,6 +446,17 @@ public class AgentController : MonoBehaviour } num++; } + + //找到的点不够,添加最后重复点 + if (list.Count < count) + { + var point = list[list.Count - 1]; + for (int i = list.Count; i < count; i++) + { + var tagent = point; + list.Add(tagent); + } + } return list; } public static bool InNavMesh(Vector3 center, Vector3 tagent) @@ -583,4 +658,44 @@ public class AgentController : MonoBehaviour } } } + public void MuitiNav(List MuitiPoints,int dis) + { + List posints = new List(); + for (int i = 0; i < MuitiPoints.Count; i++) + { + posints.Add(MuitiPoints[i]); + } + GetComponent().enabled = false; + this.StopAllCoroutines(); + corners.Clear(); + StartCoroutine(GoToMuitiPoints(posints)); + } + IEnumerator GoToMuitiPoints(List posints) + { + int i = 0; + while (i < posints.Count) + { + pointhit = posints[i]; + bool flag = setPathCorners(transform.position, pointhit, corners); + + StartCoroutine(GoToDestination()); + //MessageDispatcher.SendMessage("PATH_FINDING_COMMAND", arg); + + //while循环作用:等到达第i个侦察路径点后,再寻路至i++个侦察路径点 + float remain = Vector3.Distance(transform.position, posints[i]); + while (remain == Mathf.Infinity || remain - agent.stoppingDistance > float.Epsilon) + { + remain = Vector3.Distance(transform.position, posints[i]); + yield return null;//防止循环造成卡死 + } + + posints.Remove(posints[i]); + //i++; + } + + if (i == posints.Count) + { + GetComponent().enabled = true; + } + } } diff --git a/Assets/Scripts/Power/MultiSelectNAV.cs b/Assets/Scripts/Power/MultiSelectNAV.cs index ab29f51..3ce8148 100644 --- a/Assets/Scripts/Power/MultiSelectNAV.cs +++ b/Assets/Scripts/Power/MultiSelectNAV.cs @@ -4,6 +4,7 @@ using System; using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.AI; using UnityEngine.UI; /// @@ -31,32 +32,41 @@ public class MultiSelectNAV : ResourceLoadPanel { if (Ison) { - MessageDispatcher.AddListener("PATH_FINDING_COMMAND", PathFinding); TargetPoint.Clear(); + MessageDispatcher.AddListener("PATH_FINDING_COMMAND", PathFinding); CancelSelectedCommand.Instance.Execute(0, null); } else MessageDispatcher.RemoveListener("PATH_FINDING_COMMAND", PathFinding); pathfindingFlag = Ison; InputManager.MutiSelectFind = Ison; + //if (!Ison) + //{ + // if(!pathfindingFlag && TargetPoint.Count > 0) + // { + // //MultiSelectNavPath.instance.SetPathFind(TargetPoint, SelectCars); + // for (int i = 0; i < SelectCars.Count; i++) + // { + // SelectCars[i].GetComponent().MuitiNav(TargetPoint, i); + // } + // } + //} if (!pathfindingFlag && TargetPoint.Count > 0) { var count = TargetPoint.Count; + //最后目标点找到各车的停靠点 var list = AgentController.LiSan(TargetPoint[count - 1], SelectCars.Count, new Vector3(9, 0, 9)); int indexer = 0; - if (SelectCars.Count>0&& list.Count>0) + //开始多选车辆的巡礼操作 + SelectCars.ForEach((X) => { - //开始多选车辆的巡礼操作 - SelectCars.ForEach((X) => - { - TargetPoint[count - 1] = list[indexer]; - X.GetComponent().AutoPathFinding(TargetPoint); - indexer++; - }); - // TargetPoint.Clear(); - } - + TargetPoint[count - 1] = list[indexer]; + X.GetComponent().AutoPathFinding(TargetPoint); + indexer++; + }); + // TargetPoint.Clear(); } + } public void AddSelectCar(GameObject Car) @@ -89,7 +99,28 @@ public class MultiSelectNAV : ResourceLoadPanel return; var data = (PathFindingCmdArgs)obj.Data; InputManager.pointerObj.transform.position = data.hitPoint; - TargetPoint.Add(data.hitPoint); + if (SelectCars.Count > 0) + { + for (int i = 0; i < SelectCars.Count; i++) + { + SelectCars[i].GetComponent().StopAllCoroutines(); + } + bool haspath= SelectCars[0].GetComponent().CheckHasPath(data.hitPoint); + if (haspath) + { + TargetPoint.Add(data.hitPoint); + } + else + { + ResourceLoadWindow.Instance.LoadTextHintWindow("该点无法到达", 1f); + } + } + else + { + ResourceLoadWindow.Instance.LoadTextHintWindow("没有选中任何车辆", 1f); + InstallNAVButton.isOn = false; + return; + } } private void ShowUI(bool Ison) @@ -123,4 +154,19 @@ public class MultiSelectNAV : ResourceLoadPanel { MultiSelectNAVButton.isOn = false; } + private void Update() + { + if (!pathfindingFlag && TargetPoint.Count > 0) + { + + } + } + private void OnDestroy() + { + MessageDispatcher.RemoveListener("PATH_FINDING_COMMAND", PathFinding); + MessageDispatcher.RemoveListener("RADIO_SELECTED_COMMAND", RadioSelect); + SelectCars.Clear(); + TargetPoint.Clear(); + NAVSelectCarItem.SelectCarItem.Clear(); + } } diff --git a/Assets/Scripts/Power/NAVSelectCarItem.cs b/Assets/Scripts/Power/NAVSelectCarItem.cs index 155eb8d..b38e75c 100644 --- a/Assets/Scripts/Power/NAVSelectCarItem.cs +++ b/Assets/Scripts/Power/NAVSelectCarItem.cs @@ -60,4 +60,14 @@ public class NAVSelectCarItem : MonoBehaviour SelectCarItem.Remove(this); Destroy(gameObject); } + private void OnDestroy() + { + if (SelectCarItem.Contains(this)) + { + SelectCarItem.Remove(this); + } + MultiSelectNAV.GetInstance.RemoveSelectCar(SelectCar); + MessageDispatcher.RemoveListener("RemoveSelectCar", RemoveSelectCar); + MessageDispatcher.RemoveListener("DeleteObj", DeleteObj); + } } diff --git a/电子沙盘合成文档.docx b/电子沙盘合成文档.docx index 0c8210d..a6daf5d 100644 Binary files a/电子沙盘合成文档.docx and b/电子沙盘合成文档.docx differ