AkiraPixelWind/Assets/Scripts/Main/Role/RoleBase.cs

149 lines
3.9 KiB
C#
Raw Normal View History

2023-01-05 00:28:20 +08:00
using Axibug;
using Axibug.Runtime;
using System;
using System.Collections.Generic;
using UnityEngine;
2023-01-05 18:32:58 +08:00
using UnityEngine.XR;
2023-01-05 00:28:20 +08:00
namespace Game
{
public abstract class RoleBase : MonoBehaviour
{
2023-01-05 18:32:58 +08:00
public E_NODE_TYPE RoleType => mBaseData.RoleType;
public long RoleID => mBaseData.innate.roleid;
public ICharMachineBase Anime => mAnime;
public Vector2 InputV2;
public bool mIsMove = false;
2023-01-06 00:14:59 +08:00
public bool mIsLeft = false;
bool LastIsMove = false;
bool LastIsLeft = false;
2023-01-05 00:28:20 +08:00
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
2023-01-05 18:32:58 +08:00
protected ICharMachineBase mAnime;
2023-01-05 00:28:20 +08:00
2023-01-05 18:32:58 +08:00
protected S_ROLE_DATA_BASE mBaseData;
2023-01-06 00:14:59 +08:00
protected Transform mBridgeTransfrom;
protected Transform mModelTransfrom;
protected Rigidbody mRigidbody;
2023-01-05 18:32:58 +08:00
2023-01-06 00:14:59 +08:00
Vector3 Angle_RightDir => Vector3.zero;
Vector3 Angle_LeftDir = new Vector3(0,180,0);
protected virtual void Awake()
2023-01-05 18:32:58 +08:00
{
2023-01-06 00:14:59 +08:00
mBridgeTransfrom = transform.Find("Bridge");
mModelTransfrom = mBridgeTransfrom.Find("Model");
mRigidbody = transform.GetComponent<Rigidbody>();
}
2023-01-05 18:32:58 +08:00
2023-01-06 00:14:59 +08:00
protected virtual void OnEnable()
{
mIsMove = false;
LastIsMove = false;
2023-01-05 18:32:58 +08:00
2023-01-06 00:14:59 +08:00
mIsLeft = false;
LastIsLeft = false;
2023-01-05 18:32:58 +08:00
2023-01-06 00:14:59 +08:00
MeshChangeDir(mIsLeft);
}
2023-01-05 00:28:20 +08:00
/// <summary>
/// <20><>ʼ<EFBFBD><CABC>
/// </summary>
/// <param name="data"></param>
public virtual void Init(S_ROLE_DATA_BASE data)
{
2023-01-05 18:32:58 +08:00
mBaseData = data;
if (RoleType == E_NODE_TYPE.N_MAINPLAYER)
2023-01-05 00:28:20 +08:00
{
2023-01-05 18:32:58 +08:00
mAnime = new CharacterMachine();
2023-01-06 00:14:59 +08:00
mAnime.InitMachine(mModelTransfrom);
2023-01-05 00:28:20 +08:00
}
2023-01-05 18:32:58 +08:00
else if (RoleType == E_NODE_TYPE.N_MONSTER)
2023-01-05 00:28:20 +08:00
{
}
2023-01-05 18:32:58 +08:00
else if (RoleType == E_NODE_TYPE.N_NPC)
2023-01-05 00:28:20 +08:00
{
}
}
2023-01-06 00:14:59 +08:00
protected virtual void Update()
{
#region <EFBFBD>ƶ<EFBFBD>
//<2F>Ƿ<EFBFBD><C7B7>ƶ<EFBFBD>
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
//<2F><><EFBFBD><EFBFBD>
bool ToLeftDir = false;
2023-01-06 17:55:47 +08:00
bool bChange = false;
2023-01-06 00:14:59 +08:00
if (InputV2.x < 0)
2023-01-06 17:55:47 +08:00
{
2023-01-06 00:14:59 +08:00
ToLeftDir = true;
2023-01-06 17:55:47 +08:00
bChange = true;
}
2023-01-06 00:14:59 +08:00
else if (InputV2.x > 0)
2023-01-06 17:55:47 +08:00
{
2023-01-06 00:14:59 +08:00
ToLeftDir = false;
2023-01-06 17:55:47 +08:00
bChange = true;
}
2023-01-06 00:14:59 +08:00
2023-01-06 17:55:47 +08:00
if (bChange && LastIsLeft != ToLeftDir)
2023-01-06 00:14:59 +08:00
{
AxibugLog.Debug("MeshChangeDir =>" + ToLeftDir);
MeshChangeDir(ToLeftDir);
2023-01-06 17:55:47 +08:00
LastIsLeft = ToLeftDir;
2023-01-06 00:14:59 +08:00
}
}
protected virtual void FixedUpdate()
{
FixedUpdate_Move();
}
public abstract void MeshChangeState(bool ToMoveState);
public void MeshChangeDir(bool ToLeftDir)
{
mBridgeTransfrom.localEulerAngles = ToLeftDir ? Angle_LeftDir : Angle_RightDir;
}
2023-01-05 00:28:20 +08:00
public abstract void Release();
2023-01-06 00:14:59 +08:00
#region
/// <summary>
/// <20>ٶ<EFBFBD>
/// </summary>
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
2023-01-05 00:28:20 +08:00
}
}