|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|