// Use this for initialization void Start() { _Instance = this; pcvr.DongGanState = 1; PlayerZhuanXiangVal = GameCtrlXK.PlayerZhuanXiangPTVal; if (IsTestShootCartoon) { return; } if (HuanYingFuObj == null) { Debug.LogError("HuanYingFuObj is null"); HuanYingFuObj.name = "null"; } else { HuanYingFuObj.SetActive(false); } PlayerTran = transform; rigObj = GetComponent <Rigidbody>(); if (GetComponent <Animator>() != null) { Debug.LogWarning("Player Animator should be remove"); PlayerTran = null; PlayerTran.name = "null"; } AutoFireScript = GetComponent <PlayerAutoFire>(); ScreenWaterParticle.gameObject.SetActive(false); ChuanShenScript = GetComponentInChildren <ChuanShenCtrl>(); ChuanLunZiScript = GetComponentInChildren <ChuanLunZiCtrl>(); ZhuJiaoNanScript = GetComponentInChildren <ZhuJiaoNan>(); mGameTime = 1000; SetCamAimInfo(); CreatePlayerNeedObj(); AiPathCtrlTran = GameCtrlXK.GetInstance().AiPathCtrlTran.GetChild(0); AutoFireScript.SetPathKeyState(AiPathCtrlTran.GetComponent <AiPathCtrl>()); AimMarkTran = AiPathCtrlTran.GetChild(0); mBakeTimePointPos = AimMarkTran.position; mBakeTimePointRot = AimMarkTran.forward; AutoFireScript.SetPlayerPreMark(AimMarkTran); CreateFlyNpcAimCube(); if (GameCtrlXK.GetInstance().PlayerMarkTest != null) { AiPathCtrlTran = GameCtrlXK.GetInstance().PlayerMarkTest.parent; AutoFireScript.SetPathKeyState(AiPathCtrlTran.GetComponent <AiPathCtrl>()); AimMarkTran = GameCtrlXK.GetInstance().PlayerMarkTest; mBakeTimePointPos = AimMarkTran.position; mBakeTimePointRot = AimMarkTran.forward; AutoFireScript.SetPlayerPreMark(AimMarkTran); PlayerTran.position = mBakeTimePointPos; PlayerTran.forward = mBakeTimePointRot; } }
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); } }