158 lines
4.4 KiB
C#
158 lines
4.4 KiB
C#
using Axibug.Runtime;
|
|
using Bright.Serialization;
|
|
using System.IO;
|
|
using Game.Config;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using static Axibug.Utility;
|
|
using UnityEditor;
|
|
using Axibug.Resources;
|
|
using Axibug;
|
|
using Axibug.Event;
|
|
|
|
namespace Game
|
|
{
|
|
public class MainPlayerComponent : GameComponent
|
|
{
|
|
public Transform MainCamNode;
|
|
public Transform CamPos;
|
|
|
|
public MainRole Player;
|
|
|
|
/// <summary>
|
|
/// 摄像机Fov TODO后续应该移动到摄像机管理
|
|
/// </summary>
|
|
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;
|
|
AppEntry.Event.Subscribe(MainPlayerOnceAttackEventArgs.EventId, OnMainPlayerInAttackEventArgs);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
AppEntry.Event.Unsubscribe(MainPlayerOnceAttackEventArgs.EventId, OnMainPlayerInAttackEventArgs);
|
|
}
|
|
|
|
public void ReSetMainPlayer()
|
|
{
|
|
Player = null;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
Update_MoveForInput();
|
|
}
|
|
|
|
public void LoadPlayer()
|
|
{
|
|
bLoadFinish = false;
|
|
|
|
Player = GamePlayEntry.RoleMgr.CreateMainRole();
|
|
|
|
//摄像机
|
|
SetMainCamera();
|
|
|
|
bLoadFinish = true;
|
|
}
|
|
|
|
public void SetMainCamera()
|
|
{
|
|
//挂上摄像机震动脚本
|
|
MainCamNode.gameObject.AddComponent<CameraShake>();
|
|
|
|
//把摄像机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 (GamePlayEntry.Input.Attack
|
|
&&
|
|
Player.AttackStep != E_ONCEATTACK_STEP.InAttack
|
|
)
|
|
{
|
|
//AxibugLog.Debug("DoAttack");
|
|
DoNextMotionAnimeName();
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
#region 事件
|
|
|
|
private void OnMainPlayerInAttackEventArgs(object sender, LogicEventArgs e)
|
|
{
|
|
MainPlayerOnceAttackEventArgs msg = (MainPlayerOnceAttackEventArgs)e;
|
|
if (msg == null) throw new GameException("MainPlayerOnceAttackEventArgs is null");
|
|
if (msg.RoleID == Player.RoleID)
|
|
{
|
|
Player.AttackStep = msg.Step;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|