BITFALL/Assets/Artists/Scripts/Player/PlayerAnimationController/PlayerAnimationController.cs

91 lines
2.5 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Security;
using Animancer;
using BITFALL.Cosmetic;
using BITFALL.HotFix;
using BITFALL.Player.Animation.States;
using BITFALL.Player.Movement;
using BITKit;
using BITKit.Animations;
using BITKit.Entities;
using BITKit.StateMachine;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.Animations.Rigging;
namespace BITFALL.Player.Animation
{
public interface IPlayerAnimationState : IState
{
void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState);
}
[CustomType(typeof(PlayerAnimationController))]
public class PlayerAnimationController : StateBasedBehavior<IPlayerAnimationState>
{
[SerializeField] private AnimancerComponent animancerComponent;
[SerializeReference, SubclassSelector] private IReference handIKRig;
[SerializeReference, SubclassSelector] private IReference leftIKRig;
[SerializeReference, SubclassSelector] private IReference rightIKRig;
[Inject] public IEntityMovement Movement;
[Inject] public IHealth Health;
[Inject] public PlayerSocketService PlayerSocketService;
[Inject] private ICosmeticService _cosmeticService;
public AnimancerComponent AnimancerComponent => animancerComponent;
public override void OnAwake()
{
base.OnAwake();
Movement.OnStateChanged += OnMovementStateChanged;
Movement.OnCommand += OnCommand;
Health.OnSetAlive += OnSetAlive;
}
private void OnSetAlive(bool obj)
{
AnimancerComponent.enabled = obj;
}
public override void OnStart()
{
base.OnStart();
TransitionState<Walk>();
}
private void OnCommand(object obj)
{
switch (obj)
{
case OnPlayerJumpCommand:
UnityEntity.Invoke<string>(Constant.Animation.Play,BITConstant.Player.Jump);
break;
}
}
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.Velocity.GetLength() / _movement.ReferenceSpeed);
//animator.animator.SetFloat(Pitch,-MathV.TransientRotationAxis(_movement.ViewRotation.eulerAngles.x));
CurrentState?.OnStateUpdate(deltaTime);
UnityEntity.SetDirect(BITHash.Player.IsGrounded,Movement.IsGrounded);
}
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
{
foreach (var x in StateDictionary.Values)
{
x.OnMovementStateChanged(arg1,arg2);
}
}
}
}