refactor(interaction): 适配v1.1架构的角色/管理器/交互物改动

- Character: 替换UInteractionManager为UInteractionPromptComponent
- GameInstance: 空壳化,持久数据迁移至PersistenceSubsystem
- InteractionManager: 重写为普通C++ FInteractionManager
- InteractableComponent: 碰撞回调接入ASystemDriver注册

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 23:21:46 +08:00
parent 4bf678b937
commit c14c63f30d
7 changed files with 391 additions and 1085 deletions
+72 -19
View File
@@ -1,3 +1,8 @@
// ChildHood Project - 玩家角色 实现(v1.1 Effect/Action 架构适配)
// 变更:通过 ASystemDriver 访问 FInteractionManager + FEffectManager
// 新增 BeginPlay 初始化 PromptComponent
// 删除对旧 UInteractionManager 的依赖
// Copyright Epic Games, Inc. All Rights Reserved.
#include "ChildHoodCharacter.h"
@@ -11,7 +16,12 @@
#include "EnhancedInputSubsystems.h"
#include "InputActionValue.h"
#include "ChildHood.h"
#include "Interaction/InteractionPromptComponent.h"
#include "SystemDriver.h"
#include "Interaction/InteractionManager.h"
#include "Interaction/EffectManager.h"
#include "Interaction/InteractableComponent.h"
#include "Interaction/InteractionTypes.h"
AChildHoodCharacter::AChildHoodCharacter()
{
@@ -55,8 +65,22 @@ AChildHoodCharacter::AChildHoodCharacter()
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
FollowCamera->bUsePawnControlRotation = false;
// 创建交互管理器组件
InteractionManager = CreateDefaultSubobject<UInteractionManager>(TEXT("InteractionManager"));
// 创建交互提示组件(替代旧 InteractionManager)
PromptComponent = CreateDefaultSubobject<UInteractionPromptComponent>(TEXT("PromptComponent"));
}
void AChildHoodCharacter::BeginPlay()
{
Super::BeginPlay();
// 初始化 PromptComponent — 将其与 ASystemDriver 关联
if (PromptComponent)
{
if (ASystemDriver* Driver = ASystemDriver::Get(this))
{
PromptComponent->Initialize(Driver);
}
}
}
void AChildHoodCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
@@ -71,7 +95,7 @@ void AChildHoodCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInput
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AChildHoodCharacter::Look);
EnhancedInputComponent->BindAction(MouseLookAction, ETriggerEvent::Triggered, this, &AChildHoodCharacter::Look);
// Interaction — delegates to InteractionManager
// Interaction — delegates to ASystemDriver
if (InteractAction)
{
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Started, this, &AChildHoodCharacter::OnInteract);
@@ -111,30 +135,59 @@ void AChildHoodCharacter::Look(const FInputActionValue& Value)
void AChildHoodCharacter::OnInteract(const FInputActionValue& Value)
{
if (UInteractionManager* IM = GetInteractionManager())
ASystemDriver* Driver = ASystemDriver::Get(this);
if (!Driver) return;
auto& Mgr = Driver->GetInteractionManager();
auto& EFM = Driver->GetEffectManager();
// E 键三重功能:
// 1. Free 状态:发起交互
// 2. WaitForInput 暂停态:恢复 Effect(观察/对话类按 E 继续)
// 3. 可取消 Effect 执行中:取消 Effect
if (Mgr.GetState() == EInteractionState::Free)
{
// E 键双重功能:Free 发起交互,Active 结束交互
IM->BeginInteract();
IM->CancelInteract();
// 发起交互
auto* Selected = Mgr.BeginInteract();
if (!Selected) return;
SetInteracting(true);
FEffectContext Ctx;
Ctx.Instigator = this;
Ctx.TargetComp = Selected;
Ctx.TargetActor = Selected->GetOwner();
EFM.PlayEffect(Selected->GetInteractableData().InteractEffect, Ctx);
}
else
{
// Executing 状态 → 尝试取消/恢复
EFM.CancelEffect();
}
}
void AChildHoodCharacter::OnCancel(const FInputActionValue& Value)
{
if (UInteractionManager* IM = GetInteractionManager())
{
IM->CancelInteract();
}
ASystemDriver* Driver = ASystemDriver::Get(this);
if (!Driver) return;
auto& EFM = Driver->GetEffectManager();
EFM.CancelEffect();
}
void AChildHoodCharacter::OnSwitchInteract(const FInputActionValue& Value)
{
if (UInteractionManager* IM = GetInteractionManager())
{
float DirectionValue = Value.Get<float>();
int32 Direction = (DirectionValue >= 0.f) ? 1 : -1;
IM->SwitchTarget(Direction);
}
ASystemDriver* Driver = ASystemDriver::Get(this);
if (!Driver) return;
auto& Mgr = Driver->GetInteractionManager();
// 交互中不可切换
if (Mgr.GetState() != EInteractionState::Free) return;
float DirectionValue = Value.Get<float>();
int32 Direction = (DirectionValue >= 0.f) ? 1 : -1;
Mgr.SwitchTarget(Direction);
}
void AChildHoodCharacter::DoMove(float Right, float Forward)
@@ -177,9 +230,9 @@ void AChildHoodCharacter::DoLook(float Yaw, float Pitch)
// 交互系统方法
// ============================================================================
UInteractionManager* AChildHoodCharacter::GetInteractionManager() const
UInteractionPromptComponent* AChildHoodCharacter::GetPromptComponent() const
{
return InteractionManager;
return PromptComponent;
}
void AChildHoodCharacter::SetInteracting(bool bValue)