AkiraPixelWind/Assets/Scripts/Main/Role/RoleBase.cs
2023-01-09 23:13:17 +08:00

215 lines
5.8 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 int RoleID => mBaseData.innate.roleid;
public S_ROLE_DATA_BASE BaseData => mBaseData;
public ICharMachineBase Anime => mAnime;
public Animator AttackBoxAnime;
public AttackBox AttackBoxCollider;
public Vector2 InputV2;
public E_ONCEATTACK_STEP AttackStep = E_ONCEATTACK_STEP.None;
public Transform ModelTransfrom { get { return mModelTransfrom; } }
public Transform BridgeTransfrom { get { return mBridgeTransfrom; } }
/// <summary>
/// ¶¯»­¿ØÖÆÆ÷
/// </summary>
protected ICharMachineBase mAnime;
protected S_ROLE_DATA_BASE mBaseData;
protected Transform mBridgeTransfrom;
protected Transform mModelTransfrom;
protected Rigidbody mRigidbody;
protected Collider mselfCollider;
protected virtual void Awake()
{
mBridgeTransfrom = transform.Find("Bridge");
mModelTransfrom = mBridgeTransfrom.Find("Model");
mselfCollider = transform.GetComponent<Collider>();
mRigidbody = transform.GetComponent<Rigidbody>();
}
protected virtual void OnEnable()
{
IsMove = false;
IsLeft = false;
AttackStep = E_ONCEATTACK_STEP.None;
MeshChangeDir(mIsLeft);
}
protected virtual void OnDisable()
{
}
/// <summary>
/// ³õʼ»¯
/// </summary>
/// <param name="data"></param>
public virtual void Init(S_ROLE_DATA_BASE data)
{
mBaseData = data;
if (RoleType == E_NODE_TYPE.N_MAINPLAYER)
{
mAnime = new CharacterMachine();
mAnime.InitMachine(mModelTransfrom, data);
}
else if (RoleType == E_NODE_TYPE.N_MONSTER)
{
mAnime = new CharacterMachine();
mAnime.InitMachine(mModelTransfrom, data);
}
else if (RoleType == E_NODE_TYPE.N_NPC)
{
}
}
public virtual void SetAttackBoxAnime(Animator attackBoxAnime)
{
AttackBoxAnime = attackBoxAnime;
AttackBoxCollider = attackBoxAnime.transform.Find("Node1/Box1").GetComponent<AttackBox>();
AttackBoxCollider.InitNode(this);
}
protected virtual void Update()
{
Update_Move();
}
protected virtual void FixedUpdate()
{
FixedUpdate_Move();
}
public abstract void MeshChangeMoveState(bool ToMoveState);
public void MeshChangeDir(bool ToLeftDir)
{
mBridgeTransfrom.localEulerAngles = ToLeftDir ? ConstClass.Angle_LeftDir : ConstClass.Angle_RightDir;
}
public abstract void Release();
#region ÒƯ
private bool mIsMove = false;
public float MoveTime = 0;
public bool IsMove
{
get { return mIsMove; }
set{ if (mIsMove != value)
{
mIsMove = value;
if (value)//¸Õ¿ªÊ¼Òƶ¯
{
MoveTime = 0;
MeshChangeMoveState(true);
}
else//¸ÕÍ£Ö¹Òƶ¯
{
MoveTime = 0;
Move_currentVector = Vector3.zero;//Çå¿ÕÒƶ¯·½Ïò
MeshChangeMoveState(false);
}
}
}
}
/// <summary>
/// ³¯Ïò
/// </summary>
private bool mIsLeft = false;
public bool IsLeft
{
get { return mIsLeft; }
set{ if (mIsLeft != value)
{
mIsLeft = value;
MoveTime = 0;//³¯Ïò±ä»¯Ê±£¬ÖØÖÃÒƶ¯Ê±¼ä
if (value)//¿ªÊ¼ÍùÓÒ
MeshChangeDir(true);
else//¿ªÊ¼Íù×ó
MeshChangeDir(false);
}
}
}
void Update_Move()
{
bool isDoMove = false;
if (AttackStep != E_ONCEATTACK_STEP.None)
{
//Èç¹ûÔÚ¹¥»÷Á÷³Ì ¾Í²»Òƶ¯
}
else
{
if (InputV2 != Vector2.zero)
{
isDoMove = true;
Move_currentVector = new Vector3(InputV2.x, 0, InputV2.y);
}
//AxibugLog.Debug("Move_currentVector =>" + Move_currentVector);
//³¯Ïò
if (InputV2.x < 0)
IsLeft = true;
else if (InputV2.x > 0)
IsLeft = false;
}
IsMove = isDoMove;
}
/// <summary>
/// ËÙ¶È
/// </summary>
protected float Move_BaseSpeed = 3.5f;
protected float Move_SpeedMultiplier = 1f;
private Vector3 Move_currentVector;
/// <summary>
/// Òƶ¯Î»ÒÆ
/// </summary>
void FixedUpdate_Move()
{
if (IsMove) MoveTime += Time.deltaTime;
Vector3 _playerPos = mRigidbody.position;
_playerPos += Move_currentVector * Move_BaseSpeed * Move_SpeedMultiplier * Time.deltaTime;
mRigidbody.MovePosition(_playerPos);
//AxibugLog.Debug("FixedUpdate_Move =>" + _playerPos);
}
#endregion
#region ¹¥»÷ºÐ×Ó¯»­»ú
public void DoAtkBox(string AtkBoxAnimeName)
{
AttackBoxAnime.Play(AtkBoxAnimeName);
}
#endregion
}
}