void checkPlayerMoveDir() { if (IsCheckMoreNextPath) { CheckMoreNextPathDir(); return; } if (AimMarkTran == null) { return; } Vector3 vecA = AimMarkTran.forward; Vector3 vecB = AimMarkTran.position - PlayerTran.position; Vector3 vecC = PlayerTran.forward; vecA.y = vecB.y = vecC.y = 0f; float cosAC = Vector3.Dot(vecA, vecC); float cosAB = Vector3.Dot(vecA, vecB); float cosBC = Vector3.Dot(vecB, vecC); if (cosAC < 0f && cosBC < 0f && !GameOverCtrl.GetInstance().CheckIsActiveOver()) { if (!IsDonotTurnRight && !IsDonotTurnLeft && (AutoFireScript.PathKeyState == 0 || IntoPuBuCtrl.IsIntoPuBu || PlayerAutoFire.IsRestartMove)) { if (bIsTurnRight) { IsDonotTurnRight = true; IsDonotTurnLeft = false; } else if (bIsTurnLeft) { IsDonotTurnRight = false; IsDonotTurnLeft = true; } } SetIsDirWrong(true); } else { IsDonotTurnRight = false; IsDonotTurnLeft = false; SetIsDirWrong(false); if (cosBC <= 0f && cosAB <= 0f) { ParentPath = AimMarkTran.parent; //next path AiMark markScript = AimMarkTran.GetComponent <AiMark>(); if (markScript == null) { return; } mBakeTimePointPos = AimMarkTran.position; mBakeTimePointRot = AimMarkTran.forward; AutoFireScript.SetPlayerPreMark(AimMarkTran); int conutTmp = AimMarkTran.parent.childCount - 1; int markCount = markScript.getMarkCount(); AimMarkTran = markScript.mNextMark; if (markCount == conutTmp) { if (AimMarkTran == null) { //player run to end this.enabled = false; // IsRunToEndPoint = true; DaoJiShiCtrl.GetInstance().StopDaoJiShi(); GameOverCtrl.GetInstance().HiddenContinueGame(); FinishPanelCtrl.GetInstance().ShowFinishPanel(); AutoFireScript.SetPlayerMvSpeed(0f); //AutoFireScript.CloseWaterParticle(); return; } AiPathCtrlTran = AimMarkTran.parent; //next path AutoFireScript.SetPathKeyState(AiPathCtrlTran.GetComponent <AiPathCtrl>()); if (ParentPath != null) { AiParentPathScript = ParentPath.GetComponent <AiPathCtrl>(); if (AiParentPathScript.GetNextPathNum() > 1) { IsCheckMoreNextPath = true; } } } } } }
void OnFinishMoveAiPlayerByPath() { AiPathCtrl pathScript = AimMarkTran.parent.GetComponent <AiPathCtrl>(); int rv = pathScript.GetNextPathNum(); if (rv > 0) { int key = 0; Transform trNextPath = null; while (trNextPath == null) { int randVal = Random.Range(0, 1000) % 3; switch (randVal) { case 0: trNextPath = pathScript.mNextPath1; break; case 1: trNextPath = pathScript.mNextPath2; break; case 2: trNextPath = pathScript.mNextPath3; break; } key++; if (key > 2) { if (pathScript.mNextPath1 != null) { trNextPath = pathScript.mNextPath1; } else if (pathScript.mNextPath2 != null) { trNextPath = pathScript.mNextPath2; } else if (pathScript.mNextPath3 != null) { trNextPath = pathScript.mNextPath3; } break; } } if (trNextPath != null) { AimMarkTran = trNextPath.GetChild(0); } } else { Invoke("MoveAiPlayerToEndPos", 0.05f); return; } SetPlayerPathCount(); AiPathCtrlTran = AimMarkTran.parent; if (AimMarkTran != null) { AiMark markAimScript = AimMarkTran.GetComponent <AiMark>(); pathScript = AiPathCtrlTran.GetComponent <AiPathCtrl>(); SetPlayerAimMarkData(pathScript.PathIndex, markAimScript.getMarkCount(), PlayerTran.name); UpdateAiPlayerAction(); } Invoke("MoveAiPlayerByItween", 0.05f); }
void CheckMoreNextPathDir() { if (AiParentPathScript == null) { return; } bool isDirRight = false; //int [] DirTag = new int[3]; //DirTag: 0 -> dir is wrong, 1 -> dir is right. Transform [] aimMarkTranArray = new Transform[3]; aimMarkTranArray[0] = AiParentPathScript.mNextPath1; aimMarkTranArray[1] = AiParentPathScript.mNextPath2; aimMarkTranArray[2] = AiParentPathScript.mNextPath3; Transform aimMarkTran = null; Vector3 vecA = Vector3.zero; Vector3 vecB = Vector3.zero; Vector3 vecC = Vector3.zero; float cosAC = 0f; float cosAB = 0f; float cosBC = 0f; for (int i = 0; i < 3; i++) { if (aimMarkTranArray[i] == null) { continue; } aimMarkTran = aimMarkTranArray[i].GetChild(0); if (aimMarkTran == null) { continue; } vecA = aimMarkTran.forward; vecB = aimMarkTran.position - PlayerTran.position; vecC = PlayerTran.forward; vecA.y = vecB.y = vecC.y = 0f; cosAC = Vector3.Dot(vecA, vecC); cosAB = Vector3.Dot(vecA, vecB); cosBC = Vector3.Dot(vecB, vecC); if (cosAC < 0f && cosBC < 0f) { //dir is wrong. } else { isDirRight = true; float disAB = Vector3.Distance(vecB, Vector3.zero); if (cosAB <= 0f && disAB < 15f) { IsCheckMoreNextPath = false; ParentPath = aimMarkTran.parent; AimMarkTran = aimMarkTran; AiMark markScript = AimMarkTran.GetComponent <AiMark>(); if (markScript == null) { continue; } mBakeTimePointPos = AimMarkTran.position; mBakeTimePointRot = AimMarkTran.forward; AutoFireScript.SetPlayerPreMark(AimMarkTran); int conutTmp = AimMarkTran.parent.childCount - 1; int markCount = markScript.getMarkCount(); AimMarkTran = markScript.mNextMark; AiPathCtrlTran = AimMarkTran.parent; AutoFireScript.SetPathKeyState(AiPathCtrlTran.GetComponent <AiPathCtrl>()); if (markCount == conutTmp) { if (AimMarkTran == null) { //player run to end this.enabled = false; DaoJiShiCtrl.GetInstance().StopDaoJiShi(); GameOverCtrl.GetInstance().HiddenContinueGame(); FinishPanelCtrl.GetInstance().ShowFinishPanel(); AutoFireScript.SetPlayerMvSpeed(0f); //AutoFireScript.CloseWaterParticle(); return; } AiPathCtrlTran = AimMarkTran.parent; //next path AutoFireScript.SetPathKeyState(AiPathCtrlTran.GetComponent <AiPathCtrl>()); if (ParentPath != null) { AiParentPathScript = ParentPath.GetComponent <AiPathCtrl>(); if (AiParentPathScript.GetNextPathNum() > 1) { IsCheckMoreNextPath = true; } } } return; } } } if (isDirRight && !AutoFireScript.CheckPlayerIsMoveDirWrong()) { IsDonotTurnRight = false; IsDonotTurnLeft = false; SetIsDirWrong(false); } else { if (!IsDonotTurnRight && !IsDonotTurnLeft && (AutoFireScript.PathKeyState == 0 || IntoPuBuCtrl.IsIntoPuBu || PlayerAutoFire.IsRestartMove)) { if (bIsTurnRight) { IsDonotTurnRight = true; IsDonotTurnLeft = false; } else if (bIsTurnLeft) { IsDonotTurnRight = false; IsDonotTurnLeft = true; } } SetIsDirWrong(true); } }