From 88d01f588b2b3647d88ab13aac66422e6e3bf6b7 Mon Sep 17 00:00:00 2001 From: cit110 <840418418@qq.com> Date: Sun, 26 Apr 2026 18:13:19 +0800 Subject: [PATCH] Remove redundant SLS movement bridge --- .../Private/Characters/PHYCharacterBase.cpp | 13 ++- .../PHYSLSMovementBridgeComponent.cpp | 107 ------------------ .../Private/Player/PHYPlayerController.cpp | 26 ++++- .../PHY/Public/Characters/PHYCharacterBase.h | 9 -- .../PHYSLSMovementBridgeComponent.h | 97 ---------------- 5 files changed, 30 insertions(+), 222 deletions(-) delete mode 100644 Source/PHY/Private/Locomotion/PHYSLSMovementBridgeComponent.cpp delete mode 100644 Source/PHY/Public/Locomotion/PHYSLSMovementBridgeComponent.h diff --git a/Source/PHY/Private/Characters/PHYCharacterBase.cpp b/Source/PHY/Private/Characters/PHYCharacterBase.cpp index d3b6e76..d4ecd90 100644 --- a/Source/PHY/Private/Characters/PHYCharacterBase.cpp +++ b/Source/PHY/Private/Characters/PHYCharacterBase.cpp @@ -17,8 +17,8 @@ #include "GGA_AbilitySystemComponent.h" #include "GameFramework/CharacterMovementComponent.h" #include "Interaction/GGS_InteractionSystemComponent.h" -#include "Locomotion/PHYSLSMovementBridgeComponent.h" #include "Net/UnrealNetwork.h" +#include "PHYConfigSettings.h" #include "PHYGameplayTags.h" #include "Ragdoll/GGS_RagdollComponent.h" #include "Components/SLSCharacterMovementComponent.h" @@ -47,7 +47,6 @@ APHYCharacterBase::APHYCharacterBase(const FObjectInitializer& ObjectInitializer RagdollComponent = CreateDefaultSubobject(TEXT("RagdollComponent")); ContextEffectComponent = CreateDefaultSubobject(TEXT("ContextEffectComponent")); MeshBridgeComponent = CreateDefaultSubobject(TEXT("MeshBridgeComponent")); - SLSMovementBridgeComponent = CreateDefaultSubobject(TEXT("SLSMovementBridgeComponent")); SLSIntegrationComponent = CreateDefaultSubobject(TEXT("SLSIntegrationComponent")); USLSIntegrationDataAsset* SLSIntegrationRuntimeDataAsset = CreateDefaultSubobject(TEXT("SLSIntegrationRuntimeDataAsset")); @@ -126,9 +125,15 @@ void APHYCharacterBase::BeginPlay() ContextEffectComponent->SetGameplayTagsProvider(this); } - if (SLSMovementBridgeComponent) + if (const UPHYLocomotionSettings* LocomotionSettings = GetDefault(); LocomotionSettings && LocomotionSettings->bUseSmoothLocomotionSystem) { - SLSMovementBridgeComponent->InitializeSLSMovementBridge(this, GenericIntegrationComponent, SLSIntegrationComponent); + if (USLSCharacterMovementComponent* SLSMovementComponent = GetSLSCharacterMovementComponent()) + { + const UPHYCharacterSettings* CharacterSettings = GetDefault(); + SLSMovementComponent->ApplyBaseSLSCharacterMovementSettings(); + SLSMovementComponent->MaxWalkSpeed = CharacterSettings ? CharacterSettings->DefaultMaxWalkSpeed : SLSMovementComponent->MaxWalkSpeed; + SLSMovementComponent->MaxAcceleration = CharacterSettings ? CharacterSettings->DefaultMaxAcceleration : SLSMovementComponent->MaxAcceleration; + } } UGameFrameworkComponentManager::SendGameFrameworkComponentExtensionEvent(this, UGameFrameworkComponentManager::NAME_GameActorReady); diff --git a/Source/PHY/Private/Locomotion/PHYSLSMovementBridgeComponent.cpp b/Source/PHY/Private/Locomotion/PHYSLSMovementBridgeComponent.cpp deleted file mode 100644 index d2947f6..0000000 --- a/Source/PHY/Private/Locomotion/PHYSLSMovementBridgeComponent.cpp +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include "Locomotion/PHYSLSMovementBridgeComponent.h" - -#include UE_INLINE_GENERATED_CPP_BY_NAME(PHYSLSMovementBridgeComponent) - -#include "Characters/PHYCharacterBase.h" -#include "Characters/PHYCharacterSettings.h" -#include "Components/SLSCharacterMovementComponent.h" -#include "GameFramework/Character.h" -#include "PHYConfigSettings.h" -#include "SLSIntegrationComponent.h" - -UPHYSLSMovementBridgeComponent::UPHYSLSMovementBridgeComponent() -{ - PrimaryComponentTick.bCanEverTick = false; - SetIsReplicatedByDefault(false); -} - -bool UPHYSLSMovementBridgeComponent::InitializeSLSMovementBridge(ACharacter* InCharacter, UActorComponent* InGenericIntegrationComponent, USLSIntegrationComponent* InSLSIntegrationComponent) -{ - bInitialized = false; - OwnerCharacter = InCharacter; - GenericIntegrationComponent = InGenericIntegrationComponent; - SLSIntegrationComponent = InSLSIntegrationComponent; - SLSCharacterMovementComponent = nullptr; - - const UPHYLocomotionSettings* LocomotionSettings = GetDefault(); - if (!LocomotionSettings || !LocomotionSettings->bUseSmoothLocomotionSystem || !OwnerCharacter) - { - return false; - } - - SLSCharacterMovementComponent = Cast(OwnerCharacter->GetCharacterMovement()); - if (!SLSCharacterMovementComponent) - { - return false; - } - - if (!SLSIntegrationComponent) - { - SLSIntegrationComponent = OwnerCharacter->FindComponentByClass(); - } - - const UPHYCharacterSettings* CharacterSettings = GetDefault(); - - // 项目侧保留显式初始化,SLSIntegrationComponent 只作为运动层集中集成入口。 - SLSCharacterMovementComponent->Config.InitComponentType = ESLSComponentInitType::ManualInit; - SLSCharacterMovementComponent->Config.MovementType = ESLSMovementType::Jog; - SLSCharacterMovementComponent->Config.RotationMode = ESLSRotationMode::VelocityDirection; - SLSCharacterMovementComponent->Config.bEnableSprintInLookingDirectionRotationMode = true; - - SLSCharacterMovementComponent->ApplyBaseSLSCharacterMovementSettings(); - - if (CharacterSettings) - { - SLSCharacterMovementComponent->MaxWalkSpeed = CharacterSettings->DefaultMaxWalkSpeed; - SLSCharacterMovementComponent->MaxAcceleration = CharacterSettings->DefaultMaxAcceleration; - } - - SLSCharacterMovementComponent->InitializeMovementComponent(SLSCharacterMovementComponent->Config); - 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(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(GetOwner()); - return InitializeSLSMovementBridge(Character, GenericIntegrationComponent, SLSIntegrationComponent); -} diff --git a/Source/PHY/Private/Player/PHYPlayerController.cpp b/Source/PHY/Private/Player/PHYPlayerController.cpp index e3416db..de2dedb 100644 --- a/Source/PHY/Private/Player/PHYPlayerController.cpp +++ b/Source/PHY/Private/Player/PHYPlayerController.cpp @@ -6,9 +6,9 @@ #include "Characters/PHYPlayerCharacter.h" #include "Characters/PHYCharacterSettings.h" +#include "Components/SLSCharacterMovementComponent.h" #include "GIPS_InputSystemComponent.h" #include "InputActionValue.h" -#include "Locomotion/PHYSLSMovementBridgeComponent.h" #include "PHYGameplayTags.h" namespace @@ -156,8 +156,19 @@ bool APHYPlayerController::HandleMoveInput(const FInputActionInstance& ActionDat CachedMovementInput = IsInputReleased(TriggerEvent) ? FVector2D::ZeroVector : ExtractAxis2D(ActionData.GetValue()); - UPHYSLSMovementBridgeComponent* SLSMovementBridge = PHYCharacter->GetSLSMovementBridgeComponent(); - return SLSMovementBridge ? SLSMovementBridge->HandleMoveInput(CachedMovementInput) : false; + const FRotator YawRotation(0.0f, PHYCharacter->GetControlRotation().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 (USLSCharacterMovementComponent* SLSMovementComponent = PHYCharacter->GetSLSCharacterMovementComponent()) + { + SLSMovementComponent->Input_OnMove(CachedMovementInput); + return true; + } + + return false; } bool APHYPlayerController::ConsumeMoveProcessorGuard(const ETriggerEvent TriggerEvent) @@ -199,6 +210,11 @@ bool APHYPlayerController::HandleLookInput(const FInputActionInstance& ActionDat return false; } - UPHYSLSMovementBridgeComponent* SLSMovementBridge = PHYCharacter->GetSLSMovementBridgeComponent(); - return SLSMovementBridge ? SLSMovementBridge->HandleLookInput(CachedLookInput) : false; + if (USLSCharacterMovementComponent* SLSMovementComponent = PHYCharacter->GetSLSCharacterMovementComponent()) + { + SLSMovementComponent->Input_OnLook(CachedLookInput); + return true; + } + + return false; } diff --git a/Source/PHY/Public/Characters/PHYCharacterBase.h b/Source/PHY/Public/Characters/PHYCharacterBase.h index b9c2fec..282d9f3 100644 --- a/Source/PHY/Public/Characters/PHYCharacterBase.h +++ b/Source/PHY/Public/Characters/PHYCharacterBase.h @@ -19,7 +19,6 @@ class UGGS_InteractionSystemComponent; class UGGS_RagdollComponent; class UPHYCharacterMeshBridgeComponent; class UPHYCharacterStateComponent; -class UPHYSLSMovementBridgeComponent; class USkeletalMeshComponent; class USLSCharacterMovementComponent; class USLSIntegrationComponent; @@ -130,10 +129,6 @@ public: UFUNCTION(BlueprintCallable, BlueprintPure, Category="PHY|Character|Animation") UPHYCharacterMeshBridgeComponent* GetMeshBridgeComponent() const { return MeshBridgeComponent; } - /** @brief 获取 PHY SLS 运动桥接组件。 */ - UFUNCTION(BlueprintCallable, BlueprintPure, Category="PHY|Character|Locomotion") - UPHYSLSMovementBridgeComponent* GetSLSMovementBridgeComponent() const { return SLSMovementBridgeComponent; } - /** @brief 获取 SLS 角色运动组件。 */ UFUNCTION(BlueprintCallable, BlueprintPure, Category="PHY|Character|Locomotion") USLSCharacterMovementComponent* GetSLSCharacterMovementComponent() const; @@ -270,10 +265,6 @@ protected: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="PHY|Character|Animation") TObjectPtr MeshBridgeComponent; - /** @brief PHY 对 SLS 运动系统的桥接组件。 */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="PHY|Character|Locomotion") - TObjectPtr SLSMovementBridgeComponent; - /** @brief SLS 插件集成入口组件,由运动层集中接入。 */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="PHY|Character|Locomotion") TObjectPtr SLSIntegrationComponent; diff --git a/Source/PHY/Public/Locomotion/PHYSLSMovementBridgeComponent.h b/Source/PHY/Public/Locomotion/PHYSLSMovementBridgeComponent.h deleted file mode 100644 index 6ef2293..0000000 --- a/Source/PHY/Public/Locomotion/PHYSLSMovementBridgeComponent.h +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "CoreMinimal.h" -#include "Components/ActorComponent.h" -#include "PHYSLSMovementBridgeComponent.generated.h" - -class ACharacter; -class USLSCharacterMovementComponent; -class USLSIntegrationComponent; - -/** - * @brief PHY 对 Smooth Locomotion System 的首期运动桥接组件。 - * - * 该组件缓存并初始化明确接入的 SLS 运动组件和 SLSIntegrationComponent, - * 但不承担相机系统职责。 - */ -UCLASS(BlueprintType, Blueprintable) -class PHY_API UPHYSLSMovementBridgeComponent : public UActorComponent -{ - GENERATED_BODY() - -public: - /** @brief 创建运动桥接组件。 */ - UPHYSLSMovementBridgeComponent(); - - /** - * @brief 初始化 SLS 运动桥接。 - * @param InCharacter 拥有该桥接组件的角色。 - * @param InGenericIntegrationComponent 可选的 Generic 集成入口组件。 - * @param InSLSIntegrationComponent SLS 插件集成入口组件。 - * @return 初始化是否成功。 - */ - 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; } - - /** @brief 获取 SLS 角色运动组件。 */ - UFUNCTION(BlueprintCallable, BlueprintPure, Category="PHY|Locomotion|SLS") - USLSCharacterMovementComponent* GetSLSCharacterMovementComponent() const { return SLSCharacterMovementComponent; } - - /** @brief 获取 SLS 插件集成入口组件。 */ - UFUNCTION(BlueprintCallable, BlueprintPure, Category="PHY|Locomotion|SLS") - USLSIntegrationComponent* GetSLSIntegrationComponent() const { return SLSIntegrationComponent; } - - /** @brief 获取可选的 Generic 集成入口组件。 */ - UFUNCTION(BlueprintCallable, BlueprintPure, Category="PHY|Locomotion|SLS") - UActorComponent* GetGenericIntegrationComponent() const { return GenericIntegrationComponent; } - - /** @brief 查询桥接是否已完成初始化。 */ - UFUNCTION(BlueprintCallable, BlueprintPure, Category="PHY|Locomotion|SLS") - bool IsSLSMovementBridgeInitialized() const { return bInitialized; } - -protected: - /** @brief 确保桥接组件已经缓存角色和 SLS 运动组件。 */ - bool EnsureSLSMovementBridgeReady(); - - /** @brief 拥有 SLS 运动能力的角色。 */ - UPROPERTY(Transient, BlueprintReadOnly, Category="PHY|Locomotion|SLS") - TObjectPtr OwnerCharacter; - - /** @brief SLS 核心角色运动组件。 */ - UPROPERTY(Transient, BlueprintReadOnly, Category="PHY|Locomotion|SLS") - TObjectPtr SLSCharacterMovementComponent; - - /** @brief SLS 插件集成入口组件。 */ - UPROPERTY(Transient, BlueprintReadOnly, Category="PHY|Locomotion|SLS") - TObjectPtr SLSIntegrationComponent; - - /** @brief GenericGameSystem 提供的可选集成入口。 */ - UPROPERTY(Transient, BlueprintReadOnly, Category="PHY|Locomotion|SLS") - TObjectPtr GenericIntegrationComponent; - - /** @brief 桥接初始化状态。 */ - UPROPERTY(Transient, BlueprintReadOnly, Category="PHY|Locomotion|SLS") - bool bInitialized = false; -};