Last active
September 18, 2024 06:17
-
-
Save dmitrymatveev/65547fa215e24eccfc5f39bda52fa76c to your computer and use it in GitHub Desktop.
Unreal UObject implementing strategy pattern function.
This file contains hidden or 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
#include "SystemsContainerLite.h" | |
void UESLSystemsContainer::Execute(UObject* Context, UESLProcess *InCommand) | |
{ | |
InCommand->Error = NAME_None; | |
for (TObjectPtr<UESLSystem> ExecutionStep : Systems) | |
{ | |
if (InCommand->Error != NAME_None) | |
{ | |
return; | |
} | |
ExecutionStep->Execute(Context, InCommand); | |
} | |
} | |
void UESLSystem_Blueprint::Execute(UObject *Context, UESLProcess *InCommand) | |
{ | |
OnExecute(Context, InCommand); | |
} |
This file contains hidden or 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
#pragma once | |
#include "CoreMinimal.h" | |
#include "SystemsContainerLite.generated.h" | |
UCLASS(Blueprintable, abstract, ClassGroup=(EntitySystemLite), meta=(DisplayName="Process")) | |
class UESLProcess : public UObject | |
{ | |
GENERATED_BODY() | |
public: | |
UPROPERTY(BlueprintReadWrite) | |
FName Error; | |
}; | |
UCLASS(EditInlineNew, abstract, ClassGroup=(EntitySystemLite), meta=(DisplayName="System")) | |
class UESLSystem : public UObject | |
{ | |
GENERATED_BODY() | |
public: | |
virtual void Execute(UObject* Context, UESLProcess* InCommand) {}; | |
}; | |
UCLASS(Blueprintable, ClassGroup=(EntitySystemLite), meta=(DisplayName="Blueprintable System")) | |
class UESLSystem_Blueprint : public UESLSystem | |
{ | |
GENERATED_BODY() | |
public: | |
UFUNCTION(BlueprintImplementableEvent) | |
void OnExecute(UObject* Context, UESLProcess* InCommand); | |
virtual void Execute(UObject* Context, UESLProcess* InCommand) override; | |
}; | |
UCLASS(Blueprintable, EditInlineNew, ClassGroup=(EntitySystemLite), meta=(DisplayName="Systems Container")) | |
class UESLSystemsContainer : public UObject | |
{ | |
GENERATED_BODY() | |
public: | |
UPROPERTY(EditDefaultsOnly, Instanced, Category=EntitySystemLite) | |
TArray<TObjectPtr<UESLSystem>> Systems; | |
public: | |
UFUNCTION(BlueprintCallable) | |
virtual void Execute(UObject* Context, UESLProcess* InCommand); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment