using Axibug.Runtime; using UnityEngine; using Axibug; using Axibug.Event; namespace Game { public class MainPlayerComponent : GameComponent { public Transform MainCamNode; public Transform CamPos; public MainRole Player; /// /// 摄像机Fov TODO后续应该移动到摄像机管理 /// public float srcCameraFov; //Rigidbody mRigidbody; public bool bLoadFinish { get; private set; } = false; public bool InGame = false; private void OnEnable() { MainCamNode = transform.Find("MainCamNode"); CamPos = MainCamNode.Find("CamPos"); InGame = false; } private void OnDisable() { } public void ReSetMainPlayer() { Player = null; } void Start() { } void Update() { Update_MoveForInput(); //test if (Input.GetKeyDown(KeyCode.Z)) GamePlayEntry.BulletMgr.AddBulletRun(GamePlayEntry.MainPlayer.Player.transform.position, "1"); if (Input.GetKeyDown(KeyCode.X)) GamePlayEntry.BulletMgr.AddBulletRun(GamePlayEntry.MainPlayer.Player.transform.position, "2"); } public void LoadPlayer() { bLoadFinish = false; Player = GamePlayEntry.RoleMgr.CreateMainRole(); //摄像机 SetMainCamera(); bLoadFinish = true; } public void SetMainCamera() { //挂上摄像机震动脚本 MainCamNode.gameObject.AddComponent(); //把摄像机Node挂到玩家下 MainCamNode.parent = Player.transform; MainCamNode.localPosition = Vector3.zero; MainCamNode.localEulerAngles = Vector3.zero; //把主摄像机挂到MainCamNode的CamPos下 Camera.main.transform.parent = CamPos; Camera.main.transform.localPosition = Vector3.zero; Camera.main.transform.localEulerAngles = Vector3.zero; srcCameraFov = Camera.main.fieldOfView; } public void Update_MoveForInput() { if (!Player) return; Player.InputV2 = GamePlayEntry.Input.InputV2; //如果处于攻击 后续不执行 if (Player.AttackStep == E_ONCEATTACK_STEP.InAttack) return; if (GamePlayEntry.Input.Attack) { //AxibugLog.Debug("DoAttack"); DoNextMotionAnimeName(); return; } if (Player.JumpStep == E_JUMP_STEP.None && GamePlayEntry.Input.Jump) { //AxibugLog.Debug("Jump"); //TODO 放在这里是否合适? 动作驱动 Player.ChangeJumpState(E_JUMP_STEP.JumpUp); return; } } public void DoNextMotionAnimeName() { Player.Anime.BackToIdle(); string AnimeName; string AtkBoxAnimeName; //是否是最终招式 bool IsEndMotion = false; //一次也没按下 if (GamePlayEntry.Input.mInputMotionData.CheckHistoryLastMotion(E_MOTION_TYPE.Attack_2)) { AnimeName = "Attack_3"; AtkBoxAnimeName = "HorizontalCut_Down"; GamePlayEntry.Input.mInputMotionData.AddMontionKey(E_MOTION_TYPE.Attack_3); IsEndMotion = true; //结束动作 } else if(GamePlayEntry.Input.mInputMotionData.CheckHistoryLastMotion(E_MOTION_TYPE.Attack_1)) { AnimeName = "Attack_2"; AtkBoxAnimeName = "HorizontalCut_Up"; GamePlayEntry.Input.mInputMotionData.AddMontionKey(E_MOTION_TYPE.Attack_2); } else { AnimeName = "Attack_1"; AtkBoxAnimeName = "HorizontalCut_Down"; GamePlayEntry.Input.mInputMotionData.AddMontionKey(E_MOTION_TYPE.Attack_1); } Player.Anime.SetAttack(AnimeName); Player.DoAtkBox(AtkBoxAnimeName); if(IsEndMotion) GamePlayEntry.Input.mInputMotionData.ClearHistoryMotion(); } } }