129 lines
2.6 KiB
C#
Raw Normal View History

2025-09-24 11:24:38 +05:00
namespace TPSBR
{
using UnityEngine;
using Fusion.Addons.KCC;
using Fusion.Addons.AnimationController;
using AnimationState = Fusion.Addons.AnimationController.AnimationState;
public sealed class FullBodyLayer : AnimationLayer
{
// PUBLIC MEMBERS
public JumpState Jump => _jump;
public FallState Fall => _fall;
public LandState Land => _land;
public DeadState Dead => _dead;
public JetpackState Jetpack => _jetpack;
// PRIVATE MEMBERS
[SerializeField]
private JumpState _jump;
[SerializeField]
private FallState _fall;
[SerializeField]
private LandState _land;
[SerializeField]
private DeadState _dead;
[SerializeField]
private JetpackState _jetpack;
2025-10-22 20:43:17 +05:00
[SerializeField][Tooltip("Crouch animation state. Assign your crouch clip/state here.")]
private CrouchState _crouch;
2025-09-24 11:24:38 +05:00
private KCC _kcc;
2025-10-22 20:43:17 +05:00
private Character _character;
2025-09-24 11:24:38 +05:00
// AnimationState INTERFACE
protected override void OnInitialize()
{
_kcc = Controller.GetComponentNoAlloc<KCC>();
2025-10-22 20:43:17 +05:00
_character = Controller.GetComponentNoAlloc<Character>();
2025-09-24 11:24:38 +05:00
}
protected override void OnFixedUpdate()
{
KCCData kccData = _kcc.FixedData;
2025-10-22 20:43:17 +05:00
// Crouch animation handling
if (_crouch != null)
{
bool isCrouched = _character != null && _character.IsCrouched;
if (isCrouched == true && kccData.IsGrounded == true)
{
_crouch.Activate(0.1f);
}
else
{
_crouch.Deactivate(0.1f);
}
}
2025-09-24 11:24:38 +05:00
if (kccData.HasJumped == true)
{
_jump.Activate(0.2f);
return;
}
AnimationState activeState = GetActiveState();
if (activeState == null)
{
if (kccData.IsGrounded == false && kccData.WasGrounded == false)
{
_fall.Activate(0.2f);
}
return;
}
if (activeState == _jump)
{
if (kccData.IsGrounded == true)
{
if (kccData.InputDirection.IsAlmostZero(0.1f) == true)
{
_land.Activate(0.2f);
}
else
{
_jump.Deactivate(0.1f);
}
}
else if (_jump.IsFinished(1.0f) == true)
{
_fall.Activate(0.2f);
}
}
else if (activeState == _fall)
{
if (kccData.IsGrounded == true)
{
if (kccData.InputDirection.IsAlmostZero(0.1f) == true)
{
_land.Activate(0.1f);
}
else
{
_fall.Deactivate(0.1f);
}
}
}
else if (activeState == _land)
{
if (kccData.IsGrounded == true)
{
if (kccData.InputDirection.IsAlmostZero(0.1f) == false)
{
_land.Deactivate(0.1f);
}
}
if (_land.IsFinished(1.0f) == true)
{
_land.Deactivate(0.1f);
}
}
}
}
}