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

190 lines
5.3 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 bool mIsMove = false;
public bool mIsLeft = false;
public E_ONCEATTACK_STEP AttackStep = E_ONCEATTACK_STEP.None;
bool LastIsMove = false;
bool LastIsLeft = false;
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()
{
mIsMove = false;
LastIsMove = false;
mIsLeft = false;
LastIsLeft = 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()
{
#region ÒƯ
if (AttackStep != E_ONCEATTACK_STEP.None)
{
LastIsMove = false;
Move_currentVector = Vector3.zero;
}
else
{
//ÊÇ·ñÒƶ¯
bool ToMoveState = false;
if (InputV2 != Vector2.zero)
ToMoveState = true;
if (LastIsMove != ToMoveState)
{
//AxibugLog.Debug("MeshChangeMoveState =>" + ToMoveState);
MeshChangeMoveState(ToMoveState);
}
LastIsMove = ToMoveState;
Move_currentVector = new Vector3(InputV2.x, 0, InputV2.y);
//AxibugLog.Debug("Move_currentVector =>" + Move_currentVector);
//³¯Ïò
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;
}
}
#endregion
}
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
/// <summary>
/// ËÙ¶È
/// </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
#region ¹¥»÷ºÐ×Ó¯»­»ú
public void DoAtkBox(string AtkBoxAnimeName)
{
AttackBoxAnime.Play(AtkBoxAnimeName);
}
#endregion
}
}