2023-06-03 22:38:35 +00:00
|
|
|
// Unreal Fighting Engine by Kevin Poretti
|
2023-06-03 18:37:14 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-06-04 19:56:36 +00:00
|
|
|
// FE includes
|
|
|
|
#include "UnrealFightingEngine/IFESystemInterface.h"
|
|
|
|
|
|
|
|
// UE includes
|
2023-06-03 18:37:14 +00:00
|
|
|
#include "CoreMinimal.h"
|
|
|
|
#include "Components/ActorComponent.h"
|
|
|
|
|
2023-06-04 19:56:36 +00:00
|
|
|
#include "FEStateMachineComponent.generated.h"
|
2023-06-03 18:37:14 +00:00
|
|
|
|
2023-06-04 19:56:36 +00:00
|
|
|
/**
|
|
|
|
* A state machine is a component that evaluates and controls the transitions for state objects that
|
|
|
|
* are a part of this state machine.
|
|
|
|
*
|
|
|
|
* This component also calls the appropriate state logic when a state is changed or the component ticks.
|
|
|
|
*/
|
2023-06-03 18:37:14 +00:00
|
|
|
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
|
|
|
|
class UNREALFIGHTINGENGINE_API UFEStateMachineComponent : public UActorComponent, public IIFESystemInterface
|
|
|
|
{
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
|
|
public:
|
|
|
|
UFEStateMachineComponent();
|
|
|
|
|
2023-06-04 19:56:36 +00:00
|
|
|
/**
|
|
|
|
* Creates and adds default states and enters the first state
|
|
|
|
*/
|
|
|
|
void Initialize();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes pointers to what owns this state machine and what avatar this state represents.
|
|
|
|
*
|
|
|
|
* These pointers will also be passed to the states owned by this state machine.
|
|
|
|
*
|
|
|
|
* @param InOwner Actor that owns this state machine.
|
|
|
|
* @param InAvatar Actor that this state machine represents.
|
|
|
|
*/
|
|
|
|
virtual void InitActorInfo(AActor* InOwner, AActor* InAvatar);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an instance of the state class and adds newly created state to this state machine.
|
|
|
|
*
|
|
|
|
* @param StateClassToAdd State class type to be added to this state machine
|
|
|
|
*
|
|
|
|
* @return A pointer to the state that was added or nullptr if there was an issue adding or creating the state
|
|
|
|
*/
|
|
|
|
UFEState* AddState(TSubclassOf<UFEState> StateClassToAdd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an instance of the state classes and adds newly created states to this state machine.
|
|
|
|
*
|
|
|
|
* @param StateClassesToAdd Array of state class types to be added to this state machine
|
|
|
|
*/
|
|
|
|
void AddStates(const TArray<TSubclassOf<UFEState>>& StateClassesToAdd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the state with corresponding name and removes it from this state machine.
|
|
|
|
*/
|
|
|
|
void RemoveState(FName StateToRemove);
|
2023-06-03 18:37:14 +00:00
|
|
|
|
2023-06-04 19:56:36 +00:00
|
|
|
/**
|
|
|
|
* Transitions from CurrentState to the new state passed to this function
|
|
|
|
*
|
|
|
|
* Triggers the Exit callback on the CurrentState and the Enter callback on the new state
|
|
|
|
*/
|
|
|
|
void SwitchStates(UFEState* NewState);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of the current state
|
|
|
|
*/
|
|
|
|
UFUNCTION(BlueprintPure)
|
|
|
|
FName GetCurrentStateName() const;
|
|
|
|
|
|
|
|
// IIFESystemInterface interface
|
2023-06-03 18:37:14 +00:00
|
|
|
virtual void FixedTick(float OneFrame) override;
|
2023-06-04 19:56:36 +00:00
|
|
|
// End of IIFESystemInterface interface
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Actor that owns this state machine.
|
|
|
|
* This will typically be a player controller that possesses the avatar.
|
|
|
|
*/
|
|
|
|
UPROPERTY(BlueprintReadOnly)
|
|
|
|
AActor* Owner;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The avatar is an actor that this state machine represents.
|
|
|
|
* This will typically be a pawn or character the state machine is attached to.
|
|
|
|
*/
|
|
|
|
UPROPERTY(BlueprintReadOnly)
|
|
|
|
AActor* Avatar;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* States classes to create and add to this state machine when the game starts
|
|
|
|
*/
|
|
|
|
UPROPERTY(EditDefaultsOnly, Category="UFE|State Machine")
|
|
|
|
TArray<TSubclassOf<UFEState>> DefaultStates;
|
|
|
|
|
|
|
|
/** Current active state for this state machine */
|
|
|
|
UPROPERTY(BlueprintReadOnly)
|
|
|
|
UFEState* CurrentState;
|
|
|
|
|
|
|
|
// States that have been added
|
|
|
|
UPROPERTY(BlueprintReadOnly)
|
|
|
|
TArray<UFEState*> States;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the state with corresponding name
|
|
|
|
*/
|
|
|
|
UFEState* FindStateWithName(FName StateName);
|
|
|
|
|
|
|
|
// UActorComponent interface
|
|
|
|
virtual void BeginPlay() override;
|
|
|
|
// End of UActorComponent interface
|
2023-06-03 18:37:14 +00:00
|
|
|
};
|