Files
PHY/Source/PHY/Private/Locomotion/PHYSLSMovementBridgeComponent.cpp
2026-04-26 14:35:32 +08:00

64 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright Epic Games, Inc. All Rights Reserved.
#include "Locomotion/PHYSLSMovementBridgeComponent.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(PHYSLSMovementBridgeComponent)
#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<UPHYLocomotionSettings>();
if (!LocomotionSettings || !LocomotionSettings->bUseSmoothLocomotionSystem || !OwnerCharacter)
{
return false;
}
SLSCharacterMovementComponent = Cast<USLSCharacterMovementComponent>(OwnerCharacter->GetCharacterMovement());
if (!SLSCharacterMovementComponent)
{
return false;
}
if (!SLSIntegrationComponent)
{
SLSIntegrationComponent = OwnerCharacter->FindComponentByClass<USLSIntegrationComponent>();
}
const UPHYCharacterSettings* CharacterSettings = GetDefault<UPHYCharacterSettings>();
// 项目侧保留显式初始化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;
}