276 lines
7.1 KiB
C#
276 lines
7.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
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; }
|
|
protected IPlayerAnimationState entryState;
|
|
public virtual void Initialize()
|
|
{
|
|
|
|
}
|
|
|
|
public virtual void OnStateEntry(IState old)
|
|
{
|
|
entryState = old as IPlayerAnimationState;
|
|
}
|
|
|
|
public virtual void OnStateUpdate(float deltaTime)
|
|
{
|
|
}
|
|
|
|
public virtual void OnStateExit(IState old, IState newState)
|
|
{
|
|
}
|
|
|
|
public virtual void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
}
|
|
protected virtual void Exit()
|
|
{
|
|
if (Enabled is false) return;
|
|
switch (entryState)
|
|
{
|
|
case IPlayerWalkState:
|
|
animationController.TransitionState<Walk>();
|
|
break;
|
|
case IPlayerCrouchState:
|
|
animationController.TransitionState<Crouch>();
|
|
break;
|
|
case IPlayerSprintState:
|
|
animationController.TransitionState<Sprint>();
|
|
break;
|
|
default:
|
|
animationController.TransitionState<Walk>();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class Walk : PlayerAnimateStates,IPlayerWalkState
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.CrossFade(old switch
|
|
{
|
|
IPlayerRunState or IPlayerSprintState=> "Walk.Stop",
|
|
IPlayerLinkState { LinkArea: 5 } => "Walk.ExitClimb",
|
|
_=>BITConstant.Player.Walk
|
|
},old switch
|
|
{
|
|
IPlayerRunState or IPlayerSprintState=> 0.08f,
|
|
IPlayerSlideState or IPlayerCrouchState => 0.32f,
|
|
_=>0.16f
|
|
});
|
|
}
|
|
|
|
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,IPlayerRunState
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
base.OnStateEntry(old);
|
|
animationController.animator.Play(BITConstant.Player.Run);
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if(Enabled &&newState is not IPlayerRunState)Exit();
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class Sprint : PlayerAnimateStates,IPlayerSprintState
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.Play(BITConstant.Player.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,IPlayerCrouchState
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.Play(BITConstant.Player.Crouch);
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if (Enabled is false) return;
|
|
if(newState is not IPlayerCrouchState)
|
|
animationController.TransitionState<Walk>();
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class Parachute : PlayerAnimateStates
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.Play(BITConstant.Player.Parachute);
|
|
}
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if(newState is IPlayerParachuteState)
|
|
animationController.TransitionState<Parachute>();
|
|
else if(Enabled && newState is not IPlayerKnockdownState)
|
|
{
|
|
animationController.TransitionState<Walk>();
|
|
}
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class Slide : PlayerAnimateStates
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.Play(BITConstant.Player.Slide);
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if(newState is IPlayerSlideState)
|
|
animationController.TransitionState<Slide>();
|
|
else if(Enabled && newState is not IPlayerKnockdownState)
|
|
{
|
|
animationController.TransitionState<Walk>();
|
|
}
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public class Knockdown : PlayerAnimateStates
|
|
{
|
|
[SerializeField] private AnimatorOverrideController animatorOverrideController;
|
|
private RuntimeAnimatorController _initialController;
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
_initialController = animationController.animator.animator.runtimeAnimatorController;
|
|
}
|
|
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.animator.runtimeAnimatorController = animatorOverrideController;
|
|
animationController.animator.Play(BITConstant.Player.Walk);
|
|
}
|
|
|
|
public override void OnStateExit(IState old, IState newState)
|
|
{
|
|
animationController.animator.animator.runtimeAnimatorController = _initialController;
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if (newState is IPlayerKnockdownState)
|
|
{
|
|
animationController.TransitionState<Knockdown>();
|
|
}
|
|
else if(Enabled)
|
|
{
|
|
animationController.TransitionState<Walk>();
|
|
}
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class Link : PlayerAnimateStates,IPlayerLinkState
|
|
{
|
|
public int LinkArea { get; set; }
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
switch (LinkArea)
|
|
{
|
|
case 5:
|
|
animationController.animator.Play(BITConstant.Player.ClimbLadder);
|
|
break;
|
|
}
|
|
//animationController.animator.Play(BITConstant.Player._Run);
|
|
}
|
|
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
if (Enabled)
|
|
{
|
|
switch (newState)
|
|
{
|
|
case IPlayerWalkState:
|
|
animationController.TransitionState<Walk>();
|
|
break;
|
|
case IPlayerCrouchState:
|
|
animationController.TransitionState<Crouch>();
|
|
break;
|
|
case IPlayerSprintState:
|
|
animationController.TransitionState<Sprint>();
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (newState is IPlayerLinkState linkState)
|
|
{
|
|
LinkArea = linkState.LinkArea;
|
|
animationController.TransitionState<Link>();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class Fixed : PlayerAnimateStates
|
|
{
|
|
public override void OnStateEntry(IState old)
|
|
{
|
|
animationController.animator.Play(BITConstant.Player.Fixed);
|
|
}
|
|
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
|
{
|
|
base.OnMovementStateChanged(oldState, newState);
|
|
if(newState is IPlayerFixedState)
|
|
animationController.TransitionState<Fixed>();
|
|
else if(Enabled)
|
|
Exit();
|
|
}
|
|
}
|
|
}
|