48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using System;
|
|
using Code.OfficeGame.BattleMode.Actions;
|
|
using KinematicCharacterController;
|
|
using Reflex.Attributes;
|
|
using UnityEngine;
|
|
|
|
namespace Code.OfficeGame.Player
|
|
{
|
|
public class EntityAnimator : MonoBehaviour
|
|
{
|
|
private static readonly int VelocityForward = Animator.StringToHash("VelocityForward");
|
|
private static readonly int VelocityRight = Animator.StringToHash("VelocityRight");
|
|
private static readonly int Attack = Animator.StringToHash("Attack");
|
|
|
|
|
|
private KinematicCharacterMotor _motor;
|
|
public Animator Animator { get; private set; }
|
|
public EntityTimelineActor EntityTimelineActor { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
_motor = GetComponent<KinematicCharacterMotor>();
|
|
Animator = GetComponentInChildren<Animator>();
|
|
EntityTimelineActor = GetComponent<EntityTimelineActor>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
var forwardVelocity =
|
|
Vector3.Project(_motor.Velocity, transform.right).magnitude;
|
|
Animator.SetFloat(VelocityForward, forwardVelocity);
|
|
|
|
var rightVelocity =
|
|
Vector3.Project(_motor.Velocity, transform.forward).magnitude;
|
|
Animator.SetFloat(VelocityRight, rightVelocity);
|
|
|
|
if(EntityTimelineActor.CurrentAction)
|
|
switch (EntityTimelineActor.CurrentAction.ActionType)
|
|
{
|
|
case BattleActionType.Wait:
|
|
break;
|
|
case BattleActionType.Attack:
|
|
Animator.SetTrigger(Attack);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |