130 lines
3.1 KiB
C#
130 lines
3.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITFALL.Player.Movement;
|
|
using BITKit.Entities;
|
|
using BITKit.StateMachine;
|
|
using UnityEngine;
|
|
// ReSharper disable UnassignedField.Global
|
|
|
|
namespace BITFALL.Player.Animation.States
|
|
{
|
|
public abstract class PlayerAnimateStates : IPlayerAnimationState
|
|
{
|
|
[SerializeField] protected PlayerAnimationController animationController;
|
|
public virtual bool Enabled { get; set; }
|
|
public virtual void Initialize()
|
|
{
|
|
|
|
}
|
|
|
|
public virtual void OnStateEntry(IState old)
|
|
{
|
|
}
|
|
|
|
public virtual void OnStateUpdate(float deltaTime)
|
|
{
|
|
}
|
|
|
|
public virtual void OnStateExit(IState old, IState newState)
|
|
{
|
|
}
|
|
|
|
public virtual void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class Walk : PlayerAnimateStates
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
|
|
animationController.animator.Play(old switch
|
|
{
|
|
IPlayerRunState or IPlayerSprintState=> "Walk.Stop",
|
|
_=>PlayerAnimationController._Walk
|
|
});
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if (Enabled is false) return;
|
|
switch (newState)
|
|
{
|
|
case IPlayerRunState:
|
|
animationController.TransitionState<Run>();
|
|
break;
|
|
case IPlayerCrouchState:
|
|
animationController.TransitionState<Crouch>();
|
|
break;
|
|
case IPlayerSprintState:
|
|
animationController.TransitionState<Sprint>();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class Run : PlayerAnimateStates
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.Play(PlayerAnimationController._Run);
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if (Enabled is false) return;
|
|
switch (newState)
|
|
{
|
|
case IPlayerWalkState:
|
|
animationController.TransitionState<Walk>();
|
|
break;
|
|
case IPlayerCrouchState:
|
|
animationController.TransitionState<Crouch>();
|
|
break;
|
|
case IPlayerSprintState:
|
|
animationController.TransitionState<Sprint>();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class Sprint : PlayerAnimateStates
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.Play(PlayerAnimationController._Sprint);
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if (Enabled is false) return;
|
|
switch (newState)
|
|
{
|
|
case IPlayerWalkState:
|
|
animationController.TransitionState<Walk>();
|
|
break;
|
|
case IPlayerCrouchState:
|
|
animationController.TransitionState<Crouch>();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class Crouch : PlayerAnimateStates
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.Play(PlayerAnimationController._Crouch);
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if (Enabled is false) return;
|
|
if(newState is not IPlayerCrouchState)
|
|
animationController.TransitionState<Walk>();
|
|
}
|
|
}
|
|
}
|