A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
VRDialComponent.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "MotionControllerComponent.h"
8#include "VRGripInterface.h"
9#include "GameplayTagContainer.h"
10#include "GameplayTagAssetInterface.h"
12#include "Components/StaticMeshComponent.h"
13
14
15#include "VRDialComponent.generated.h"
16
17
19DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVRDialStateChangedSignature, float, DialMilestoneAngle);
20DECLARE_DYNAMIC_MULTICAST_DELEGATE(FVRDialFinishedLerpingSignature);
21
22UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = (VRExpansionPlugin))
23class VREXPANSIONPLUGIN_API UVRDialComponent : public UStaticMeshComponent, public IVRGripInterface, public IGameplayTagAssetInterface
24{
25 GENERATED_BODY()
27public:
28 UVRDialComponent(const FObjectInitializer& ObjectInitializer);
29
30
32
33 // Call to use an object
34 UPROPERTY(BlueprintAssignable, Category = "VRDialComponent")
35 FVRDialStateChangedSignature OnDialHitSnapAngle;
36
37 UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Dial Hit Snap Angle"))
38 void ReceiveDialHitSnapAngle(float DialMilestoneAngle);
39
40 // If true the dial will lerp back to zero on release
41 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent|Lerping")
42 bool bLerpBackOnRelease;
43
44 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent|Lerping")
45 bool bSendDialEventsDuringLerp;
46
47 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent|Lerping")
48 float DialReturnSpeed;
49
50 UPROPERTY(BlueprintReadOnly, Category = "VRDialComponent|Lerping")
51 bool bIsLerping;
52
53 UPROPERTY(BlueprintAssignable, Category = "VRDialComponent|Lerping")
54 FVRDialFinishedLerpingSignature OnDialFinishedLerping;
56 UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Dial Finished Lerping"))
57 void ReceiveDialFinishedLerping();
58
59 UPROPERTY(BlueprintReadOnly, Category = "VRDialComponent")
60 float CurrentDialAngle;
61
62 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")//, meta = (ClampMin = "0.0", ClampMax = "360.0", UIMin = "0.0", UIMax = "360.0"))
63 float ClockwiseMaximumDialAngle;
64
65 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")//, meta = (ClampMin = "0.0", ClampMax = "360.0", UIMin = "0.0", UIMax = "360.0"))
66 float CClockwiseMaximumDialAngle;
67
68 // If true then the dial can "roll over" past 360/0 degrees in a direction
69 // Allowing unlimited dial angle values
70 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
71 bool bUseRollover;
72
73 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
74 bool bDialUsesAngleSnap;
76 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
77 bool bDialUseSnapAngleList;
78
79 // Optional list of snap angles for the dial
80 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (editcondition = "bDialUseSnapAngleList"))
81 TArray<float> DialSnapAngleList;
82
83 // Angle that the dial snaps to on release and when within the threshold distance
84 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (editcondition = "!bDialUseSnapAngleList", ClampMin = "0.0", ClampMax = "180.0", UIMin = "0.0", UIMax = "180.0"))
85 float SnapAngleIncrement;
86
87 // Threshold distance that when within the dial will stay snapped to its closest snap increment
88 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (editcondition = "!bDialUseSnapAngleList", ClampMin = "0.0", ClampMax = "180.0", UIMin = "0.0", UIMax = "180.0"))
89 float SnapAngleThreshold;
90
91 // Scales rotational input to speed up or slow down the rotation
92 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (ClampMin = "0.0", ClampMax = "180.0", UIMin = "0.0", UIMax = "180.0"))
93 float RotationScaler;
94
95 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
96 EVRInteractibleAxis DialRotationAxis;
97
98 // If true then the dial will directly sample the hands rotation instead of using its movement around it.
99 // This is good for roll specific dials but is fairly bad elsewhere.
100 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
101 bool bDialUseDirectHandRotation;
102
103 float LastGripRot;
104 float InitialGripRot;
105 float InitialRotBackEnd;
106
107 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (editcondition = "bDialUseDirectHandRotation"))
108 EVRInteractibleAxis InteractorRotationAxis;
109
110 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
111 float PrimarySlotRange;
112
113 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
114 float SecondarySlotRange;
115
116 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
117 int GripPriority;
118
119 // Sets the grip priority
120 UFUNCTION(BlueprintCallable, Category = "GripSettings")
121 void SetGripPriority(int NewGripPriority);
122
123 // Resetting the initial transform here so that it comes in prior to BeginPlay and save loading.
124 virtual void OnRegister() override;
125
126 // Now replicating this so that it works correctly over the network
127 UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_InitialRelativeTransform, Category = "VRDialComponent")
128 FTransform_NetQuantize InitialRelativeTransform;
129
130 UFUNCTION()
131 virtual void OnRep_InitialRelativeTransform()
132 {
133 CalculateDialProgress();
134 }
135
136 void CalculateDialProgress();
137
138 //FTransform InitialRelativeTransform;
139 FVector InitialInteractorLocation;
140 FVector InitialDropLocation;
141 float CurRotBackEnd;
142 FRotator LastRotation;
143 float LastSnapAngle;
144
145 // Should be called after the dial is moved post begin play
146 UFUNCTION(BlueprintCallable, Category = "VRLeverComponent")
147 void ResetInitialDialLocation();
148
149 // Can be called to recalculate the dial angle after you move it if you want different values
150 UFUNCTION(BlueprintCallable, Category = "VRLeverComponent")
151 void AddDialAngle(float DialAngleDelta, bool bCallEvents = false, bool bSkipSettingRot = false);
152
153 // Directly sets the dial angle, still obeys maximum limits and snapping though
154 UFUNCTION(BlueprintCallable, Category = "VRLeverComponent")
155 void SetDialAngle(float DialAngle, bool bCallEvents = false);
156
157 // ------------------------------------------------
158 // Gameplay tag interface
159 // ------------------------------------------------
160
162 virtual void GetOwnedGameplayTags(FGameplayTagContainer& TagContainer) const override
163 {
164 TagContainer = GameplayTags;
165 }
166
168 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "GameplayTags")
169 FGameplayTagContainer GameplayTags;
170
171 // End Gameplay Tag Interface
172
173 virtual void PreReplication(IRepChangedPropertyTracker & ChangedPropertyTracker) override;
174
175
176 // Requires bReplicates to be true for the component
177 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
178 bool bRepGameplayTags;
179
180 // Overrides the default of : true and allows for controlling it like in an actor, should be default of off normally with grippable components
181 UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface|Replication")
182 bool bReplicateMovement;
183
184 virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
185 virtual void BeginPlay() override;
186
187 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
188 EGripMovementReplicationSettings MovementReplicationSetting;
190 UPROPERTY(BlueprintReadOnly, Category = "VRGripInterface", meta = (ScriptName = "IsCurrentlyHeld"))
191 bool bIsHeld; // Set on grip notify, not net serializing
192
193 UPROPERTY(BlueprintReadOnly, Category = "VRGripInterface")
194 FBPGripPair HoldingGrip; // Set on grip notify, not net serializing
195 bool bOriginalReplicatesMovement;
197 // Called when a object is gripped
198 // If you override the OnGrip event then you will need to call the parent implementation or this event will not fire!!
199 UPROPERTY(BlueprintAssignable, Category = "Grip Events")
200 FVROnGripSignature OnGripped;
201
202 // Called when a object is dropped
203 // If you override the OnGrip event then you will need to call the parent implementation or this event will not fire!!
204 UPROPERTY(BlueprintAssignable, Category = "Grip Events")
205 FVROnDropSignature OnDropped;
206
207 // Distance before the object will break out of the hand, 0.0f == never will
208 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
209 float BreakDistance;
211 // Should we deny gripping on this object
212 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface", meta = (ScriptName = "IsDenyGripping"))
213 bool bDenyGripping;
214
215 // Grip interface setup
216
217 // Set up as deny instead of allow so that default allows for gripping
218 // The GripInitiator is not guaranteed to be valid, check it for validity
219 bool DenyGripping_Implementation(UGripMotionControllerComponent * GripInitiator = nullptr) override;
220
221 // How an interfaced object behaves when teleporting
222 EGripInterfaceTeleportBehavior TeleportBehavior_Implementation() override;
223
224 // Should this object simulate on drop
225 bool SimulateOnDrop_Implementation() override;
226
227 // Grip type to use
228 EGripCollisionType GetPrimaryGripType_Implementation(bool bIsSlot) override;
229
230 // Secondary grip type
231 ESecondaryGripType SecondaryGripType_Implementation() override;
233 // Define which movement repliation setting to use
234 EGripMovementReplicationSettings GripMovementReplicationType_Implementation() override;
235
236 // Define the late update setting
237 EGripLateUpdateSettings GripLateUpdateSetting_Implementation() override;
238
239 // What grip stiffness and damping to use if using a physics constraint
240 void GetGripStiffnessAndDamping_Implementation(float &GripStiffnessOut, float &GripDampingOut) override;
242 // Get the advanced physics settings for this grip
243 FBPAdvGripSettings AdvancedGripSettings_Implementation() override;
245 // What distance to break a grip at (only relevent with physics enabled grips
246 float GripBreakDistance_Implementation() override;
247
248 // Get grip slot in range
249 void ClosestGripSlotInRange_Implementation(FVector WorldLocation, bool bSecondarySlot, bool & bHadSlotInRange, FTransform & SlotWorldTransform, FName & SlotName, UGripMotionControllerComponent * CallingController = nullptr, FName OverridePrefix = NAME_None) override;
250
251 // Check if an object allows multiple grips at one time
252 bool AllowsMultipleGrips_Implementation() override;
253
254 // Returns if the object is held and if so, which controllers are holding it
255 void IsHeld_Implementation(TArray<FBPGripPair>& CurHoldingControllers, bool & bCurIsHeld) override;
256
257 // Interface function used to throw the delegates that is invisible to blueprints so that it can't be overridden
258 virtual void Native_NotifyThrowGripDelegates(UGripMotionControllerComponent* Controller, bool bGripped, const FBPActorGripInformation& GripInformation, bool bWasSocketed = false) override;
259
260 // Sets is held, used by the plugin
261 void SetHeld_Implementation(UGripMotionControllerComponent * NewHoldingController, uint8 GripID, bool bNewIsHeld) override;
262
263 // Returns if the object wants to be socketed
264 bool RequestsSocketing_Implementation(USceneComponent *& ParentToSocketTo, FName & OptionalSocketName, FTransform_NetQuantize & RelativeTransform) override;
265
266 // Get grip scripts
267 bool GetGripScripts_Implementation(TArray<UVRGripScriptBase*> & ArrayReference) override;
268
269
270 // Events //
271
272 // Event triggered each tick on the interfaced object when gripped, can be used for custom movement or grip based logic
273 void TickGrip_Implementation(UGripMotionControllerComponent * GrippingController, const FBPActorGripInformation & GripInformation, float DeltaTime) override;
274
275 // Event triggered on the interfaced object when gripped
276 void OnGrip_Implementation(UGripMotionControllerComponent * GrippingController, const FBPActorGripInformation & GripInformation) override;
277
278 // Event triggered on the interfaced object when grip is released
279 void OnGripRelease_Implementation(UGripMotionControllerComponent * ReleasingController, const FBPActorGripInformation & GripInformation, bool bWasSocketed = false) override;
280
281 // Event triggered on the interfaced object when child component is gripped
282 void OnChildGrip_Implementation(UGripMotionControllerComponent * GrippingController, const FBPActorGripInformation & GripInformation) override;
283
284 // Event triggered on the interfaced object when child component is released
285 void OnChildGripRelease_Implementation(UGripMotionControllerComponent * ReleasingController, const FBPActorGripInformation & GripInformation, bool bWasSocketed = false) override;
286
287 // Event triggered on the interfaced object when secondary gripped
288 void OnSecondaryGrip_Implementation(UGripMotionControllerComponent * GripOwningController, USceneComponent * SecondaryGripComponent, const FBPActorGripInformation & GripInformation) override;
289
290 // Event triggered on the interfaced object when secondary grip is released
291 void OnSecondaryGripRelease_Implementation(UGripMotionControllerComponent * GripOwningController, USceneComponent * ReleasingSecondaryGripComponent, const FBPActorGripInformation & GripInformation) override;
292
293 // Interaction Functions
294
295 // Call to use an object
296 void OnUsed_Implementation() override;
297
298 // Call to stop using an object
299 void OnEndUsed_Implementation() override;
300
301 // Call to use an object
302 void OnSecondaryUsed_Implementation() override;
303
304 // Call to stop using an object
305 void OnEndSecondaryUsed_Implementation() override;
306
307 // Call to send an action event to the object
308 void OnInput_Implementation(FKey Key, EInputEvent KeyEvent) override;
309
310 protected:
311
312};
EGripMovementReplicationSettings
UENUM(Blueprintable)
ESecondaryGripType
UENUM(Blueprintable)
EGripCollisionType
UENUM(Blueprintable)
EGripLateUpdateSettings
UENUM(Blueprintable)
EGripInterfaceTeleportBehavior
UENUM(Blueprintable)
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FVRDialFinishedLerpingSignature)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FVRDialStateChangedSignature, float, DialMilestoneAngle)
EVRInteractibleAxis
UENUM(Blueprintable)
virtual void Native_NotifyThrowGripDelegates(UGripMotionControllerComponent *Controller, bool bGripped, const FBPActorGripInformation &GripInformation, bool bWasSocketed=false)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = MotionController)
UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent), ClassGroup = (VRExpansionPlugin))
EGripMovementReplicationSettings MovementReplicationSetting
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
virtual void GetOwnedGameplayTags(FGameplayTagContainer &TagContainer) const override
float SnapAngleThreshold
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (editcondition = "!...
float CClockwiseMaximumDialAngle
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
FVROnGripSignature OnGripped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
bool bIsHeld
UPROPERTY(BlueprintReadOnly, Category = "VRGripInterface", meta = (ScriptName = "IsCurrentlyHeld"))
FVROnDropSignature OnDropped
UPROPERTY(BlueprintAssignable, Category = "Grip Events")
void ReceiveDialFinishedLerping()
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Dial Finished Lerping"))
bool bDialUseSnapAngleList
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
bool bSendDialEventsDuringLerp
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent|Lerping")
FVector InitialInteractorLocation
int GripPriority
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
virtual void OnRep_InitialRelativeTransform()
UFUNCTION()
float ClockwiseMaximumDialAngle
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
bool bLerpBackOnRelease
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent|Lerping")
TArray< float > DialSnapAngleList
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (editcondition = "bD...
bool bRepGameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface")
bool bUseRollover
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
EVRInteractibleAxis InteractorRotationAxis
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (editcondition = "bD...
EVRInteractibleAxis DialRotationAxis
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
float SnapAngleIncrement
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (editcondition = "!...
bool bDialUsesAngleSnap
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
bool bReplicateMovement
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "VRGripInterface|Replication")
FGameplayTagContainer GameplayTags
UPROPERTY(EditAnywhere, Replicated, BlueprintReadWrite, Category = "GameplayTags")
void ReceiveDialHitSnapAngle(float DialMilestoneAngle)
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Dial Hit Snap Angle"))
FTransform_NetQuantize InitialRelativeTransform
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_InitialRelativeTransform, Category = "VRDialComp...
bool bDialUseDirectHandRotation
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent")
FVRDialStateChangedSignature OnDialHitSnapAngle
UPROPERTY(BlueprintAssignable, Category = "VRDialComponent")
FVRDialFinishedLerpingSignature OnDialFinishedLerping
UPROPERTY(BlueprintAssignable, Category = "VRDialComponent|Lerping")
float RotationScaler
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent", meta = (ClampMin = "0....
bool bIsLerping
UPROPERTY(BlueprintReadOnly, Category = "VRDialComponent|Lerping")
float BreakDistance
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface")
float SecondarySlotRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
float PrimarySlotRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "GripSettings")
bool bDenyGripping
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRGripInterface", meta = (ScriptName = "IsDen...
FBPGripPair HoldingGrip
UPROPERTY(BlueprintReadOnly, Category = "VRGripInterface")
float CurrentDialAngle
UPROPERTY(BlueprintReadOnly, Category = "VRDialComponent")
float DialReturnSpeed
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VRDialComponent|Lerping")
UCLASS(NotBlueprintable, BlueprintType, EditInlineNew, DefaultToInstanced, Abstract,...
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary")
USTRUCT(BlueprintType, Category = "VRExpansionLibrary|TransformNetQuantize", meta = (HasNativeMake = ...