48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
// ChildHood Project - 通用交互物 Actor 基类 实现
|
|
|
|
#include "Interaction/InteractableActor.h"
|
|
#include "Interaction/InteractableComponent.h"
|
|
|
|
#include "Components/StaticMeshComponent.h"
|
|
|
|
// ============================================================================
|
|
// 构造函数
|
|
// ============================================================================
|
|
|
|
AInteractableActor::AInteractableActor()
|
|
{
|
|
PrimaryActorTick.bCanEverTick = false;
|
|
|
|
// 创建 Mesh 为根组件
|
|
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
|
|
RootComponent = MeshComp;
|
|
MeshComp->SetCollisionProfileName(TEXT("BlockAll"));
|
|
|
|
// 创建交互组件(UActorComponent 不需要 SetupAttachment,数据驱动型组件)
|
|
InteractableComp = CreateDefaultSubobject<UInteractableComponent>(TEXT("InteractableComp"));
|
|
}
|
|
|
|
// ============================================================================
|
|
// 交互回调
|
|
// ============================================================================
|
|
|
|
void AInteractableActor::OnInteractStarted_Implementation(UInteractableComponent* Comp)
|
|
{
|
|
if (!Comp || !MeshComp) return;
|
|
|
|
const FInteractableData& Data = Comp->GetInteractableData();
|
|
|
|
// 门类型:根据开关状态旋转 Mesh
|
|
if (Data.Type == EInteractType::Operate && Data.OperateSubType == EOperateSubType::Door)
|
|
{
|
|
FRotator CurrentRot = MeshComp->GetRelativeRotation();
|
|
float TargetYaw = Comp->IsDoorOpen() ? 90.0f : 0.0f;
|
|
MeshComp->SetRelativeRotation(FRotator(CurrentRot.Pitch, TargetYaw, CurrentRot.Roll));
|
|
}
|
|
}
|
|
|
|
void AInteractableActor::OnInteractEnded_Implementation(UInteractableComponent* Comp)
|
|
{
|
|
// 默认空实现,子类可覆盖
|
|
}
|