using Axibug; using Axibug.Runtime; using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR; namespace Game { public abstract class RoleBase : MonoBehaviour { public E_NODE_TYPE RoleType => mBaseData.RoleType; public long RoleID => mBaseData.innate.roleid; public ICharMachineBase Anime => mAnime; public Vector2 InputV2; public bool mIsMove = false; public bool mIsLeft = false; bool LastIsMove = false; bool LastIsLeft = false; /// /// 动画控制器 /// protected ICharMachineBase mAnime; protected S_ROLE_DATA_BASE mBaseData; protected Transform mBridgeTransfrom; protected Transform mModelTransfrom; protected Rigidbody mRigidbody; Vector3 Angle_RightDir => Vector3.zero; Vector3 Angle_LeftDir = new Vector3(0,180,0); protected virtual void Awake() { mBridgeTransfrom = transform.Find("Bridge"); mModelTransfrom = mBridgeTransfrom.Find("Model"); mRigidbody = transform.GetComponent(); } protected virtual void OnEnable() { mIsMove = false; LastIsMove = false; mIsLeft = false; LastIsLeft = false; MeshChangeDir(mIsLeft); } /// /// 初始化 /// /// public virtual void Init(S_ROLE_DATA_BASE data) { mBaseData = data; if (RoleType == E_NODE_TYPE.N_MAINPLAYER) { mAnime = new CharacterMachine(); mAnime.InitMachine(mModelTransfrom); } else if (RoleType == E_NODE_TYPE.N_MONSTER) { } else if (RoleType == E_NODE_TYPE.N_NPC) { } } protected virtual void Update() { #region 移动 //是否移动 bool ToMoveState = false; if (InputV2 != Vector2.zero) ToMoveState = true; if (LastIsMove != ToMoveState) { AxibugLog.Debug("MeshChangeState =>" + ToMoveState); MeshChangeState(ToMoveState); } LastIsMove = ToMoveState; Move_currentVector = new Vector3(InputV2.x, 0, InputV2.y); AxibugLog.Debug("Move_currentVector =>" + Move_currentVector); #endregion //朝向 bool ToLeftDir = false; bool bChange = false; if (InputV2.x < 0) { ToLeftDir = true; bChange = true; } else if (InputV2.x > 0) { ToLeftDir = false; bChange = true; } if (bChange && LastIsLeft != ToLeftDir) { AxibugLog.Debug("MeshChangeDir =>" + ToLeftDir); MeshChangeDir(ToLeftDir); LastIsLeft = ToLeftDir; } } protected virtual void FixedUpdate() { FixedUpdate_Move(); } public abstract void MeshChangeState(bool ToMoveState); public void MeshChangeDir(bool ToLeftDir) { mBridgeTransfrom.localEulerAngles = ToLeftDir ? Angle_LeftDir : Angle_RightDir; } public abstract void Release(); #region /// /// 速度 /// public float Move_Speed = 3.5f; private Vector3 Move_currentVector; void FixedUpdate_Move() { Vector3 _playerPos = mRigidbody.position; _playerPos += Move_currentVector * Move_Speed * Time.deltaTime; mRigidbody.MovePosition(_playerPos); AxibugLog.Debug("FixedUpdate_Move =>" + _playerPos); } #endregion } }