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.
239 lines
8.2 KiB
239 lines
8.2 KiB
using AX.InputSystem; |
|
using AX.MessageSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.AI; |
|
|
|
public class FireManDebarkation : MonoBehaviour |
|
{ |
|
private Vector3 EndPos; |
|
private Vector3 StartPos; |
|
private List<Vector3> ThePath; |
|
private NavMeshPath path; |
|
private int ManMum; |
|
|
|
void Start() |
|
{ |
|
MessageDispatcher.AddListener("Debarkation", firemandebarkation); |
|
} |
|
void OnDestroy() |
|
{ |
|
MessageDispatcher.RemoveListener("Debarkation", firemandebarkation); |
|
} |
|
|
|
private void firemandebarkation(IMessage obj) |
|
{ |
|
if (RecordEvent.IsReplay()) |
|
return; |
|
long gameid = (long)obj.Sender; |
|
if (gameid == this.GetComponent<BaseGameObjInfo>().GameObjID) |
|
if (GetComponent<UnityEngine.AI.NavMeshObstacle>()) |
|
{//如果障碍组件存在 |
|
StartCoroutine(SetXiaoFangYuanPos()); |
|
} |
|
else |
|
{ |
|
SetPos(); |
|
} |
|
} |
|
IEnumerator SetXiaoFangYuanPos() |
|
{ |
|
GetComponent<UnityEngine.AI.NavMeshObstacle>().enabled = false; |
|
yield return null; |
|
if (!GetComponent<UnityEngine.AI.NavMeshObstacle>().enabled) |
|
{//如果障碍组件关闭了,就开启寻路组件 |
|
GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = true; |
|
SetPos(); |
|
} |
|
else |
|
{//如果障碍组件没关闭,就继续执行协程 |
|
StartCoroutine(SetXiaoFangYuanPos()); |
|
} |
|
|
|
} |
|
void SetPos() |
|
{ |
|
BoxCollider BoxCollider = GetComponent<BoxCollider>(); |
|
float X = 3; |
|
int ManMum = GetComponent<TruckMessages>().CarAttribute.FireManNum; |
|
Vector3 vetPos = this.transform.position; |
|
bool Can = true; |
|
bool Can1 = true; |
|
bool Can2 = true; |
|
bool Can3 = true; |
|
for (int num = 1; num < 5; num++) |
|
{ |
|
switch (num) |
|
{ |
|
case 1: |
|
X = BoxCollider.bounds.size.x / 2; |
|
StartPos = new Vector3(vetPos.x + 3 * 1, vetPos.y, vetPos.z); |
|
|
|
ThePath = new List<Vector3>(); |
|
for (int i = 0; i < ManMum; i++) |
|
{ |
|
X += 1; |
|
EndPos = new Vector3(vetPos.x + X * 1, vetPos.y, vetPos.z); |
|
path = new UnityEngine.AI.NavMeshPath(); |
|
UnityEngine.AI.NavMesh.CalculatePath(StartPos, EndPos, -1, path); |
|
|
|
if (path.corners.Length <= 2 && path.corners.Length != 0) |
|
{ |
|
ThePath.Add(path.corners[path.corners.Length - 1]); |
|
} |
|
else |
|
{ |
|
Can = false; |
|
} |
|
} |
|
if (Can) |
|
{ |
|
GetCar(ThePath); |
|
return; |
|
} |
|
break; |
|
case 2: |
|
X = BoxCollider.bounds.size.x / 2; |
|
StartPos = new Vector3(vetPos.x + 3 * (-1), vetPos.y, vetPos.z); |
|
|
|
ThePath = new List<Vector3>(); |
|
for (int i = 0; i < ManMum; i++) |
|
{ |
|
X += 1; |
|
EndPos = new Vector3(vetPos.x + X * (-1), vetPos.y, vetPos.z); |
|
path = new UnityEngine.AI.NavMeshPath(); |
|
UnityEngine.AI.NavMesh.CalculatePath(StartPos, EndPos, -1, path); |
|
|
|
if (path.corners.Length <= 2 && path.corners.Length != 0) |
|
{ |
|
ThePath.Add(path.corners[path.corners.Length - 1]); |
|
} |
|
else |
|
{ |
|
Can1 = false; |
|
} |
|
} |
|
if (Can1) |
|
{ |
|
GetCar(ThePath); |
|
return; |
|
} |
|
break; |
|
case 3: |
|
X = BoxCollider.bounds.size.z / 2; |
|
StartPos = new Vector3(vetPos.x, vetPos.y, vetPos.z + 3 * 1); |
|
|
|
ThePath = new List<Vector3>(); |
|
for (int i = 0; i < ManMum; i++) |
|
{ |
|
X += 1; |
|
EndPos = new Vector3(vetPos.x, vetPos.y, vetPos.z + X * 1); |
|
path = new UnityEngine.AI.NavMeshPath(); |
|
UnityEngine.AI.NavMesh.CalculatePath(StartPos, EndPos, -1, path); |
|
|
|
if (path.corners.Length <= 2 && path.corners.Length != 0) |
|
{ |
|
ThePath.Add(path.corners[path.corners.Length - 1]); |
|
} |
|
else |
|
{ |
|
Can2 = false; |
|
} |
|
} |
|
if (Can2) |
|
{ |
|
GetCar(ThePath); |
|
return; |
|
} |
|
break; |
|
case 4: |
|
X = BoxCollider.bounds.size.z / 2; |
|
ThePath = new List<Vector3>(); |
|
StartPos = new Vector3(vetPos.x, vetPos.y, vetPos.z + 3 * (-1)); |
|
for (int i = 0; i < ManMum; i++) |
|
{ |
|
X += 1; |
|
EndPos = new Vector3(vetPos.x, vetPos.y, vetPos.z + X * (-1)); |
|
path = new UnityEngine.AI.NavMeshPath(); |
|
UnityEngine.AI.NavMesh.CalculatePath(StartPos, EndPos, -1, path); |
|
|
|
if (path.corners.Length <= 2 && path.corners.Length != 0) |
|
{ |
|
ThePath.Add(path.corners[path.corners.Length - 1]); |
|
} |
|
else |
|
{ |
|
Can3 = false; |
|
} |
|
} |
|
if (Can3) |
|
{ |
|
GetCar(ThePath); |
|
return; |
|
} |
|
break; |
|
default: |
|
break; |
|
} |
|
if (!Can && !Can1 && !Can2 && !Can3) |
|
{ |
|
ResourceLoadWindow.Instance.LoadTextHintWindow("没有合适下车位置", 1.5f); |
|
} |
|
} |
|
} |
|
public void GetCar(List<Vector3> ath) |
|
{ |
|
ManMum = GetComponent<TruckMessages>().CarAttribute.FireManNum; |
|
for (int i = 0; i < ManMum; i++) |
|
{ |
|
instanceMan(i); |
|
} |
|
GetComponent<TruckMessages>().EnabledSkills &= ~TruckSkillsEnum.Debarkation; |
|
if (SelectedObjs.selectedObj == this.gameObject) |
|
MessageDispatcher.SendMessage("SetTrcukSkills", gameObject); |
|
ReSetNavMesh(); |
|
} |
|
void ReSetNavMesh() |
|
{//如果已经下车,那么就重置障碍组件 |
|
if (!GetComponent<UnityEngine.AI.NavMeshObstacle>()) |
|
{//如果障碍组件不存在,就跑路 |
|
return; |
|
} |
|
StartCoroutine(ReSetNav()); |
|
} |
|
IEnumerator ReSetNav() |
|
{ |
|
GetComponent<UnityEngine.AI.NavMeshAgent>().enabled = false; |
|
yield return null; |
|
if (!GetComponent<UnityEngine.AI.NavMeshAgent>().enabled) |
|
{//如果寻路组件没有被开启,就开启障碍组件 |
|
GetComponent<UnityEngine.AI.NavMeshObstacle>().enabled = true; |
|
} |
|
else |
|
{ |
|
StartCoroutine(ReSetNav()); |
|
} |
|
} |
|
void instanceMan(int I) |
|
{ |
|
Vector3 vetPos = this.transform.position; |
|
Vector3 POS; |
|
if (ThePath[I] == null) |
|
{ |
|
POS = ThePath[I - 1]; |
|
} |
|
else |
|
{ |
|
POS = ThePath[I]; |
|
} |
|
var arg = new CloneCmdArgs |
|
{ |
|
cloneObjType = CloneObjType.FireMan, |
|
hitPos = new Vector3(POS.x, POS.y, POS.z), |
|
gameObjID = GetComponent<CloneGameObjInfo>().GameObjID |
|
}; |
|
MessageDispatcher.SendMessage(EntitiesManager.Instance.CreateObjID(), "CLONE_COMMAND", arg); |
|
} |
|
}
|
|
|