Browse Source

代码迁移

killf 1 year ago
parent
commit
3734b028d6

+ 2 - 2
Config/DefaultEngine.ini

@@ -2,8 +2,8 @@
 GameName=TetreeseDemo
 
 [/Script/EngineSettings.GameMapsSettings]
-EditorStartupMap=/Game/Maps/Map007.Map007
-GameDefaultMap=/Game/Maps/Map007.Map007
+EditorStartupMap=/Game/Maps/Map000.Map000
+GameDefaultMap=/Game/Maps/Map000.Map000
 TransitionMap=
 bUseSplitscreen=True
 TwoPlayerSplitscreenLayout=Horizontal

BIN
Content/BP/VRCharacter.uasset


BIN
Content/BP/VRHUD.uasset


BIN
Content/Maps/Map000.umap


BIN
Content/Maps/VRGameMode2.uasset


+ 12 - 0
Source/TetreeseDemo/Helper.cpp

@@ -0,0 +1,12 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+
+#include "Helper.h"
+
+Helper::Helper()
+{
+}
+
+Helper::~Helper()
+{
+}

+ 15 - 0
Source/TetreeseDemo/Helper.h

@@ -0,0 +1,15 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+#pragma once
+
+#include "CoreMinimal.h"
+
+/**
+ * 
+ */
+class TETREESEDEMO_API Helper
+{
+public:
+	Helper();
+	~Helper();
+};

+ 120 - 0
Source/TetreeseDemo/VRCharacterBase.cpp

@@ -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();
+
+}

+ 60 - 0
Source/TetreeseDemo/VRCharacterBase.h

@@ -0,0 +1,60 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+#pragma once
+
+#include "CoreMinimal.h"
+#include "GameFramework/Character.h"
+#include "Camera/CameraComponent.h"
+#include "Components/TimelineComponent.h"
+#include "VRCharacterBase.generated.h"
+
+UCLASS()
+class TETREESEDEMO_API AVRCharacterBase : public ACharacter
+{
+	GENERATED_BODY()
+
+public:
+	// Sets default values for this character's properties
+	AVRCharacterBase(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
+
+protected:
+	// Called when the game starts or when spawned
+	virtual void BeginPlay() override;
+
+public:	
+	// Called every frame
+	virtual void Tick(float DeltaTime) override;
+
+	// Called to bind functionality to input
+	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
+
+private:
+
+	void MoveForward(float value);
+
+	void MoveRight(float value);
+
+	void Turn(float value);
+
+	void LookUp(float value);
+
+	void BeginWaitConnected();
+
+	void Test();
+
+private:
+
+	UPROPERTY(Category = Component, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
+		TObjectPtr<UCameraComponent> FirstPersonCamera;
+
+	FTimeline MyTimeline;
+
+	UPROPERTY()
+	UCurveFloat* MyCurveFloat;
+
+	UFUNCTION()
+	void OnTimelineUpdate(float value);
+
+	UFUNCTION()
+	void OnTimelineFinished();
+};

+ 34 - 0
Source/TetreeseDemo/VRGroupBase.cpp

@@ -0,0 +1,34 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+
+#include "VRGroupBase.h"
+
+// Sets default values
+AVRGroupBase::AVRGroupBase()
+{
+ 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
+	PrimaryActorTick.bCanEverTick = true;
+
+}
+
+// Called when the game starts or when spawned
+void AVRGroupBase::BeginPlay()
+{
+	Super::BeginPlay();
+	
+}
+
+// Called every frame
+void AVRGroupBase::Tick(float DeltaTime)
+{
+	Super::Tick(DeltaTime);
+
+}
+
+// Called to bind functionality to input
+void AVRGroupBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
+{
+	Super::SetupPlayerInputComponent(PlayerInputComponent);
+
+}
+

+ 29 - 0
Source/TetreeseDemo/VRGroupBase.h

@@ -0,0 +1,29 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+#pragma once
+
+#include "CoreMinimal.h"
+#include "GameFramework/Pawn.h"
+#include "VRGroupBase.generated.h"
+
+UCLASS()
+class TETREESEDEMO_API AVRGroupBase : public APawn
+{
+	GENERATED_BODY()
+
+public:
+	// Sets default values for this pawn's properties
+	AVRGroupBase();
+
+protected:
+	// Called when the game starts or when spawned
+	virtual void BeginPlay() override;
+
+public:	
+	// Called every frame
+	virtual void Tick(float DeltaTime) override;
+
+	// Called to bind functionality to input
+	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
+
+};

+ 10 - 0
Source/TetreeseDemo/VRHUDBase.cpp

@@ -0,0 +1,10 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+
+#include "VRHUDBase.h"
+
+#include "Kismet/KismetSystemLibrary.h"
+
+void AVRHUDBase::Test_Implementation() {	
+	UKismetSystemLibrary::PrintString(GetWorld(), TEXT("AVRHUDBase::Test_Implementation"));
+}

+ 22 - 0
Source/TetreeseDemo/VRHUDBase.h

@@ -0,0 +1,22 @@
+// Fill out your copyright notice in the Description page of Project Settings.
+
+#pragma once
+
+#include "CoreMinimal.h"
+#include "GameFramework/HUD.h"
+#include "VRHUDBase.generated.h"
+
+/**
+ * 
+ */
+UCLASS()
+class TETREESEDEMO_API AVRHUDBase : public AHUD
+{
+	GENERATED_BODY()
+	
+public:
+	UFUNCTION(BlueprintNativeEvent)
+	void Test();
+
+	void Test_Implementation();
+};