Compare commits

...

2 Commits

Author SHA1 Message Date
662184001d Move player camera manager implementation to blueprint 2026-04-26 16:34:47 +08:00
163092858c Route player input through SLS movement 2026-04-26 16:28:55 +08:00
7 changed files with 84 additions and 69 deletions

View File

@@ -4,6 +4,7 @@
#include UE_INLINE_GENERATED_CPP_BY_NAME(PHYSLSMovementBridgeComponent)
#include "Characters/PHYCharacterBase.h"
#include "Characters/PHYCharacterSettings.h"
#include "Components/SLSCharacterMovementComponent.h"
#include "GameFramework/Character.h"
@@ -61,3 +62,46 @@ bool UPHYSLSMovementBridgeComponent::InitializeSLSMovementBridge(ACharacter* InC
bInitialized = true;
return true;
}
bool UPHYSLSMovementBridgeComponent::HandleMoveInput(const FVector2D MoveInput)
{
if (!EnsureSLSMovementBridgeReady())
{
return false;
}
const FRotator YawRotation(0.0f, OwnerCharacter->GetControlRotation().Yaw, 0.0f);
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
const FVector WorldIntent = (ForwardDirection * MoveInput.Y) + (RightDirection * MoveInput.X);
if (APHYCharacterBase* PHYCharacter = Cast<APHYCharacterBase>(OwnerCharacter))
{
PHYCharacter->SetMovementIntent(WorldIntent);
}
SLSCharacterMovementComponent->Input_OnMove(MoveInput);
return true;
}
bool UPHYSLSMovementBridgeComponent::HandleLookInput(const FVector2D LookInput)
{
if (!EnsureSLSMovementBridgeReady())
{
return false;
}
SLSCharacterMovementComponent->Input_OnLook(LookInput);
return true;
}
bool UPHYSLSMovementBridgeComponent::EnsureSLSMovementBridgeReady()
{
if (bInitialized && OwnerCharacter && SLSCharacterMovementComponent)
{
return true;
}
ACharacter* Character = OwnerCharacter ? OwnerCharacter.Get() : Cast<ACharacter>(GetOwner());
return InitializeSLSMovementBridge(Character, GenericIntegrationComponent, SLSIntegrationComponent);
}

View File

@@ -1,19 +0,0 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#include "Player/PHYPlayerCameraManager.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(PHYPlayerCameraManager)
#include "Player/PHYPlayerController.h"
FRotator APHYPlayerCameraManager::GetRotationInput_Implementation() const
{
const APHYPlayerController* PHYController = Cast<APHYPlayerController>(PCOwner);
return PHYController ? PHYController->GetCachedRotationInput() : FRotator::ZeroRotator;
}
FVector APHYPlayerCameraManager::GetMovementControlInput_Implementation() const
{
const APHYPlayerController* PHYController = Cast<APHYPlayerController>(PCOwner);
return PHYController ? PHYController->GetCachedMovementControlInput() : FVector::ZeroVector;
}

View File

@@ -5,9 +5,10 @@
#include UE_INLINE_GENERATED_CPP_BY_NAME(PHYPlayerController)
#include "Characters/PHYPlayerCharacter.h"
#include "Characters/PHYCharacterSettings.h"
#include "GIPS_InputSystemComponent.h"
#include "InputActionValue.h"
#include "Player/PHYPlayerCameraManager.h"
#include "Locomotion/PHYSLSMovementBridgeComponent.h"
#include "PHYGameplayTags.h"
namespace
@@ -40,7 +41,14 @@ namespace
APHYPlayerController::APHYPlayerController(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
PlayerCameraManagerClass = APHYPlayerCameraManager::StaticClass();
const UPHYCharacterSettings* CharacterSettings = GetDefault<UPHYCharacterSettings>();
if (CharacterSettings && !CharacterSettings->DefaultPlayerCameraManagerClass.IsNull())
{
if (UClass* CameraManagerClass = CharacterSettings->DefaultPlayerCameraManagerClass.LoadSynchronous())
{
PlayerCameraManagerClass = CameraManagerClass;
}
}
}
void APHYPlayerController::BeginPlay()
@@ -148,21 +156,8 @@ bool APHYPlayerController::HandleMoveInput(const FInputActionInstance& ActionDat
CachedMovementInput = IsInputReleased(TriggerEvent) ? FVector2D::ZeroVector : ExtractAxis2D(ActionData.GetValue());
const FRotator CurrentControlRotation = GetControlRotation();
const FRotator YawRotation(0.0f, CurrentControlRotation.Yaw, 0.0f);
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
const FVector WorldIntent = (ForwardDirection * CachedMovementInput.Y) + (RightDirection * CachedMovementInput.X);
PHYCharacter->SetMovementIntent(WorldIntent);
if (!CachedMovementInput.IsNearlyZero())
{
PHYCharacter->AddMovementInput(ForwardDirection, CachedMovementInput.Y);
PHYCharacter->AddMovementInput(RightDirection, CachedMovementInput.X);
}
return true;
UPHYSLSMovementBridgeComponent* SLSMovementBridge = PHYCharacter->GetSLSMovementBridgeComponent();
return SLSMovementBridge ? SLSMovementBridge->HandleMoveInput(CachedMovementInput) : false;
}
bool APHYPlayerController::ConsumeMoveProcessorGuard(const ETriggerEvent TriggerEvent)
@@ -198,11 +193,12 @@ bool APHYPlayerController::HandleLookInput(const FInputActionInstance& ActionDat
CachedLookInput = IsInputReleased(TriggerEvent) ? FVector2D::ZeroVector : ExtractAxis2D(ActionData.GetValue());
CachedRotationInput = FRotator(CachedLookInput.Y, CachedLookInput.X, 0.0f);
if (!CachedLookInput.IsNearlyZero())
APHYPlayerCharacter* PHYCharacter = GetPHYPlayerCharacter();
if (!PHYCharacter)
{
AddYawInput(CachedLookInput.X);
AddPitchInput(CachedLookInput.Y);
return false;
}
return true;
UPHYSLSMovementBridgeComponent* SLSMovementBridge = PHYCharacter->GetSLSMovementBridgeComponent();
return SLSMovementBridge ? SLSMovementBridge->HandleLookInput(CachedLookInput) : false;
}

View File

@@ -9,9 +9,9 @@
class APHYAICharacter;
class APHYAIController;
class APHYPlayerCameraManager;
class APHYPlayerCharacter;
class APHYPlayerController;
class APlayerCameraManager;
class UUGC_CameraDataAssetBase;
/**
@@ -75,7 +75,7 @@ public:
/** @brief 玩家相机管理器默认软类引用。 */
UPROPERTY(Config, EditDefaultsOnly, Category="PHY|Character")
TSoftClassPtr<APHYPlayerCameraManager> DefaultPlayerCameraManagerClass;
TSoftClassPtr<APlayerCameraManager> DefaultPlayerCameraManagerClass;
/** @brief UGC 默认 CameraData 软引用,首期不强制制作资产。 */
UPROPERTY(Config, EditDefaultsOnly, Category="PHY|Character")

View File

@@ -35,6 +35,22 @@ public:
UFUNCTION(BlueprintCallable, Category="PHY|Locomotion|SLS")
bool InitializeSLSMovementBridge(ACharacter* InCharacter, UActorComponent* InGenericIntegrationComponent, USLSIntegrationComponent* InSLSIntegrationComponent = nullptr);
/**
* @brief 通过 SLS 原生移动输入接口处理二维移动输入。
* @param MoveInput X 为右移输入Y 为前进输入。
* @return 成功路由到 SLS 运动组件时返回 true。
*/
UFUNCTION(BlueprintCallable, Category="PHY|Locomotion|SLS|Input")
bool HandleMoveInput(FVector2D MoveInput);
/**
* @brief 通过 SLS 原生视角输入接口处理二维视角输入。
* @param LookInput X 为 Yaw 输入Y 为 Pitch 输入。
* @return 成功路由到 SLS 运动组件时返回 true。
*/
UFUNCTION(BlueprintCallable, Category="PHY|Locomotion|SLS|Input")
bool HandleLookInput(FVector2D LookInput);
/** @brief 获取桥接到的角色。 */
UFUNCTION(BlueprintCallable, BlueprintPure, Category="PHY|Locomotion|SLS")
ACharacter* GetOwnerCharacter() const { return OwnerCharacter; }
@@ -56,6 +72,9 @@ public:
bool IsSLSMovementBridgeInitialized() const { return bInitialized; }
protected:
/** @brief 确保桥接组件已经缓存角色和 SLS 运动组件。 */
bool EnsureSLSMovementBridgeReady();
/** @brief 拥有 SLS 运动能力的角色。 */
UPROPERTY(Transient, BlueprintReadOnly, Category="PHY|Locomotion|SLS")
TObjectPtr<ACharacter> OwnerCharacter;

View File

@@ -1,25 +0,0 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Camera/UGC_PlayerCameraManager.h"
#include "PHYPlayerCameraManager.generated.h"
/**
* @brief PHY 玩家相机管理器。
*
* 该类型从 PlayerController 的 C++ 缓存读取输入,不把 UGC 蓝图 Pawn Interface 作为主路径。
*/
UCLASS(BlueprintType, Blueprintable)
class PHY_API APHYPlayerCameraManager : public AUGC_PlayerCameraManager
{
GENERATED_BODY()
public:
/** @brief 返回玩家视角输入。 */
virtual FRotator GetRotationInput_Implementation() const override;
/** @brief 返回玩家移动控制输入。 */
virtual FVector GetMovementControlInput_Implementation() const override;
};