64 lines
2.4 KiB
C++
64 lines
2.4 KiB
C++
// 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;
|
||
}
|