110 lines
3.2 KiB
C++
110 lines
3.2 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "PwnInteractable.h"
|
|
#include "PwnInteractableActor.h"
|
|
#include "Components/ActorComponent.h"
|
|
#include "PwnTrigger.generated.h"
|
|
|
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FTriggerDelegate, AActor*, Actor);
|
|
|
|
USTRUCT(BlueprintType)
|
|
struct FInteractableAction {
|
|
GENERATED_BODY()
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
FPwnInteractableActor Interactable;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
TEnumAsByte<EInteractionType> InteractionType;
|
|
};
|
|
|
|
USTRUCT(BlueprintType)
|
|
struct FInteractableActions {
|
|
GENERATED_BODY()
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
TArray<FInteractableAction> Actions;
|
|
|
|
UPROPERTY(EditAnywhere)
|
|
bool SelfInteract;
|
|
|
|
UPROPERTY(EditAnywhere, meta=(EditCondition="SelfInteract", EditConditionHides))
|
|
TEnumAsByte<EInteractionType> SelfInteractionType;
|
|
};
|
|
|
|
UCLASS(ClassGroup="Interaction",
|
|
HideCategories=("Cooking", "Replication", "Collision"),
|
|
meta=(BlueprintSpawnableComponent))
|
|
class PAWN_API UPwnTrigger : public UActorComponent, public IPwnInteractable {
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPwnTrigger();
|
|
|
|
protected:
|
|
// Unreal Engine overrides
|
|
virtual void BeginPlay() override;
|
|
|
|
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
|
|
|
|
UFUNCTION()
|
|
void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
|
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
|
|
|
|
UFUNCTION()
|
|
void OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
|
int32 OtherBodyIndex);
|
|
|
|
virtual void Activate(bool bReset) override;
|
|
|
|
virtual void Deactivate() override;
|
|
// End of Unreal Engine overrides
|
|
public:
|
|
// IPwnInteractable overrides
|
|
virtual void Interact_Implementation(const EInteractionType InteractionType, const AActor* Interactor) override;
|
|
// End of IPwnInteractable overrides
|
|
|
|
UFUNCTION()
|
|
FVector GetVolumeCenter() const;
|
|
|
|
private:
|
|
void ExecuteActions(const FInteractableActions &InteractableActions, const AActor* Interactor) const;
|
|
|
|
public:
|
|
UPROPERTY(EditAnywhere, Category="Interaction")
|
|
FInteractableActions EnterActions;
|
|
|
|
UPROPERTY(EditAnywhere, Category="Interaction")
|
|
FInteractableActions ExitActions;
|
|
|
|
UPROPERTY(EditAnywhere, Category="Interaction")
|
|
FInteractableActions ManualActions;
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Interactor", meta=(ToolTip="If true, the manual actions can only be triggered if the player is facing the center of the trigger volume."))
|
|
bool MustFaceCenter = true;
|
|
|
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Interactor", meta=(Units="degrees", EditCondition="MustFaceCenter", ClampMin=0.0f, ClampMax=360.0f, UIMin=0.0f, UIMax=360.0f))
|
|
float FaceAngle = 60.0f;
|
|
|
|
UPROPERTY(BlueprintAssignable)
|
|
FTriggerDelegate OnTriggerEnter;
|
|
|
|
UPROPERTY(BlueprintAssignable)
|
|
FTriggerDelegate OnTriggerExit;
|
|
|
|
UPROPERTY(BlueprintAssignable)
|
|
FTriggerDelegate OnTriggerReadyToInteract;
|
|
|
|
UPROPERTY(BlueprintAssignable)
|
|
FTriggerDelegate OnTriggerUnreadyToInteract;
|
|
|
|
protected:
|
|
UPROPERTY(EditAnywhere, Category="Volume", meta=(UseComponentPicker, AllowedClasses="ShapeComponent"))
|
|
FComponentReference TriggerVolume;
|
|
|
|
private:
|
|
UPROPERTY(Transient)
|
|
UShapeComponent* VolumeComponent;
|
|
};
|