1
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "BITFALL.Player.AnimationController",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:1235ca61e7f433b408ed5a68767e7123",
|
||||
"GUID:7efac18f239530141802fb139776f333"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit.Animations;
|
||||
using BITKit.Entities;
|
||||
using BITKit.StateMachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Player.Animation
|
||||
{
|
||||
public interface IPlayerAnimationState : IState
|
||||
{
|
||||
void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState);
|
||||
}
|
||||
public class PlayerAnimationController : StateBasedComponent<IPlayerAnimationState>
|
||||
{
|
||||
public const string _Walk = "Walk";
|
||||
public const string _Run = "Run";
|
||||
public const string _Sprint = "Sprint";
|
||||
public const string _Crouch = "Crouch";
|
||||
[SerializeField] internal UnityAnimator animator;
|
||||
|
||||
private IEntityMovement _movement;
|
||||
private static readonly int Vertical = Animator.StringToHash("Vertical");
|
||||
private static readonly int Horizontal = Animator.StringToHash("Horizontal");
|
||||
private static readonly int SqrMagnitude = Animator.StringToHash("SqrMagnitude");
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_movement = entity.Get<IEntityMovement>();
|
||||
_movement.OnStateChanged += OnMovementStateChanged;
|
||||
}
|
||||
|
||||
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.LocomotionBasedVelocity.sqrMagnitude);
|
||||
}
|
||||
|
||||
private void OnMovementStateChanged(IEntityMovementState arg1, IEntityMovementState arg2)
|
||||
{
|
||||
foreach (var x in StateDictionary.Values)
|
||||
{
|
||||
x.OnMovementStateChanged(arg1,arg2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITFALL.Player.Movement;
|
||||
using BITKit.Entities;
|
||||
using BITKit.StateMachine;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Player.Animation.States
|
||||
{
|
||||
[Serializable]
|
||||
public class Climb : PlayerAnimateStates
|
||||
{
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
animationController.animator.Play("Climb");
|
||||
}
|
||||
public override void OnMovementStateChanged(IEntityMovementState oldState, IEntityMovementState newState)
|
||||
{
|
||||
if (newState is IPlayerClimbState)
|
||||
{
|
||||
animationController.TransitionState<Climb>();
|
||||
}
|
||||
else if(Enabled)
|
||||
{
|
||||
animationController.TransitionState<Walk>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user