2023-08-27 02:58:19 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using BITKit.Animations;
|
|
|
|
using BITKit.Entities;
|
|
|
|
using BITKit.StateMachine;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BITFALL.Player.Animation
|
|
|
|
{
|
|
|
|
public interface IPlayerAnimationState : IState
|
|
|
|
{
|
|
|
|
void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState);
|
|
|
|
}
|
2023-10-30 01:25:53 +08:00
|
|
|
public class PlayerAnimationController : StateBasedBehavior<IPlayerAnimationState>
|
2023-08-27 02:58:19 +08:00
|
|
|
{
|
2023-10-20 19:31:12 +08:00
|
|
|
|
2023-08-27 02:58:19 +08:00
|
|
|
[SerializeField] internal UnityAnimator animator;
|
|
|
|
|
|
|
|
private IEntityMovement _movement;
|
|
|
|
private static readonly int Vertical = Animator.StringToHash("Vertical");
|
|
|
|
private static readonly int Horizontal = Animator.StringToHash("Horizontal");
|
|
|
|
private static readonly int SqrMagnitude = Animator.StringToHash("SqrMagnitude");
|
|
|
|
|
|
|
|
public override void OnAwake()
|
|
|
|
{
|
|
|
|
base.OnAwake();
|
2023-10-30 01:25:53 +08:00
|
|
|
_movement = UnityEntity.Get<IEntityMovement>();
|
2023-08-27 02:58:19 +08:00
|
|
|
_movement.OnStateChanged += OnMovementStateChanged;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnFixedUpdate(float deltaTime)
|
|
|
|
{
|
|
|
|
animator.animator.SetFloat(Vertical, _movement.LocomotionBasedVelocity.z);
|
|
|
|
animator.animator.SetFloat(Horizontal, _movement.LocomotionBasedVelocity.x);
|
|
|
|
animator.animator.SetFloat(SqrMagnitude, _movement.LocomotionBasedVelocity.sqrMagnitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
|
|
|
|
{
|
|
|
|
foreach (var x in StateDictionary.Values)
|
|
|
|
{
|
|
|
|
x.OnMovementStateChanged(arg1,arg2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|