-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace constructstatemachine node by a custom k2 node, add delegates…
… in state machines and other features. add StateMachine component
- Loading branch information
Showing
10 changed files
with
529 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
Source/UT_Framework/Private/Component/StateMachine/StateMachineComponent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/************************************************************************/ | ||
/* UMBRA TOOLS */ | ||
/* Maxwell - Axel Clerget */ | ||
/************************************************************************/ | ||
|
||
#include "StateMachineComponent.h" | ||
#include "Kismet/GameplayStatics.h" | ||
|
||
// Sets default values for this component's properties | ||
UStateMachineComponent::UStateMachineComponent() | ||
{ | ||
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features | ||
// off to improve performance if you don't need them. | ||
PrimaryComponentTick.bCanEverTick = false; | ||
} | ||
|
||
|
||
// Called when the game starts | ||
void UStateMachineComponent::BeginPlay() | ||
{ | ||
Super::BeginPlay(); | ||
|
||
if (AutoStart) | ||
this->Start(); | ||
} | ||
|
||
void UStateMachineComponent::BeginDestroy() | ||
{ | ||
this->UnbindDelegates(); | ||
this->Stop(); | ||
|
||
Super::BeginDestroy(); | ||
} | ||
|
||
FState UStateMachineComponent::GetCurrentState() | ||
{ | ||
if (this->StateMachine) | ||
return this->StateMachine->GetCurrentState(); | ||
|
||
return FState(); | ||
} | ||
|
||
void UStateMachineComponent::Start() | ||
{ | ||
if (StateMachine == nullptr) | ||
{ | ||
this->StateMachine = UStateMachine::ConstructStateMachine(Template, this, UGameplayStatics::GetPlayerController(this, 0)); | ||
|
||
if (this->StateMachine) | ||
{ | ||
this->BindDelegates(); | ||
this->StateMachine->Start(); | ||
} | ||
} | ||
else | ||
this->StateMachine->Start(); | ||
} | ||
|
||
void UStateMachineComponent::Stop() | ||
{ | ||
if (this->StateMachine) | ||
StateMachine->Stop(); | ||
} | ||
|
||
FString UStateMachineComponent::GetCurrentStateName() | ||
{ | ||
if (this->StateMachine) | ||
return this->StateMachine->GetCurrentStateName(); | ||
|
||
return FString(); | ||
} | ||
|
||
void UStateMachineComponent::Pause() | ||
{ | ||
if (this->StateMachine) | ||
this->StateMachine->Pause(); | ||
} | ||
|
||
void UStateMachineComponent::UnPaused() | ||
{ | ||
if (this->StateMachine) | ||
this->StateMachine->UnPaused(); | ||
} | ||
|
||
bool UStateMachineComponent::IsPaused() const | ||
{ | ||
if (this->StateMachine) | ||
this->StateMachine->IsPaused(); | ||
|
||
return false; | ||
} | ||
|
||
bool UStateMachineComponent::IsValid() const | ||
{ | ||
return this->StateMachine->IsValidLowLevel(); | ||
} | ||
|
||
void UStateMachineComponent::BindDelegates() | ||
{ | ||
this->StateMachine->OnInit.AddDynamic(this, &UStateMachineComponent::OnInitTriggered); | ||
this->StateMachine->OnStart.AddDynamic(this, &UStateMachineComponent::OnStartTriggered); | ||
this->StateMachine->OnStop.AddDynamic(this, &UStateMachineComponent::OnStopTriggered); | ||
this->StateMachine->OnPause.AddDynamic(this, &UStateMachineComponent::OnPauseTriggered); | ||
this->StateMachine->OnUnPause.AddDynamic(this, &UStateMachineComponent::OnUnPauseTriggered); | ||
} | ||
|
||
void UStateMachineComponent::UnbindDelegates() | ||
{ | ||
if (this->OnInit.IsBound()) | ||
this->OnInit.RemoveDynamic(this, &UStateMachineComponent::OnInitTriggered); | ||
|
||
if (this->OnStart.IsBound()) | ||
this->OnStart.RemoveDynamic(this, &UStateMachineComponent::OnStartTriggered); | ||
|
||
if (this->OnStop.IsBound()) | ||
this->OnStop.RemoveDynamic(this, &UStateMachineComponent::OnStopTriggered); | ||
|
||
if (this->OnPause.IsBound()) | ||
this->OnPause.RemoveDynamic(this, &UStateMachineComponent::OnPauseTriggered); | ||
|
||
if (this->OnUnPause.IsBound()) | ||
this->OnUnPause.RemoveDynamic(this, &UStateMachineComponent::OnUnPauseTriggered); | ||
} | ||
|
||
void UStateMachineComponent::OnInitTriggered() | ||
{ | ||
this->OnInit.Broadcast(); | ||
} | ||
|
||
void UStateMachineComponent::OnStartTriggered() | ||
{ | ||
this->OnStart.Broadcast(); | ||
} | ||
|
||
void UStateMachineComponent::OnStopTriggered() | ||
{ | ||
this->StateMachine = nullptr; | ||
this->UnbindDelegates(); | ||
this->OnStop.Broadcast(); | ||
} | ||
|
||
void UStateMachineComponent::OnPauseTriggered() | ||
{ | ||
this->OnPause.Broadcast(); | ||
} | ||
|
||
void UStateMachineComponent::OnUnPauseTriggered() | ||
{ | ||
this->OnUnPause.Broadcast(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Source/UT_Framework/Private/Object/StateMachine/StateMachineCallbackProxy.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/************************************************************************/ | ||
/* UMBRA TOOLS */ | ||
/* Maxwell - Axel Clerget */ | ||
/************************************************************************/ | ||
|
||
#include "StateMachineCallbackProxy.h" | ||
#include "StateMachine.h" | ||
#include "GameFramework/PlayerController.h" | ||
|
||
UStateMachineCallbackProxy::UStateMachineCallbackProxy(const FObjectInitializer& ObjectInitializer) | ||
: Super(ObjectInitializer) | ||
{ | ||
} | ||
|
||
UStateMachineCallbackProxy* UStateMachineCallbackProxy::CreateProxyObjectForConstructStateMachine(TSubclassOf<UStateMachine> Template, UObject* Owner, APlayerController* Controller) | ||
{ | ||
UStateMachineCallbackProxy* Proxy = NewObject<UStateMachineCallbackProxy>(); | ||
Proxy->SetFlags(RF_StrongRefOnFrame); | ||
|
||
if (UStateMachine* StateMachine = UStateMachine::ConstructStateMachine(Template, Owner, Controller)) | ||
{ | ||
Proxy->OnCompleted.Broadcast(StateMachine); | ||
} | ||
else | ||
Proxy->OnFailed.Broadcast(nullptr); | ||
|
||
return Proxy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.