A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
PixoVRCircleProgress.cpp
Go to the documentation of this file.
1// Copyright(c) Pixo Group. All Rights Reserved.
2
4#include "PixoVRCharacter.h"
6
8{
9 PrimaryActorTick.bCanEverTick = true;
10 PrimaryActorTick.bStartWithTickEnabled = false;
11 bReplicates = true;
12
13 SceneRoot = CreateDefaultSubobject<USceneComponent>(TEXT("SceneRoot"));
14 SetRootComponent(SceneRoot);
15
16 ProgressPlane = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ProgressPlane"));
17 ProgressPlane->SetCollisionProfileName("NoCollision");
18 ProgressPlane->SetupAttachment(GetRootComponent());
19
20 SetActorHiddenInGame(true);
21}
22
24{
26 {
27 ProgressMaterialInstance =ProgressPlane->CreateDynamicMaterialInstance(0);
28 }
29 ProgressMaterialInstance->SetScalarParameterValue("Decimal", Percentage);
30}
31
32void APixoVRCircleProgress::SetCircleProgressEnabled_Implementation(bool bIsEnabled)
33{
34 SetActorHiddenInGame(!bIsEnabled);
35 SetActorTickEnabled(bIsEnabled);
36}
37
38void APixoVRCircleProgress::Tick(float DeltaSeconds)
39{
40 Super::Tick(DeltaSeconds);
41
43 {
44 const float ThresholdPercentage = VisibilityThresholdTime / LongHoldComponent->GetNeededTime();
45 const FVector2D InputRange(ThresholdPercentage, 1.0f);
46 const FVector2D OutputRange(0.0f, 1.0f);
47 const float Percentage = FMath::GetMappedRangeValueClamped(InputRange, OutputRange, LongHoldComponent->GetCurrentTimePercentage());
48
50 }
51}
52
54{
55 Super::BeginPlay();
56
57 if (const auto Character = Cast<APixoVRCharacter>(GetOwner()))
58 {
59 LongHoldComponent = Character->LongHoldComponent;
60 }
61}
virtual void Tick(float DeltaSeconds) override
UPixoVRLongHoldComponent * LongHoldComponent
UPROPERTY()
virtual void BeginPlay() override
float VisibilityThresholdTime
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Setup)
UMaterialInstanceDynamic * ProgressMaterialInstance
UPROPERTY()
UStaticMeshComponent * ProgressPlane
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
void UpdateCircle(float Percentage)
Updates the circle progress to the specified percentage.
USceneComponent * SceneRoot
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = Components)
float GetNeededTime() const
Gets the needed time for a successful long hold.
float GetCurrentTime() const
Gets the current time of the long hold.
float GetCurrentTimePercentage() const
Gets the current time percentage of the long hold.