using System.Collections; using System.Collections.Generic; using UnityEngine; using AX.NetworkSystem; using AX.MessageSystem; using System; using UnityEngine.AI; using AX.InputSystem; using UnityEngine.EventSystems; using System.Linq; public enum MoveState { IDLE, MOVEFREE, //GUIDED, FALLDOWN, //FIREMANCLOSE } public class TrappedMoveFree : MonoBehaviour { //private Ray ray = new Ray(); /// /// 随机移动位置点 /// private Vector3 randomVector = Vector3.zero; /// /// 最近一次遇到的火的位置 /// private Vector3 DangerousLastmet = Vector3.zero; /// /// 检测危险的距离 /// public float MetDangerousDistance = 10; /// /// 每次随机点位的最大移动距离 /// private float MaxRange = 15; private bool DrillStart; public bool FireManNear = false; private NavMeshAgent nav; /// /// 是否被急救 /// //public bool First_Aid; /// /// 是否已被安抚 /// //public bool Pacify; /// /// 是否被引导 /// public bool Guidance; /// /// 引导点索引 /// // private int GuidIndex = 0; /// /// 是否遇到危险 /// public bool MeetDangerous; /// /// 最后一个操作该被困人员的消防员 /// public long FireManlastID; public float arrive; private Transform P_SafeArea; [SerializeField] /// /// 消防员设置的寻路点 /// public List guidPoint = new List(); RaycastHit hit; /// /// 是否被消防员移动 /// public bool IsMoveState; //移动跟随的消防员 public GameObject MoveFireman; public bool firemanHit; public float Haemal; private Animator anim; [SerializeField] public MoveState movestate; /// /// 寻路目标点,如果为消防员移动后,将该点设为消防员发来的点,将其设置为寻路点之后再重置为zero用以做移动状态的判断 /// private Vector3 targetPosition; public SceneType scenetype; //触发器里面的消防员 //public List firemanList = new List(); //结束移动或引导 public bool OverMoveOrGuidance = false; /// /// 附近危险列表 /// private List DangerousList = new List(); private Transform P_Disasters; //private bool DangerousOverTwo=false; private float timer = 1f; /// /// 自己本客户端,一个是用来控制文字提示,一个是用来控制引导时,会出现不正常引导的情况 /// public bool IsselfClient = true; public float distance; /// /// 营救该被困人员的消防员userId,报告里要用到 /// public long SaveFrirmanUserId; /// /// 演练开始时的起始位置点,总在该点周围移动 /// public Vector3 originalpoint; private BaseHaemalController basehaemal; /// /// 是否被移动或者被急救 /// public bool isBefirstAirOrMoving = false; /// /// 移动生命少于50的伤员时,周围闲置最近的消防员 /// private List> freeFiremanAround = new List>(); private Transform p_fireman; public bool falldownlock = false; public bool IsSetPoint = false; public bool IsBefirstAirOrMoving { get { return isBefirstAirOrMoving; } set { isBefirstAirOrMoving = value; if (value) { CancelInvokeRandom(); GetComponent().StopAllCoroutines(); TargetPosition = transform.position; if (nav.enabled) nav.SetDestination(transform.position); GetComponent().pathFindEnable = false; if (GetComponent().Haemal > 50) { if (movestate != MoveState.IDLE) { movestate = MoveState.IDLE; anim.SetFloat("Speed", 0f); } } } else { GetComponent().pathFindEnable = true; } WounderFirstAidOrMoveStateSyncData arg = new WounderFirstAidOrMoveStateSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = GetComponent().gameObjID; arg.IsBeFristAidOrMove = value; NetworkManager.Default.SendAsync("WOUNDER_FRISTAID_OR_MOVE_STATE_SYNC", arg); } } public Vector3 TargetPosition { get { return targetPosition; } set { //Debug.Log("" + "dssfsda" + ""); targetPosition = value; } } public void OnEnable() { //MessageDispatcher.AddListener("SetGuidpathIndex", AddGuidIndex); MessageDispatcher.AddListener("MOVE_MAN_COMMAND", MoveExcute); MessageDispatcher.AddListener("GUIDANCE_MAN_COMMAND", GuidanceTrapped); MessageDispatcher.AddListener("FRISTAID_MAN_COMMAND", FristAidTrapped); MessageDispatcher.AddListener("TRAPPED_MOVE_FOLLOW_GUIDE_POINT_COMMAND", MoveFollowGuidPoint); MessageDispatcher.AddListener("ENDMOVE", EndMove); RescuedValue.getAllRescuedTrapped += addMyRescue; DrillBeginButton.getUnrescuedCount += addMyUnrescue; TrappedInfo.getAllTrappedCount += addMyTrapped; TrappedInfo.getTrappedRescuedCount += addMyRescue; TrappedTime.getAllWoundedTrappedCount += addMyUnrescue; MessageDispatcher.AddListener("FiremanHitCancel", cancelHit); } public void OnDestroy() { // MessageDispatcher.RemoveListener("SetGuidpathIndex", AddGuidIndex); MessageDispatcher.RemoveListener("MOVE_MAN_COMMAND", MoveExcute); MessageDispatcher.RemoveListener("GUIDANCE_MAN_COMMAND", GuidanceTrapped); MessageDispatcher.RemoveListener("FRISTAID_MAN_COMMAND", FristAidTrapped); MessageDispatcher.RemoveListener("TRAPPED_MOVE_FOLLOW_GUIDE_POINT_COMMAND", MoveFollowGuidPoint); MessageDispatcher.RemoveListener("ENDMOVE", EndMove); RescuedValue.getAllRescuedTrapped -= addMyRescue; DrillBeginButton.getUnrescuedCount -= addMyUnrescue; TrappedInfo.getAllTrappedCount -= addMyTrapped; TrappedInfo.getTrappedRescuedCount -= addMyRescue; TrappedTime.getAllWoundedTrappedCount -= addMyUnrescue; MessageDispatcher.RemoveListener("FiremanHitCancel", cancelHit); } public void OnDisable() { //MessageDispatcher.RemoveListener("SetGuidpathIndex", AddGuidIndex); MessageDispatcher.RemoveListener("MOVE_MAN_COMMAND", MoveExcute); MessageDispatcher.RemoveListener("GUIDANCE_MAN_COMMAND", GuidanceTrapped); MessageDispatcher.RemoveListener("FRISTAID_MAN_COMMAND", FristAidTrapped); MessageDispatcher.RemoveListener("TRAPPED_MOVE_FOLLOW_GUIDE_POINT_COMMAND", MoveFollowGuidPoint); MessageDispatcher.RemoveListener("ENDMOVE", EndMove); RescuedValue.getAllRescuedTrapped -= addMyRescue; DrillBeginButton.getUnrescuedCount -= addMyUnrescue; TrappedInfo.getAllTrappedCount -= addMyTrapped; TrappedInfo.getTrappedRescuedCount -= addMyRescue; TrappedTime.getAllWoundedTrappedCount -= addMyUnrescue; MessageDispatcher.RemoveListener("FiremanHitCancel", cancelHit); } private void cancelHit(IMessage obj) { if (firemanHit) { if (!OverMoveOrGuidance) { if (!Guidance) { CancelGuidance(); } } } } private void EndMove(IMessage obj) { var fireman = (GameObject)obj.Data; if (IsMoveState) { if (MoveFireman == fireman) { SaveFrirmanUserId = fireman.GetComponent().UserID; //同步 TrappedMoveFollowFiremanSyncData arg = new TrappedMoveFollowFiremanSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.IsEnd = true; arg.SaveFiremanUserID = SaveFrirmanUserId; arg.TrappedID = GetComponent().gameObjID; arg.FiremanID = MoveFireman.GetComponent().gameObjID; NetworkManager.Default.SendAsync("TRAPPED_MOVE_FOLLOW_FIREMAN_SYNC", arg); TargetPosition = transform.position; MoveFireman.GetComponent().trappedlist.Clear(); MoveFireman = null; IsMoveState = false; OverMoveOrGuidance = true; TrappedTime.CheckStopTime(); //MessageDispatcher.SendMessage("SomeoneOutOfTrap"); //通知火场信息-疏散救生-被困时间部分更新,看是否可以停止计时 } } } private void FristAidTrapped(IMessage obj) { var info = (ForcibleEntryCmdArgs)obj.Data; GameObject fireMan = EntitiesManager.Instance.GetEntityByID(info.fireManID); if (info.gameObjID == GetComponent().gameObjID) { if (Haemal <= 0) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员已死亡,不能操作", 2f); return; } if (IsBefirstAirOrMoving) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在被急救或者移动,不能操作", 2f); return; } //if (MeetDangerous) //{ // LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在逃离灾情,不能操作", 2f); // return; //} if (Vector3.Distance(fireMan.transform.position, transform.position) > 3) { LoadPromptWin.Instance.LoadTextPromptWindow("请靠近需救助人员", 1f); firemanHit = true; // CancelInvoke("RandomPoint"); // StartCoroutine(WaitForFireman()); } else { if (basehaemal) { basehaemal.skillList.Add(new KeyValuePair(fireMan, FireManSkills.FristAid)); } //显示急救进度条 GetComponent().haemal.GetComponent().FirstAir(fireMan); IsBefirstAirOrMoving = true; fireMan.GetComponent().pathFindEnable = false; if (FireManSkillPanelController.Instance) { if (FireManSkillPanelController.Instance.SelectFireMan == fireMan) { FireManSkillPanelController.Instance.SetSkillDisable(); } } //同步 // StartCoroutine(firstAidText()); FireManlastID = info.fireManID; } } } private void GuidanceTrapped(IMessage obj) { var info = (ForcibleEntryCmdArgs)obj.Data; GameObject fireMan = EntitiesManager.Instance.GetEntityByID(info.fireManID); if (info.gameObjID == GetComponent().gameObjID) { if (OverMoveOrGuidance) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员已被营救,不能再进行操作", 1f); return; } //if (MeetDangerous) //{ // LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在逃离灾情,不能操作", 2f); // return; //} if (Guidance) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员正被引导,不能再进行操作", 1f); return; } if (IsBefirstAirOrMoving) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在被急救或者移动,不能操作", 2f); return; } if (Vector3.Distance(fireMan.transform.position, transform.position) > 3) { LoadPromptWin.Instance.LoadTextPromptWindow("请靠近需救助人员", 1f); firemanHit = true; if (IsselfClient) { movestate = MoveState.IDLE; var arg = new TrappedWaitFiremanSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = GetComponent().gameObjID; arg.IsWait = true; arg.Waitposition = transform.position; NetworkManager.Default.SendAsync("TRAPPED_WAIT_FIREMAN_SYNC", arg); } nav.SetDestination(transform.position); CancelInvokeRandom(); GetComponent().StopAllCoroutines(); TargetPosition = transform.position; movestate = MoveState.IDLE; //CancelInvoke("RandomPoint"); // StartCoroutine(WaitForFireman()); } else { if (Haemal <= 50) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员已昏迷,不能引导", 1f); return; } Guidance = true; IsSetPoint = true; if (MeetDangerous) { MeetDangerous = false; } CancelInvokeRandom(); StopAllCoroutines(); nav.SetDestination(transform.position); if (GetComponent()) { basehaemal.skillList.Add(new KeyValuePair(fireMan, FireManSkills.Guidance)); } FireManlastID = info.fireManID; //禁用触发器,防止其他消防员再次引导该被困人员 //GetComponent().enabled = false; //if (MeetDangerous) //{ // MeetDangerous = false; //} movestate = MoveState.IDLE; LoadPromptWin.Instance.LoadTextPromptWindow("即将开始引导,左键点击场景设置引导点,关闭或选择其他技能后被困人员将按照引导点移动", 3f); fireMan.GetComponent().GuidanceTrapped = gameObject; InputManager.IsGuidance = true; //firemanList.Clear(); //firemanList.Add(fireMan); //引导同步 TrappedGuidanceSyncData argguide = new TrappedGuidanceSyncData(); argguide.SaveFiremanUserID = SaveFrirmanUserId; argguide.IsSetPoint = true; argguide.SendUserID = CurrentUserInfo.mySelf.Id; argguide.gameObjID = GetComponent().gameObjID; NetworkManager.Default.SendAsync("TRAPPED_GUIDANCE_SYNC", argguide); } } } public void CancelGuidance() { firemanHit = false; IsSetPoint = false; Guidance = false; if (CurrentUserInfo.mySelf.Id==CurrentUserInfo.room.Owner.UserInfo.Id) { InvokeRepeating("RandomPoint", 0f, 8f); } //同步 var arg = new TrappedWaitFiremanSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = GetComponent().gameObjID; arg.IsWait = false; arg.Waitposition = transform.position; NetworkManager.Default.SendAsync("TRAPPED_WAIT_FIREMAN_SYNC", arg); } /// /// 对被困人员使用移动技能 /// /// private void MoveExcute(IMessage obj) { var info = (ForcibleEntryCmdArgs)obj.Data; GameObject fireMan = EntitiesManager.Instance.GetEntityByID(info.fireManID); if (info.gameObjID == GetComponent().gameObjID) { if (IsBefirstAirOrMoving) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在被急救或者移动,不能操作", 2f); return; } //if(MeetDangerous) //{ // LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在逃离灾情,不能操作", 2f); // return; //} if (OverMoveOrGuidance == true) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员被营救,不能再进行操作", 1f); return; } //if (fireMan.GetComponent().trappedlist.Count > 0) //{ // if (fireMan.GetComponent().trappedlist.Contains(info.gameObjID)) // { // LoadPromptWin.Instance.LoadTextPromptWindow("该人员已跟随移动", 1f); // return; // } // else // { // LoadPromptWin.Instance.LoadTextPromptWindow("不能同时移动多名人员", 1f); // return; // } //} if (!IsMoveState && !OverMoveOrGuidance) { if (Haemal > 50) { LoadPromptWin.Instance.LoadTextPromptWindow("该被困人员不需要移动", 1f); return; } if (Vector3.Distance(fireMan.transform.position, transform.position) > 3) { LoadPromptWin.Instance.LoadTextPromptWindow("请靠近需救助人员", 1f); firemanHit = true; // CancelInvoke("RandomPoint"); // StartCoroutine(WaitForFireman()); } else { if (Haemal <= 50) { if (CheckFiremanAround(fireMan) == null) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员已昏迷,需两名消防员进行移动", 2f); return; } else {//两名消防员对重伤员移动逻辑 GameObject nestestfireman = CheckFiremanAround(fireMan); GetComponent().haemal.GetComponent().Moving(fireMan, nestestfireman); IsBefirstAirOrMoving = true; GetComponent().IsMoving = true; falldownlock = true; IsMoveState = true; return; } } else { IsMoveState = true; if (basehaemal) { basehaemal.skillList.Add(new KeyValuePair(fireMan, FireManSkills.Move)); } FireManlastID = info.fireManID; //GetComponentInChildren().enabled = false; //禁用触发器,防止其他消防员再次移动该被困人员 //firemanList.Clear(); //firemanList.Add(fireMan); LoadPromptWin.Instance.LoadTextPromptWindow("移动成功,该被困人员将跟随该消防员移动,关闭或选择其他技能后将停止移动", 3f); //将该被困人员加入对应消防员的移动列表 fireMan.GetComponent().trappedlist.Add(gameObject.GetComponent().gameObjID); MoveFireman = fireMan; TargetPosition = Vector3.zero; GetComponent().StopAllCoroutines(); GetComponent().SetDestination(transform.position); movestate = MoveState.IDLE; //被困人员移动同步 TrappedMoveFollowFiremanSyncData arg = new TrappedMoveFollowFiremanSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.IsEnd = false; arg.TrappedID = GetComponent().gameObjID; arg.FiremanID = MoveFireman.GetComponent().gameObjID; NetworkManager.Default.SendAsync("TRAPPED_MOVE_FOLLOW_FIREMAN_SYNC", arg); } } } else { LoadPromptWin.Instance.LoadTextPromptWindow("被困人员已被其他消防员移动或引导", 1f); } } } /// /// 返回该轻伤员附近空闲的消防员 /// /// /// GameObject CheckFiremanAround(GameObject fireman) { GameObject nestest = null; freeFiremanAround.Clear(); long userid = fireman.GetComponent().UserID; for (int i = 0; i < p_fireman.childCount; i++) { if (p_fireman.GetChild(i).GetComponent().UserID == userid) { if (p_fireman.GetChild(i).gameObject != fireman) { //如果附近有空闲或者开着移动技能但是没有移动人员的消防员 if (p_fireman.GetChild(i).GetComponent().workType == FireManSkills.None || (p_fireman.GetChild(i).GetComponent().workType == FireManSkills.Move && p_fireman.GetChild(i).GetComponent().trappedlist.Count < 1)) { if (Vector3.Distance(p_fireman.GetChild(i).position, transform.position) < 3) { freeFiremanAround.Add(new KeyValuePair(p_fireman.GetChild(i).gameObject, Vector3.Distance(p_fireman.GetChild(i).position, transform.position))); } if (freeFiremanAround.Count > 0) { var resert = freeFiremanAround.OrderBy(p => p.Value); nestest = resert.ElementAt(0).Key; } } } } } return nestest; } //监听寻路点设置,按寻路点移动 private void MoveFollowGuidPoint(IMessage obj) { var info = (GuideLodeCmdArgs)obj.Data; var fireman = EntitiesManager.Instance.GetEntityByID(info.FireManID); if (info.TrappedID == GetComponent().gameObjID) { IsSetPoint = false; if (Haemal <= 50) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员已昏迷不能引导", 1f); if (fireman.GetComponent().GuidanceTrapped != null) { fireman.GetComponent().GuidanceTrapped = null; } return; } guidPoint.Clear(); //获取引导的点 foreach (var item in info.pathpointList) { guidPoint.Add(item); } // guidPoint = info.pathpointList; if (guidPoint.Count < 1) { LoadPromptWin.Instance.LoadTextPromptWindow("引导失败,未设置引导点", 1f); return; } Guidance = true; for (int i = 0; i < guidPoint.Count - 1; i++) { for (int k = guidPoint.Count - 2; k > i; k--) { float distance = Vector3.Distance(guidPoint[i], guidPoint[k]);//计算两点的距离 if (distance < 5) { for (int j = k; j > i; j--) { guidPoint.RemoveAt(j); } break; } } } TargetPosition = guidPoint[0]; SaveFrirmanUserId = fireman.GetComponent().UserID; //引导同步 TrappedGuidanceSyncData argguide = new TrappedGuidanceSyncData(); argguide.SaveFiremanUserID = SaveFrirmanUserId; argguide.Guidlist = guidPoint; argguide.IsEnd = false; argguide.SendUserID = CurrentUserInfo.mySelf.Id; argguide.gameObjID = GetComponent().gameObjID; NetworkManager.Default.SendAsync("TRAPPED_GUIDANCE_SYNC", argguide); //TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs(); //arg.hitPoint = guidPoint[0]; //targetPosition = arg.hitPoint; ////arg.gameObjID = GetComponent().gameObjID; //arg.gameObjIdSelf = GetComponent().gameObjID; //TrappedPathFindingCommand.Instance.Execute(GetComponent().gameObjID, arg); CloneGameObjInfo msg = GetComponent(); Transform safe = P_SafeArea.transform.GetChild(0); msg.buildNum = safe.GetComponent().buildNum; msg.floorNum = safe.GetComponent().floorNum; msg.interlayerNum = safe.GetComponent().interlayerNum; //StartCoroutine(checkguide()); } } IEnumerator checkguide() { while (Guidance && !OverMoveOrGuidance) { yield return new WaitForSeconds(10f); if (Vector3.Distance(transform.position, guidPoint[0]) > 1f) { if (CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id) { TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs(); arg.hitPoint = guidPoint[0]; TargetPosition = guidPoint[0]; arg.gameObjIdSelf = GetComponent().gameObjID; TrappedPathFindingCommand.Instance.Execute(GetComponent().gameObjID, arg); } } } } private void AddGuidIndex() { //if (!Guidance) //{ // return; //} //if (GuidIndex >= guidPoint.Count - 1) //{ // //movestate = MoveState.IDLE; // return; //} //GuidIndex++; guidPoint.Remove(guidPoint[0]); TargetPosition = guidPoint[0]; if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id) { TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs(); arg.hitPoint = guidPoint[0]; TargetPosition = guidPoint[0]; arg.gameObjIdSelf = GetComponent().gameObjID; TrappedPathFindingCommand.Instance.Execute(GetComponent().gameObjID, arg); } } void Start() { P_Disasters = GameObject.Find("P_AllParent").transform.Find("P_Disasters"); P_SafeArea = GameObject.Find("P_AllParent/P_Tools/P_SafeArea").transform; p_fireman = GameObject.Find("P_AllParent/P_Person/P_Fireman").transform; basehaemal = GetComponent(); originalpoint = transform.position; //firemanList = GetComponentInChildren().FireMenList; nav = GetComponent(); anim = GetComponent(); anim.SetFloat("Speed", 0); if (GetComponent()) { Haemal = GetComponent().Haemal; } //GameSettings.othersSettings.isStartDrill = true; DrillStart = GameSettings.othersSettings.isStartDrill; //被克隆出来时就已经开始演练 if (DrillStart) { GetDangerousList(); dangerousDetection(); if (MeetDangerous) { if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id) { Vector3 dia = transform.position - DangerousLastmet; TargetPosition = dia; TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs(); arg.hitPoint = transform.position + dia; arg.gameObjIdSelf = GetComponent().gameObjID; TrappedPathFindingCommand.Instance.Execute(GetComponent().gameObjID, arg); } } InvokeRepeating("RandomPoint", 0f, 3f/*randominvoketime()*/); } } public void FallDown() { if (GetComponent().enabled) { GetComponent().enabled = false; // GetComponent().enabled = true; //transform.Find("Trigger").GetComponent().center = GetComponent().center; nav.SetDestination(transform.position); TargetPosition = transform.position; } } void Update() { DrillStart = GameSettings.othersSettings.isStartDrill; //移动 //演练已经开始 if (DrillStart) { //if (!IsselfClient) //{ // return; //} if (IsBefirstAirOrMoving) { return; } distance = Vector3.Distance(transform.position, TargetPosition); //arrive = Vector3.Distance(targetPosition, transform.position); Haemal = GetComponent().Haemal; if (Haemal <= 50) { //被困人员倒下后设置碰撞器 //FallDown(); if (movestate != MoveState.FALLDOWN) { movestate = MoveState.FALLDOWN; anim.SetFloat("Speed", 0); anim.SetBool("FallDown", true); //nav.SetDestination(transform.position); TargetPosition = transform.position; GetComponent().pathFindEnable = false; //设置碰撞器 GetComponent().center = Vector3.zero; GetComponent().radius = 0.7f; GetComponent().height = 1f; nav.enabled = false; } if (Guidance) { Guidance = false; } if (falldownlock == false && IsMoveState) { IsMoveState = false; if (MoveFireman != null) { MessageDispatcher.SendMessage("Trapped_Down", GetComponent().gameObjID); } } IsMoveState = false; Guidance = false; GetComponent().pathFindEnable = false; return; } if (OverMoveOrGuidance) { if (firemanHit) { firemanHit = false; } if (anim.GetFloat("Speed") > 0) { anim.SetFloat("Speed", 0f); } if (movestate != MoveState.IDLE) { movestate = MoveState.IDLE; } return; } MoveStateSet(); AniamtorSet(); // arrive = Vector3.Distance(transform.position, targetPosition); #region //没有被消防员引导和移动,随机移动 if (!Guidance && !IsMoveState && !firemanHit) { GetDangerousList(); dangerousDetection(); ////被使用救助技能的消防员点击 //if (firemanHit && !MeetDangerous) //{ // return; //} //消防员不在附近,随机移动 //if (!FireManNear) { if (IsInvoking() == false) { if (!firemanHit) InvokeRepeating("RandomPoint", 2f, 8f); } //检测范围内是否有危险 //碰到危险,重新随机一个点 if (MeetDangerous) { if (timer == 1) { //if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id) //{ // Vector3 dia = transform.position - DangerousLastmet; // targetPosition = dia; // TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs(); // arg.hitPoint = transform.position + dia; // arg.MeetDangerous = true; // //arg.gameObjID = GetComponent().gameObjID; // arg.gameObjIdSelf = GetComponent().gameObjID; // TrappedPathFindingCommand.Instance.Execute(GetComponent().gameObjID, arg); //} StartCoroutine(randompoint(0.2f)); } timer -= Time.deltaTime; if (timer <= 0) { timer = 1f; } } } ////附近有消防员, 暂时停止移动 //else //{ // CancelInvoke("RandomPoint"); // movestate = MoveState.IDLE; //} } else if (!Guidance && !IsMoveState && firemanHit && !MeetDangerous) { if (IsInvoking() == true) { // CancelInvokeRandom(); // StartCoroutine(WaitForFireman()); } } else if (IsBefirstAirOrMoving) { if (firemanHit) { firemanHit = false; } if (IsInvoking() == true) { CancelInvokeRandom(); } } //被消防员引导,按规划点位移动 else if (Guidance || IsMoveState) { if (firemanHit) { firemanHit = false; } if (MeetDangerous) { Debug.LogWarning("引导中遇险"); } CancelInvoke("RandomPoint"); //引导 if (Guidance) { if (guidPoint.Count == 1 /*&& Vector3.Distance(transform.position, guidPoint[0]) < 2*/) { if (TargetPosition!=guidPoint[0]) { Debug.Log("" + "sssssssss"+ ""); TargetPosition = guidPoint[0]; if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id) { TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs(); arg.hitPoint = guidPoint[0]; TargetPosition = guidPoint[0]; arg.gameObjIdSelf = GetComponent().gameObjID; TrappedPathFindingCommand.Instance.Execute(GetComponent().gameObjID, arg); } } if (Vector3.Distance(transform.position, guidPoint[0]) < 2) { Guidance = false; movestate = MoveState.IDLE; GetComponent().StopAllCoroutines(); GetComponent().enabled = false; OverMoveOrGuidance = true; TrappedTime.CheckStopTime(); anim.SetFloat("Speed", 0); //InputManager.GuidanceList.Clear(); //InputManager.IsGuidance = false; if (IsselfClient)//本客户端触发的引导提示信息 { LoadPromptWin.Instance.LoadTextPromptWindow("被困人员到达引导目标位置", 1f); } TrappedGuidanceSyncData argguide = new TrappedGuidanceSyncData(); argguide.IsEnd = true; argguide.SendUserID = CurrentUserInfo.mySelf.Id; argguide.gameObjID = GetComponent().gameObjID; NetworkManager.Default.SendAsync("TRAPPED_GUIDANCE_SYNC", argguide); MessageDispatcher.SendMessage("SomeoneOutOfTrap"); //通知火场信息-疏散救生-被困时间部分更新,看是否可以停止计时 return; } } else if (guidPoint.Count > 1) { if (!guidPoint.Contains(TargetPosition)) { AddGuidIndex(); } if (Vector3.Distance(transform.position, guidPoint[0]) < 2) { AddGuidIndex(); } } else { } } //被移动 if (IsMoveState) { if (MoveFireman != null) { TargetPosition = transform.position; if (Vector3.Distance(transform.position, MoveFireman.transform.position) > 2) { Vector3 offset = -MoveFireman.transform.forward; nav.SetDestination(MoveFireman.transform.position + offset); movestate = MoveState.MOVEFREE; anim.SetFloat("Speed", 3.5f); } else { movestate = MoveState.IDLE; anim.SetFloat("Speed", 0); } } } //if (Vector3.Distance(transform.position, targetPosition) < 0.1) //{ // OverMoveOrGuidance = true; //} } #endregion } } /// /// 随机移动点位 /// /// void RandomPoint() { //if (!IsselfClient) // { // return; // } //if (MeetDangerous) //{ // MeetDangerous = false; //} if (IsMoveState) { Debug.Log("移动状态调用"); } if (Guidance) { Debug.Log("引导状态调用"); } if (!firemanHit && !IsBefirstAirOrMoving) { if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id) { float rang = UnityEngine.Random.Range(4f, 8f); StartCoroutine(randompoint(rang)); } } else { Debug.Log("在消防员点击状态下调用"); } } IEnumerator randompoint(float rang) { movestate = MoveState.IDLE; yield return new WaitForSeconds(rang); Vector2 randomcicle = UnityEngine.Random.insideUnitCircle; randomVector = new Vector3(originalpoint.x + randomcicle.x * MaxRange, originalpoint.y, originalpoint.z + randomcicle.y * MaxRange); TargetPosition = randomVector; //nav.destination = randomVector; TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs(); arg.hitPoint = randomVector; arg.MeetDangerous = false; arg.gameObjIdSelf = GetComponent().gameObjID; TrappedPathFindingCommand.Instance.Execute(GetComponent().gameObjID, arg); MeetDangerous = false; } //延迟方法调用时间间隔 int randominvoketime() { return UnityEngine.Random.Range(2, 5); } void AniamtorSet() { if (Haemal <= 50) { return; } if (nav.enabled==false) { return; } if (movestate == MoveState.IDLE) { nav.SetDestination(transform.position); anim.SetFloat("Speed", 0); } if (movestate == MoveState.MOVEFREE) { //if (MeetDangerous && !Guidance && !IsMoveState) //{ // anim.SetFloat("Speed", 3.5f); //} //if (!MeetDangerous && !Guidance && !IsMoveState) //{ // anim.SetFloat("Speed", 2f); //} if (Guidance && !IsSetPoint) { anim.SetFloat("Speed", 2.5f); } else { anim.SetFloat("Speed", 1f); } } if (movestate == MoveState.FALLDOWN) { anim.SetFloat("Speed", 0); anim.SetBool("FallDown", true); nav.SetDestination(transform.position); TargetPosition = transform.position; GetComponent().pathFindEnable = false; } if (Haemal > 50) { if (anim.GetFloat("Speed") < 0.1f) { movestate = MoveState.IDLE; } } } void MoveStateSet() { if (Haemal <= 50) { if (movestate != MoveState.FALLDOWN) { movestate = MoveState.FALLDOWN; } } else { if (OverMoveOrGuidance) { movestate = MoveState.IDLE; } else { if (Vector3.Distance(transform.position, TargetPosition) > 1 && TargetPosition != Vector3.zero /*&& !Guidance && !IsMoveState*/) { movestate = MoveState.MOVEFREE; } if (Vector3.Distance(transform.position, TargetPosition) <= 1 && TargetPosition != Vector3.zero /*&& !Guidance && !IsMoveState&&!MeetDangerous*/) { movestate = MoveState.IDLE; } if (MeetDangerous) { movestate = MoveState.MOVEFREE; } if (firemanHit) { movestate = MoveState.IDLE; } //if (FireManNear && !IsMoveState && !Guidance) //{ // //transform.LookAt(firemanList[0].transform); // movestate = MoveState.IDLE; //} if (Guidance && !IsSetPoint) { movestate = MoveState.MOVEFREE; } if (Guidance && IsSetPoint) { movestate = MoveState.IDLE; } if (isBefirstAirOrMoving) { movestate = MoveState.IDLE; } } } //if (Guidance) //{ // movestate = MoveState.GUIDED; //} } /// /// 获取周围的危险列表 /// void GetDangerousList() { DangerousList.Clear(); CloneGameObjInfo[] allDisaster = P_Disasters.GetComponentsInChildren(); for (int i = 0; i < allDisaster.Length; i++) { if (allDisaster[i].gameObjType == CloneObjType.dangerousGoods || allDisaster[i].gameObjType == CloneObjType.fireNormal || allDisaster[i].gameObjType == CloneObjType.fireBreakThrough || allDisaster[i].gameObjType == CloneObjType.LiquidLevel || allDisaster[i].gameObjType == CloneObjType.SpreadedFire/* || allDisaster[i].gameObjType == CloneObjType.smokeNormal || allDisaster[i].gameObjType == CloneObjType.smokeIndoor1 || allDisaster[i].gameObjType == CloneObjType.smokeIndoor2*/) { if (scenetype != SceneType.化工建筑) { //现检测高度范围为低于1.2(地面下0.2),高于2米(头上1米) if (transform.position.y - allDisaster[i].transform.position.y < 1.2 || allDisaster[i].transform.position.y - transform.position.y < 2) { //检测范围以内的 if (Vector3.Distance(transform.position, allDisaster[i].transform.position) < MetDangerousDistance) { if (Vector3.Distance(transform.position, allDisaster[i].transform.position) <= MetDangerousDistance) { if ((allDisaster[i].gameObjType == CloneObjType.fireNormal && allDisaster[i].GetComponent().enabled == true)) { DangerousList.Add(allDisaster[i].gameObject); } else if (allDisaster[i].gameObjType != CloneObjType.fireNormal) { DangerousList.Add(allDisaster[i].gameObject); } } } } } else { //化工暂时不限高 if (transform.position.y - allDisaster[i].transform.position.y < 1.2) { //检测范围以内的 if (Vector3.Distance(transform.position, allDisaster[i].transform.position) < MetDangerousDistance) { if (Vector3.Distance(transform.position, allDisaster[i].transform.position) <= MetDangerousDistance) { if ((allDisaster[i].gameObjType == CloneObjType.fireNormal && allDisaster[i].GetComponent().enabled == true)) { DangerousList.Add(allDisaster[i].gameObject); } else if (allDisaster[i].gameObjType != CloneObjType.fireNormal) { DangerousList.Add(allDisaster[i].gameObject); } } } } } } } } /// /// 当前角色能否检测到危险列表中的物体 /// void dangerousDetection() { if (DangerousList.Count < 1) { return; } for (int i = 0; i < DangerousList.Count; i++) { Vector3 dir = DangerousList[i].transform.position - transform.position; //目前视角为120度 if (Vector3.Dot(new Vector3(dir.x, 0, dir.z).normalized, transform.forward.normalized) > 0.2) { DangerousLastmet = DangerousList[i].transform.position; if (Haemal > 50) { movestate = MoveState.MOVEFREE; } MeetDangerous = true; } } } public void CancelInvokeRandom() { CancelInvoke("RandomPoint"); } IEnumerator firstAidText() { LoadPromptWin.Instance.LoadTextPromptWindow("正在实施急救", 5f); yield return new WaitForSeconds(5.5f); LoadPromptWin.Instance.LoadTextPromptWindow("实施急救成功", 2f); } IEnumerator WaitForFireman() { //等待消防员同步 if (IsselfClient) { movestate = MoveState.IDLE; var arg = new TrappedWaitFiremanSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = GetComponent().gameObjID; arg.IsWait = true; arg.Waitposition = transform.position; NetworkManager.Default.SendAsync("TRAPPED_WAIT_FIREMAN_SYNC", arg); } // nav.enabled = false; //TrappedPathFindingCmdArgs cmdarg = new TrappedPathFindingCmdArgs(); //cmdarg.hitPoint = transform.position; //cmdarg.gameObjIdSelf = GetComponent().gameObjID; //TrappedPathFindingCommand.Instance.Execute(GetComponent().gameObjID, cmdarg); nav.SetDestination(transform.position); CancelInvokeRandom(); GetComponent().StopAllCoroutines(); TargetPosition = transform.position; movestate = MoveState.IDLE; yield return new WaitForSeconds(3f); firemanHit = false; //nav.enabled = true; if (IsselfClient) { var warg = new TrappedWaitFiremanSyncData(); warg.SendUserID = CurrentUserInfo.mySelf.Id; warg.gameObjID = GetComponent().gameObjID; warg.IsWait = false; warg.Waitposition = transform.position; NetworkManager.Default.SendAsync("TRAPPED_WAIT_FIREMAN_SYNC", warg); } //InvokeRepeating("RandomPoint", 0f, 3f); } private IntData addMyRescue(IntData data) { if (OverMoveOrGuidance == true) { data.value += 1; } return data; } private IntData addMyUnrescue(IntData data) { if (OverMoveOrGuidance == false) { data.value += 1; } return data; } private IntData addMyTrapped(IntData data) { data.value += 1; return data; } //public IEnumerator WaitForFiremanNotext() //{ // firemanHit = true; // CancelInvoke("RandomPoint"); // nav.SetDestination(transform.position); // targetPosition = transform.position; // yield return new WaitForSeconds(3f); // firemanHit = false; //} }