6#include "Components/BoxComponent.h"
7#include "Components/TimelineComponent.h"
8#include "Components/WidgetComponent.h"
10#include "Kismet/GameplayStatics.h"
11#include "Kismet/KismetMathLibrary.h"
12#include "Serialization/ObjectAndNameAsStringProxyArchive.h"
15#include "Net/UnrealNetwork.h"
21 PrimaryActorTick.bCanEverTick =
true;
24 BoxForSpawn = CreateDefaultSubobject<UBoxComponent>(FName(
"BoxForSpawn"));
28 BoxForSpawn->SetBoxExtent(FVector(10.0f, 60.0f, 60.0f));
32 BoxForRotate = CreateDefaultSubobject<UBoxComponent>(FName(
"BoxForRotate"));
39 WidgetScene = CreateDefaultSubobject<USceneComponent>(FName(
"WidgetScene"));
46 WidgetComponent = CreateDefaultSubobject<UWidgetComponent>(FName(
"Widget"));
56 OpenCloseTimeline = CreateDefaultSubobject<UTimelineComponent>(TEXT(
"OpenCloseTimeline"));
58 BoxForTouch = CreateDefaultSubobject<UBoxComponent>(FName(
"BoxForTouch"));
62 BoxForTouch->SetBoxExtent(FVector(60.0f, 60.0f, 60.0f));
66 static ConstructorHelpers::FObjectFinder<USoundWave> OpenSoundFinder(TEXT(
"SoundWave'/PixoCore/Audio/UI/UI_Open.UI_Open'"));
68 static ConstructorHelpers::FObjectFinder<USoundWave> CloseSoundFinder(TEXT(
"SoundWave'/PixoCore/Audio/UI/UI_Close.UI_Close'"));
70 static ConstructorHelpers::FObjectFinder<UCurveFloat> OpenCloseCurveFinder(TEXT(
"CurveFloat'/PixoCore/Blueprints/UI/OpenCloseWidgetCurve.OpenCloseWidgetCurve'"));
93 UE_LOG(LogTemp, Warning, TEXT(
"Timeline Curve Doesn't Set"));
100 Super::Tick(DeltaTime);
103 const APawn* FirstPlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
105 if (FirstPlayerPawn && IsWidgetExist)
109 const float TargetYaw = UKismetMathLibrary::FindLookAtRotation(
FinalLocation, FirstPlayerPawn->GetActorLocation()).Yaw;
110 FRotator ResultYaw = FMath::RInterpConstantTo(
BoxForRotate->GetComponentRotation(), FRotator(0.0f, TargetYaw, 0.0f), DeltaTime, 200.0f);
114 ResultYaw = FMath::RInterpConstantTo(
WidgetComponent->GetComponentRotation(), FRotator(0.0f, TargetYaw, 0.0f), DeltaTime, 200.0f);
119 const FVector InstigatorLocation = FirstPlayerPawn->GetActorLocation();
120 if (!InstigatorLocation.Equals(FVector::ZeroVector, 1.0f))
122 const float SquaredDistance2D = FVector::DistSquared2D(InstigatorLocation,
FinalLocation);
147 if (NeedToCreateNewWidget)
151 UE_LOG(LogTemp, Warning, TEXT(
"WidgetController can't open widget by UpdateRequest"));
181 BasicWidget->
Init(WidgetInfo);
182 SetActorEnableCollision(
true);
205 UWorld* ThisWorld = GetWorld();
206 if (
OpenSound && ThisWorld && ThisWorld->bAllowAudioPlayback && !ThisWorld->IsNetMode(NM_DedicatedServer) &&
bSoundAllowed)
208 UGameplayStatics::PlaySound2D(ThisWorld,
OpenSound);
213 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult& SweepResult)
215 if (
const APixoVRHand* HandOverlapping = Cast<APixoVRHand>(OtherActor))
218 HandOverlapping->TouchComponent->Activate();
223 UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
225 if (
const APixoVRHand* HandOverlapping = Cast<APixoVRHand>(OtherActor))
227 IHandAnimationInterface::Execute_SetAnimationGripState(HandOverlapping->HandMesh->GetAnimInstance(),
EPixoVRGripState::Open);
228 HandOverlapping->TouchComponent->Deactivate();
264 SetActorEnableCollision(
false);
267 UWorld* ThisWorld = GetWorld();
268 if (
CloseSound && ThisWorld && ThisWorld->bAllowAudioPlayback && !ThisWorld->IsNetMode(NM_DedicatedServer) &&
bSoundAllowed)
270 UGameplayStatics::PlaySound2D(ThisWorld,
CloseSound);
321 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
332 WidgetScene->SetWorldScale3D(FVector(Value, Value, Value));
337 SetActorRotation(NewRotation);
356void AWidgetController::BeginOverlap(UPrimitiveComponent* OverlappedComponent,
AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
bool bFromSweep,
const FHitResult &SweepResult)
APixoVRHand is an actor class that represents a hand in the VR environment.