2023-08-27 02:58:19 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2024-04-26 03:55:43 +08:00
|
|
|
using System.Security;
|
2024-02-21 01:40:53 +08:00
|
|
|
using Animancer;
|
2024-04-26 03:55:43 +08:00
|
|
|
using BITFALL.Cosmetic;
|
|
|
|
using BITFALL.HotFix;
|
2024-03-31 23:34:22 +08:00
|
|
|
using BITFALL.Player.Animation.States;
|
2023-11-30 00:23:23 +08:00
|
|
|
using BITFALL.Player.Movement;
|
|
|
|
using BITKit;
|
2023-08-27 02:58:19 +08:00
|
|
|
using BITKit.Animations;
|
|
|
|
using BITKit.Entities;
|
|
|
|
using BITKit.StateMachine;
|
2024-04-26 03:55:43 +08:00
|
|
|
using Cysharp.Threading.Tasks;
|
2023-08-27 02:58:19 +08:00
|
|
|
using UnityEngine;
|
2023-11-30 00:23:23 +08:00
|
|
|
using UnityEngine.Animations.Rigging;
|
2023-08-27 02:58:19 +08:00
|
|
|
|
|
|
|
namespace BITFALL.Player.Animation
|
|
|
|
{
|
|
|
|
public interface IPlayerAnimationState : IState
|
|
|
|
{
|
|
|
|
void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState);
|
|
|
|
}
|
2024-04-19 00:40:34 +08:00
|
|
|
[CustomType(typeof(PlayerAnimationController))]
|
2023-10-30 01:25:53 +08:00
|
|
|
public class PlayerAnimationController : StateBasedBehavior<IPlayerAnimationState>
|
2023-08-27 02:58:19 +08:00
|
|
|
{
|
2024-04-19 00:40:34 +08:00
|
|
|
[SerializeField] private AnimancerComponent animancerComponent;
|
2023-11-30 00:23:23 +08:00
|
|
|
|
2024-04-26 03:55:43 +08:00
|
|
|
[SerializeReference, SubclassSelector] private IReference handIKRig;
|
|
|
|
[SerializeReference, SubclassSelector] private IReference leftIKRig;
|
|
|
|
[SerializeReference, SubclassSelector] private IReference rightIKRig;
|
2024-04-19 00:40:34 +08:00
|
|
|
|
2024-04-26 03:55:43 +08:00
|
|
|
[Inject] public IEntityMovement Movement;
|
|
|
|
[Inject] public IHealth Health;
|
|
|
|
[Inject] public PlayerSocketService PlayerSocketService;
|
|
|
|
[Inject] private ICosmeticService _cosmeticService;
|
2023-08-27 02:58:19 +08:00
|
|
|
|
2024-04-19 00:40:34 +08:00
|
|
|
public AnimancerComponent AnimancerComponent => animancerComponent;
|
2023-08-27 02:58:19 +08:00
|
|
|
public override void OnAwake()
|
|
|
|
{
|
|
|
|
base.OnAwake();
|
2024-04-26 03:55:43 +08:00
|
|
|
Movement.OnStateChanged += OnMovementStateChanged;
|
2023-11-30 00:23:23 +08:00
|
|
|
|
2024-04-26 03:55:43 +08:00
|
|
|
Movement.OnCommand += OnCommand;
|
|
|
|
Health.OnSetAlive += OnSetAlive;
|
|
|
|
|
2024-04-19 00:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnSetAlive(bool obj)
|
|
|
|
{
|
|
|
|
AnimancerComponent.enabled = obj;
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
2023-11-30 00:23:23 +08:00
|
|
|
|
2024-03-31 23:34:22 +08:00
|
|
|
public override void OnStart()
|
|
|
|
{
|
|
|
|
base.OnStart();
|
|
|
|
TransitionState<Walk>();
|
|
|
|
}
|
2023-11-30 00:23:23 +08:00
|
|
|
private void OnCommand(object obj)
|
|
|
|
{
|
|
|
|
switch (obj)
|
|
|
|
{
|
|
|
|
case OnPlayerJumpCommand:
|
|
|
|
UnityEntity.Invoke<string>(Constant.Animation.Play,BITConstant.Player.Jump);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-08-27 02:58:19 +08:00
|
|
|
public override void OnFixedUpdate(float deltaTime)
|
|
|
|
{
|
2024-04-19 00:40:34 +08:00
|
|
|
//animator.animator.SetFloat(Vertical, _movement.LocomotionBasedVelocity.z);
|
|
|
|
//animator.animator.SetFloat(Horizontal, _movement.LocomotionBasedVelocity.x);
|
|
|
|
//animator.animator.SetFloat(SqrMagnitude, _movement.Velocity.GetLength() / _movement.ReferenceSpeed);
|
2023-11-30 00:23:23 +08:00
|
|
|
|
2024-04-19 00:40:34 +08:00
|
|
|
//animator.animator.SetFloat(Pitch,-MathV.TransientRotationAxis(_movement.ViewRotation.eulerAngles.x));
|
2023-11-30 00:23:23 +08:00
|
|
|
|
2024-02-21 01:40:53 +08:00
|
|
|
CurrentState?.OnStateUpdate(deltaTime);
|
|
|
|
|
2024-04-26 03:55:43 +08:00
|
|
|
UnityEntity.SetDirect(BITHash.Player.IsGrounded,Movement.IsGrounded);
|
|
|
|
|
|
|
|
|
2023-08-27 02:58:19 +08:00
|
|
|
}
|
|
|
|
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
|
|
|
|
{
|
|
|
|
foreach (var x in StateDictionary.Values)
|
|
|
|
{
|
|
|
|
x.OnMovementStateChanged(arg1,arg2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|