A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
InteractionButton.h
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/Actor.h"
7#include "Components/BoxComponent.h"
8#include "Components/PointLightComponent.h"
9#include "Components/TextRenderComponent.h"
10#include "Components/TimelineComponent.h"
11#include "InteractionButton.generated.h"
12
16UENUM(BlueprintType)
17enum class EButtonState : uint8
18{
19 BS_None = 0 UMETA(DisplayName = "None"),
20 BS_Default UMETA(DisplayName = "Default"),
21 BS_Pressed UMETA(DisplayName = "Pressed"),
22 BS_Disabled UMETA(DisplayName = "Disabled")
23};
24
25DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FButtonPressedDelegate, APlayerController*, PlayerController);
26DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FButtonReleasedDelegate, APlayerController*, PlayerController);
27
31UCLASS(Blueprintable)
32class PIXOCORE_API AInteractionButton : public AActor
33{
34 GENERATED_BODY()
35
36public:
38 virtual void Tick(float DeltaTime) override;
39
44 void SetButtonVisibility(bool bVisible);
45
50 FButtonPressedDelegate& OnButtonPressed() { return ButtonPressedDelegate; }
55 FButtonReleasedDelegate& OnButtonReleased() { return ButtonReleasedDelegate; }
61 UFUNCTION(BlueprintCallable, BlueprintPure)
62 EButtonState GetButtonState() const { return CurrentButtonState; }
63
68 UFUNCTION(BlueprintCallable)
69 void SetButtonState(EButtonState InButtonState);
74 UFUNCTION(BlueprintCallable)
75 void SetButtonName(const FName& InButtonName);
76
77 virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
78
79 UPROPERTY(BlueprintAssignable)
80 FButtonPressedDelegate ButtonPressedDelegate;
81 UPROPERTY(BlueprintAssignable)
82 FButtonReleasedDelegate ButtonReleasedDelegate;
83
84protected:
85 virtual void BeginPlay() override;
86
90 UFUNCTION(BlueprintNativeEvent)
91 void ButtonPress();
95 UFUNCTION(BlueprintNativeEvent)
96 void ButtonRelease();
97
98private:
99 UFUNCTION()
100 void OnBeginOverlapButton(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
101 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
102 const FHitResult& SweepResult);
107 UFUNCTION()
108 void MovingButtonTimelineProgress(float Value);
112 UFUNCTION()
113 void MovingButtonTimelineFinished();
114
115protected:
116 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
117 UStaticMeshComponent* ButtonSupportComp;
118 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
119 UStaticMeshComponent* ButtonMovingComp;
120 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
121 UBoxComponent* BoxCollisionComp;
122 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
123 UPointLightComponent* PointLightComp;
124 UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
125 UTextRenderComponent* TextRenderComp;
126
127 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
128 bool bIsButtonHaveText = false;
129 UPROPERTY(Replicated, EditAnywhere, BlueprintReadOnly, Category = Setup, meta = (EditCondition = "bIsButtonHaveText = true", EditConditionHides))
130 FName ButtonText = "Button Text";
131 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
132 USoundBase* ButtonPressSound;
133 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
134 UCurveFloat* MovingButtonCurve;
135 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
136 UForceFeedbackEffect* LeftHandFeedbackEffect;
137 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
138 UForceFeedbackEffect* RightHandFeedbackEffect;
139
140private:
141 bool bIsPressed = false;
142 EButtonState CurrentButtonState = EButtonState::BS_Default;
143
144 FTimeline MovingButtonTimeLine;
145 UPROPERTY()
146 TEnumAsByte<ETimelineDirection::Type> TimelineDirection;
147
148 UPROPERTY()
149 APlayerController* PlayerController;
150};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FButtonPressedDelegate, APlayerController *, PlayerController)
EButtonState
Enumeration defining the possible states of the button.
@ BS_Disabled
Disabled state.
@ BS_Pressed
Pressed state.
@ BS_None
No state.
@ BS_Default
Default state.
Represents an interaction button actor.
UBoxComponent * BoxCollisionComp
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
UPointLightComponent * PointLightComp
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
APlayerController * PlayerController
UPROPERTY()
FButtonPressedDelegate & OnButtonPressed()
Retrieves the button pressed delegate.
USoundBase * ButtonPressSound
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
FButtonReleasedDelegate & OnButtonReleased()
Retrieves the button released delegate.
EButtonState GetButtonState() const
Gets the current state of the button.
UForceFeedbackEffect * RightHandFeedbackEffect
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
UForceFeedbackEffect * LeftHandFeedbackEffect
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
UStaticMeshComponent * ButtonSupportComp
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
FTimeline MovingButtonTimeLine
Timeline for the movement of the button.
void ButtonRelease()
Event called when button was released. Overload it when you want to add functionality.
UCurveFloat * MovingButtonCurve
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Setup)
void ButtonPress()
Event called when button was pressed. Overload it when you want to add functionality.
TEnumAsByte< ETimelineDirection::Type > TimelineDirection
UPROPERTY()
FButtonReleasedDelegate ButtonReleasedDelegate
UPROPERTY(BlueprintAssignable)
FButtonPressedDelegate ButtonPressedDelegate
UPROPERTY(BlueprintAssignable)
UStaticMeshComponent * ButtonMovingComp
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
UTextRenderComponent * TextRenderComp
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)