Browse Source

修改多选寻路,删除主火时删除蔓延火,更新合成文档

11
曹衍涛 3 years ago
parent
commit
2193b2a8c2
  1. BIN
      Assets/Scene/MainScene_New.unity
  2. 5
      Assets/Scripts/DisasterSetting/FireSpreadCtrl.cs
  3. 22
      Assets/Scripts/DisasterSetting/SpreadFire.cs
  4. 147
      Assets/Scripts/Power/AgentController.cs
  5. 72
      Assets/Scripts/Power/MultiSelectNAV.cs
  6. 10
      Assets/Scripts/Power/NAVSelectCarItem.cs
  7. BIN
      电子沙盘合成文档.docx

BIN
Assets/Scene/MainScene_New.unity

Binary file not shown.

5
Assets/Scripts/DisasterSetting/FireSpreadCtrl.cs

@ -118,6 +118,7 @@ public class FireSpreadCtrl : MonoBehaviour
public void OnDestroy()
{
MessageDispatcher.SendMessage("DelectSpread",GetComponent<CloneGameObjInfo>().gameObjID);
MessageDispatcher.RemoveListener("ReplayEvent", ReplayEventSpreadFire);
}
public void Reset()
@ -264,6 +265,10 @@ public class FireSpreadCtrl : MonoBehaviour
List<Vector3> tempFirePosList = spdFirePositions[index++];
for (int j = 0; j < tempFirePosList.Count; j++)
{
if (gameObject.GetComponent<CloneGameObjInfo>().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<SpreadedFire>();

22
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<CloneGameObjInfo>().gameObjID;

147
Assets/Scripts/Power/AgentController.cs

@ -23,6 +23,8 @@ public class AgentController : MonoBehaviour
private float speed;
private float angularSpeed;
public List<Vector3> TargetPoint = new List<Vector3>();
private float oriStopDis;//初始停止距离
private void Awake()
{
pathFindEnable = true;
@ -82,7 +84,7 @@ public class AgentController : MonoBehaviour
}
void Start()
{
oriStopDis = GetComponent<NavMeshAgent>().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<FireManMessage>();
//GetComponent<XiaoFangYuanDrawLine>().setLine();
if (mess.workType == FireManSkills.LayLifeSavingFlarePath ||
@ -202,11 +204,11 @@ public class AgentController : MonoBehaviour
}
}
}
public static event Func<Vector3,IntData, IntData> checkCautionAreaEntering;
public static event Func<Vector3, IntData, IntData> 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<CautionAreaTipData>(eventData.json);
if (data.gameObjID == GetComponent<CloneGameObjInfo>().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<Vector3> TargetPoint)
{
if (pathFindEnable && !FixedArmFlag)
StartCoroutine(PathFinding(TargetPoint));
{
StopAllCoroutines();
corners.Clear();
var templeteCorners = new List<Vector3>();
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<Vector3> 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<NavMeshAgent>();
filter.agentTypeID = agent.agentTypeID;
filter.areaMask = agent.areaMask;
var hasHit = NavMesh.SamplePosition(tagent, out hit, 1, filter);
return hasHit;
}
public static List<Vector3> LiSan(Vector3 center, int count, Vector3 size)
{
List<Vector3> list = new List<Vector3>();
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<Vector3> MuitiPoints,int dis)
{
List<Vector3> posints = new List<Vector3>();
for (int i = 0; i < MuitiPoints.Count; i++)
{
posints.Add(MuitiPoints[i]);
}
GetComponent<BoxCollider>().enabled = false;
this.StopAllCoroutines();
corners.Clear();
StartCoroutine(GoToMuitiPoints(posints));
}
IEnumerator GoToMuitiPoints(List<Vector3> 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<BoxCollider>().enabled = true;
}
}
}

72
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;
/// <summary>
@ -31,32 +32,41 @@ public class MultiSelectNAV : ResourceLoadPanel<MultiSelectNAV>
{
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<AgentController>().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<AgentController>().AutoPathFinding(TargetPoint);
indexer++;
});
// TargetPoint.Clear();
}
TargetPoint[count - 1] = list[indexer];
X.GetComponent<AgentController>().AutoPathFinding(TargetPoint);
indexer++;
});
// TargetPoint.Clear();
}
}
public void AddSelectCar(GameObject Car)
@ -89,7 +99,28 @@ public class MultiSelectNAV : ResourceLoadPanel<MultiSelectNAV>
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<AgentController>().StopAllCoroutines();
}
bool haspath= SelectCars[0].GetComponent<AgentController>().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<MultiSelectNAV>
{
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();
}
}

10
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);
}
}

BIN
电子沙盘合成文档.docx

Binary file not shown.
Loading…
Cancel
Save