Files
ChildHood/Source/ChildHood/Interaction/InteractableActor.h
T
starmen1265 237885e3b8 fix(interaction): 修复编译错误和交互系统集成问题
- SystemDriver: EffectManager改为值持有,去掉TUniquePtr和条件编译
- SystemDriver: 补充EngineUtils.h include修复TActorIterator编译错误
- GameMode: BeginPlay自动Spawn ASystemDriver
- InteractableActor: 改为abstract基类,子类自行创建交互组件
- DoorActor: 创建DoorInteractableComp替代基类组件
- EffectManager: 实现ExecuteToggleDoor调用实际门开关逻辑
- InteractableComponent/DoorComponent: 修复GetGameInstance路径和调用方式
- EffectManager: Broadcast改为Execute(单播委托)
2026-06-12 00:51:00 +08:00

77 lines
2.5 KiB
C++

// ChildHood Project - 通用交互物 Actor 基类(v1.1 Effect/Action 架构)
// 对应技术方案: docs/technical/交互系统-技术方案.md 第3节(类设计)
// 职责:持有 Mesh,提供可被子类覆盖的交互回调
// 注意:本类为 abstract,子类必须自行创建并赋值 InteractableComp
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "InteractableActor.generated.h"
class UInteractableComponent;
class UStaticMeshComponent;
/**
* AInteractableActor
*
* 交互物 Actor 抽象基类。提供 Mesh 和交互回调框架。
* 子类必须在构造函数中创建合适的 InteractableComponent 并赋值给 InteractableComp。
*
* 组成:
* - UStaticMeshComponent* MeshComp(根组件,承载可视模型)
* - UInteractableComponent* InteractableComp(由子类创建)
*/
UCLASS(abstract)
class AInteractableActor : public AActor
{
GENERATED_BODY()
public:
AInteractableActor();
// === 组件访问 ===
/** 获取静态网格组件 */
UFUNCTION(BlueprintCallable, Category = "Interact")
UStaticMeshComponent* GetMeshComp() const { return MeshComp; }
/** 获取交互组件 */
UFUNCTION(BlueprintCallable, Category = "Interact")
UInteractableComponent* GetInteractableComp() const { return InteractableComp; }
// === 可被子类覆盖的交互回调 ===
/**
* 交互开始时调用。
* BlueprintNativeEvent,子类可在蓝图中或 C++ 中覆盖实现。
* 默认为空实现。
*/
UFUNCTION(BlueprintNativeEvent, Category = "Interact", meta = (DisplayName = "On Interact Started"))
void OnInteractStarted(UInteractableComponent* Comp);
virtual void OnInteractStarted_Implementation(UInteractableComponent* Comp);
/**
* 交互结束时调用。
* BlueprintNativeEvent,子类可在蓝图中或 C++ 中覆盖实现。
* 默认为空实现。
*/
UFUNCTION(BlueprintNativeEvent, Category = "Interact", meta = (DisplayName = "On Interact Ended"))
void OnInteractEnded(UInteractableComponent* Comp);
virtual void OnInteractEnded_Implementation(UInteractableComponent* Comp);
protected:
/** 交互物的可视模型 */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UStaticMeshComponent> MeshComp;
/**
* 交互物的交互组件(数据 + 检测 + 状态)。
* 由子类在构造函数中创建并赋值。
*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
TObjectPtr<UInteractableComponent> InteractableComp;
};