diff --git a/Source/D1/Components/StateManagerComponent.cpp b/Source/D1/Components/StateManagerComponent.cpp new file mode 100644 index 00000000..48819167 --- /dev/null +++ b/Source/D1/Components/StateManagerComponent.cpp @@ -0,0 +1,58 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Components/StateManagerComponent.h" + +// Sets default values for this component's properties +UStateManagerComponent::UStateManagerComponent() +{ + // 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 = true; + + // ... +} + + +// Called when the game starts +void UStateManagerComponent::BeginPlay() +{ + Super::BeginPlay(); + + // ... + +} + + +// Called every frame +void UStateManagerComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + +void UStateManagerComponent::SetState(ECharacterState NewState) +{ + if (NewState != CurrentState) + { + //TODO : Delegate ÇÔ¼ö È£Ãâ (Call on State End) + CurrentState = NewState; + //TODO : Delegate ÇÔ¼ö È£Ãâ (Call on State Begin) + } +} + +ECharacterState UStateManagerComponent::GetCurrentState() +{ + return CurrentState; +} + +void UStateManagerComponent::ResetState() +{ + CurrentState = ECharacterState::Nothing; +} + +bool UStateManagerComponent::IsCurrentStateEqualToAny(TArray StatesToCheck) +{ + return StatesToCheck.Contains(CurrentState); +} \ No newline at end of file diff --git a/Source/D1/Components/StateManagerComponent.h b/Source/D1/Components/StateManagerComponent.h new file mode 100644 index 00000000..402a7282 --- /dev/null +++ b/Source/D1/Components/StateManagerComponent.h @@ -0,0 +1,44 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "StateManagerComponent.generated.h" + +UENUM(BlueprintType) +enum class ECharacterState : uint8 +{ + Nothing UMETA(DisplayName = "Nothing"), + Attacking UMETA(DisplayName = "Attacking"), + Dodging UMETA(DisplayName = "Dodging"), + GeneralActionState UMETA(DisplayName = "GeneralActionState"), + Dead UMETA(DisplayName = "Dead"), + Disable UMETA(DisplayName = "Disable") +}; + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class D1_API UStateManagerComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UStateManagerComponent(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + +public: + void SetState(ECharacterState NewState); + ECharacterState GetCurrentState(); + void ResetState(); + bool IsCurrentStateEqualToAny(TArray StatesToCheck); +private: + ECharacterState CurrentState; +};