FiE-Game/Assets/Scripts/Fie/Ponies/Fie.Ponies.Applejack/FieStateMachineApplejackBackstep.cs

108 lines
2.4 KiB
C#
Raw Normal View History

2018-11-20 20:10:49 +01:00
using Fie.Object;
using Spine;
using System;
using UnityEngine;
2023-07-24 21:52:50 +02:00
using Event = Spine.Event;
2018-11-20 20:10:49 +01:00
namespace Fie.Ponies.Applejack
{
public class FieStateMachineApplejackBackstep : FieStateMachineGameCharacterBase
{
private enum StepState
{
STEP_START,
STEPPING
}
private StepState _stepState;
private bool _isEnd;
public override void initialize(FieGameCharacter gameCharacter)
{
if (!(gameCharacter == null))
{
gameCharacter.isEnableAutoFlip = false;
}
}
public override void terminate(FieGameCharacter gameCharacter)
{
if (!(gameCharacter == null))
{
gameCharacter.isEnableCollider = true;
}
}
public override void updateState<T>(ref T gameCharacter)
{
if (gameCharacter is FieApplejack)
{
FieApplejack applejack = gameCharacter as FieApplejack;
if (_stepState == StepState.STEP_START)
{
if (applejack.groundState == FieObjectGroundState.Grounding)
{
TrackEntry trackEntry = null;
trackEntry = applejack.animationManager.SetAnimation(36, isLoop: false, isForceSet: true);
if (trackEntry != null)
{
2023-07-24 21:52:50 +02:00
trackEntry.Event += delegate(TrackEntry state, Event trackIndex)
2018-11-20 20:10:49 +01:00
{
2023-07-24 21:52:50 +02:00
if (trackIndex.Data.Name == "move")
2018-11-20 20:10:49 +01:00
{
2023-07-24 21:52:50 +02:00
Vector3 vector = applejack.flipDirectionVector * trackIndex.Float;
2018-11-20 20:10:49 +01:00
if (applejack.externalInputVector != Vector3.zero)
{
vector = applejack.externalInputVector;
vector.z = vector.y;
vector.y = 0f;
vector.Normalize();
2023-07-24 21:52:50 +02:00
vector *= 0f - trackIndex.Float;
2018-11-20 20:10:49 +01:00
vector.z *= 0.7f;
}
applejack.setFlipByVector(-vector);
applejack.resetMoveForce();
applejack.setMoveForce(vector, 0f, useRound: false);
applejack.applySideEffectOfStep();
}
2023-07-24 21:52:50 +02:00
if (trackIndex.Data.Name == "finished")
2018-11-20 20:10:49 +01:00
{
_isEnd = true;
}
2023-07-24 21:52:50 +02:00
if (trackIndex.Data.Name == "immunity")
2018-11-20 20:10:49 +01:00
{
2023-07-24 21:52:50 +02:00
applejack.isEnableCollider = (trackIndex.Int < 1);
2018-11-20 20:10:49 +01:00
}
};
trackEntry.Complete += delegate
{
_isEnd = true;
};
}
else
{
_isEnd = true;
}
}
else
{
_isEnd = true;
}
_stepState = StepState.STEPPING;
}
}
}
public override bool isEnd()
{
return _isEnd;
}
public override Type getNextState()
{
return typeof(FieStateMachineCommonIdle);
}
}
}