|
@@ -0,0 +1,120 @@
|
|
|
+// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
+
|
|
|
+
|
|
|
+#include "VRCharacterBase.h"
|
|
|
+
|
|
|
+#include "Kismet/GameplayStatics.h"
|
|
|
+#include "Kismet/KismetSystemLibrary.h"
|
|
|
+
|
|
|
+#include "Components/CapsuleComponent.h"
|
|
|
+
|
|
|
+#include "VRHUDBase.h"
|
|
|
+
|
|
|
+static FName FirstPersonCameraName(TEXT("FirstPersonCamera"));
|
|
|
+
|
|
|
+// Sets default values
|
|
|
+AVRCharacterBase::AVRCharacterBase(const FObjectInitializer& ObjectInitializer): Super(ObjectInitializer)
|
|
|
+{
|
|
|
+ // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
|
|
+ PrimaryActorTick.bCanEverTick = true;
|
|
|
+
|
|
|
+ GetCapsuleComponent()->InitCapsuleSize(50, 50);
|
|
|
+ GetCapsuleComponent()->SetRelativeLocation(FVector(-240, 60, 190));
|
|
|
+
|
|
|
+ GetMesh()->SetRelativeLocation(FVector(0, 0, -100));
|
|
|
+ GetMesh()->SetRelativeRotation(FRotator(0, -90, 0));
|
|
|
+
|
|
|
+ FirstPersonCamera = CreateDefaultSubobject<UCameraComponent>(FirstPersonCameraName);
|
|
|
+ if (FirstPersonCamera) {
|
|
|
+ FirstPersonCamera->SetRelativeLocation(FVector(60, 0, 15));
|
|
|
+ FirstPersonCamera->SetupAttachment(GetCapsuleComponent());
|
|
|
+ }
|
|
|
+
|
|
|
+ MyTimeline.SetTimelineLength(2);
|
|
|
+
|
|
|
+ MyCurveFloat = CreateDefaultSubobject<UCurveFloat>(FName("MyCurveFloat"));
|
|
|
+ if (MyCurveFloat) {
|
|
|
+ MyCurveFloat->FloatCurve.AddKey(0, 0);
|
|
|
+ MyCurveFloat->FloatCurve.AddKey(2, 100);
|
|
|
+ }
|
|
|
+
|
|
|
+ FOnTimelineFloatStatic onTimelineUpdate;
|
|
|
+ onTimelineUpdate.BindUFunction(this, FName("OnTimelineUpdate"));
|
|
|
+ MyTimeline.AddInterpFloat(MyCurveFloat, onTimelineUpdate);
|
|
|
+
|
|
|
+ FOnTimelineEventStatic onTimelineFinished;
|
|
|
+ onTimelineFinished.BindUFunction(this, FName("OnTimelineFinished"));
|
|
|
+ MyTimeline.SetTimelineFinishedFunc(onTimelineFinished);
|
|
|
+}
|
|
|
+
|
|
|
+// Called when the game starts or when spawned
|
|
|
+void AVRCharacterBase::BeginPlay()
|
|
|
+{
|
|
|
+ Super::BeginPlay();
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// Called every frame
|
|
|
+void AVRCharacterBase::Tick(float DeltaTime)
|
|
|
+{
|
|
|
+ Super::Tick(DeltaTime);
|
|
|
+
|
|
|
+ MyTimeline.TickTimeline(DeltaTime);
|
|
|
+}
|
|
|
+
|
|
|
+// Called to bind functionality to input
|
|
|
+void AVRCharacterBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
|
|
+{
|
|
|
+ Super::SetupPlayerInputComponent(PlayerInputComponent);
|
|
|
+
|
|
|
+ PlayerInputComponent->BindAxis("MoveForward", this, &AVRCharacterBase::MoveForward);
|
|
|
+ PlayerInputComponent->BindAxis("MoveRight", this, &AVRCharacterBase::MoveRight);
|
|
|
+ PlayerInputComponent->BindAxis("Turn", this, &AVRCharacterBase::Turn);
|
|
|
+ PlayerInputComponent->BindAxis("LookUp", this, &AVRCharacterBase::LookUp);
|
|
|
+
|
|
|
+ PlayerInputComponent->BindAction("BeginWaitConnected", EInputEvent::IE_Pressed, this, &AVRCharacterBase::BeginWaitConnected);
|
|
|
+
|
|
|
+ PlayerInputComponent->BindAction("TestButton", EInputEvent::IE_Pressed, this, &AVRCharacterBase::Test);
|
|
|
+}
|
|
|
+
|
|
|
+void AVRCharacterBase::MoveForward(float value) {
|
|
|
+ FVector direction = GetActorForwardVector();
|
|
|
+ AddMovementInput(direction * value);
|
|
|
+}
|
|
|
+
|
|
|
+void AVRCharacterBase::MoveRight(float value) {
|
|
|
+ FVector direction = GetActorRightVector();
|
|
|
+ AddMovementInput(direction * value);
|
|
|
+}
|
|
|
+
|
|
|
+void AVRCharacterBase::Turn(float value) {
|
|
|
+ AddControllerYawInput(value);
|
|
|
+}
|
|
|
+
|
|
|
+void AVRCharacterBase::LookUp(float value) {
|
|
|
+ FirstPersonCamera->AddRelativeRotation(FRotator(-value, 0, 0));
|
|
|
+}
|
|
|
+
|
|
|
+void AVRCharacterBase::BeginWaitConnected() {
|
|
|
+ UE_LOG(LogTemp, Warning, TEXT("AVRCharacterBase::BeginWaitConnected"));
|
|
|
+
|
|
|
+ MyTimeline.PlayFromStart();
|
|
|
+}
|
|
|
+
|
|
|
+void AVRCharacterBase::OnTimelineUpdate(float value) {
|
|
|
+ UE_LOG(LogTemp, Warning, TEXT("AVRCharacterBase::OnTimelineUpdate: %f"), value);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void AVRCharacterBase::OnTimelineFinished() {
|
|
|
+ UE_LOG(LogTemp, Warning, TEXT("AVRCharacterBase::OnTimelineFinished"));
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void AVRCharacterBase::Test() {
|
|
|
+ UGameInstance *gameInstance = GetGameInstance();
|
|
|
+
|
|
|
+ AVRHUDBase* hud = Cast<AVRHUDBase>(UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetHUD());
|
|
|
+ hud->Test();
|
|
|
+
|
|
|
+}
|