From b2cb9a4d0cb40abd8d141afc296f270ad0e3e502 Mon Sep 17 00:00:00 2001 From: meishibiezb <750783119@qq.com> Date: Sat, 14 Mar 2026 23:59:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/lonese/MyCharacter.cpp | 61 ++++++++++++++++++++++++++++ Source/lonese/MyCharacter.h | 37 +++++++++++++++++ Source/lonese/MyPlayerController.cpp | 4 +- Source/lonese/MyPlayerController.h | 1 - Source/lonese/lonese.Build.cs | 2 +- lonese.uproject | 59 +++++++++++++++------------ 6 files changed, 133 insertions(+), 31 deletions(-) create mode 100644 Source/lonese/MyCharacter.cpp create mode 100644 Source/lonese/MyCharacter.h diff --git a/Source/lonese/MyCharacter.cpp b/Source/lonese/MyCharacter.cpp new file mode 100644 index 0000000..874093a --- /dev/null +++ b/Source/lonese/MyCharacter.cpp @@ -0,0 +1,61 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "EnhancedInputSubsystems.h" +#include "EnhancedInputComponent.h" + +#include "MyCharacter.h" + +void AMyCharacter::Move(const FInputActionValue& Value) +{ + auto f2d = Value.Get(); + AddMovementInput(GetActorRotation().Vector()); +} + +// Sets default values +AMyCharacter::AMyCharacter() +{ + // 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; + +} + +// Called when the game starts or when spawned +void AMyCharacter::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void AMyCharacter::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + +// Called to bind functionality to input +void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) +{ + Super::SetupPlayerInputComponent(PlayerInputComponent); + + auto PlayerController = Cast(GetController()); + UEnhancedInputLocalPlayerSubsystem* Subsystem; + if (PlayerController) + { + Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer()); + } + if (Subsystem && DefaultMapping) + { + Subsystem->AddMappingContext(DefaultMapping, 0); + } + + auto EnhancedInputComponent = Cast(PlayerInputComponent); + if (EnhancedInputComponent) + { + if (MoveAction) { + EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AMyCharacter::Move); + } + } +} + diff --git a/Source/lonese/MyCharacter.h b/Source/lonese/MyCharacter.h new file mode 100644 index 0000000..e1c74c0 --- /dev/null +++ b/Source/lonese/MyCharacter.h @@ -0,0 +1,37 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Character.h" +#include "MyCharacter.generated.h" + +UCLASS() +class LONESE_API AMyCharacter : public ACharacter +{ + GENERATED_BODY() + +public: + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") + class UInputMappingContext* DefaultMapping; + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") + class UInputAction* MoveAction; + + UFUNCTION(BlueprintCallable, Category = "Move") + void Move(const FInputActionValue& Value); + + // Sets default values for this character's properties + AMyCharacter(); + + // Called every frame + virtual void Tick(float DeltaTime) override; + + // Called to bind functionality to input + virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; +protected: + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +private: + +}; diff --git a/Source/lonese/MyPlayerController.cpp b/Source/lonese/MyPlayerController.cpp index 2716e2b..bfa3d48 100644 --- a/Source/lonese/MyPlayerController.cpp +++ b/Source/lonese/MyPlayerController.cpp @@ -10,5 +10,5 @@ APawn* AMyPlayerController::GetOwnedPawn() void AMyPlayerController::BeginPlay() { - //GetPawn()->SetActorLocation(FVector(0.f, 0.f, 300.f)); -} + Super::BeginPlay(); +} \ No newline at end of file diff --git a/Source/lonese/MyPlayerController.h b/Source/lonese/MyPlayerController.h index 213f950..e8d9691 100644 --- a/Source/lonese/MyPlayerController.h +++ b/Source/lonese/MyPlayerController.h @@ -22,5 +22,4 @@ protected: virtual void BeginPlay() override; private: - }; diff --git a/Source/lonese/lonese.Build.cs b/Source/lonese/lonese.Build.cs index ab04e4c..0d58025 100644 --- a/Source/lonese/lonese.Build.cs +++ b/Source/lonese/lonese.Build.cs @@ -8,7 +8,7 @@ public class lonese : ModuleRules { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" }); PrivateDependencyModuleNames.AddRange(new string[] { }); diff --git a/lonese.uproject b/lonese.uproject index b0830fc..3776ce6 100644 --- a/lonese.uproject +++ b/lonese.uproject @@ -1,29 +1,34 @@ { - "FileVersion": 3, - "EngineAssociation": "5.7", - "Category": "", - "Description": "", - "Modules": [ - { - "Name": "lonese", - "Type": "Runtime", - "LoadingPhase": "Default", - "AdditionalDependencies": [ - "Engine" - ] - } - ], - "Plugins": [ - { - "Name": "ModelingToolsEditorMode", - "Enabled": true, - "TargetAllowList": [ - "Editor" - ] - }, - { - "Name": "Text3D", - "Enabled": true - } - ] + "FileVersion": 3, + "EngineAssociation": "5.7", + "Category": "", + "Description": "", + "Modules": [ + { + "Name": "lonese", + "Type": "Runtime", + "LoadingPhase": "Default" + } + ], + "Plugins": [ + { + "Name": "ModelingToolsEditorMode", + "Enabled": true + }, + { + "Name": "Text3D", + "Enabled": true + }, + { + "Name": "VisualStudioTools", + "Enabled": true, + "SupportedTargetPlatforms": [ + "Win64" + ] + } + ], + "TargetPlatforms": [], + "AdditionalRootDirectories": [], + "AdditionalPluginDirectories": [], + "EpicSampleNameHash": "" } \ No newline at end of file