70 lines
2.4 KiB
C++
70 lines
2.4 KiB
C++
// ChildHood Project - 通用交互物 Actor 基类
|
|
// 对应技术方案: docs/technical/交互系统-技术方案.md 第3节(类设计)
|
|
// 职责:持有 Mesh + InteractableComponent,提供可被子类覆盖的交互回调
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "GameFramework/Actor.h"
|
|
#include "InteractableActor.generated.h"
|
|
|
|
class UInteractableComponent;
|
|
|
|
/**
|
|
* AInteractableActor
|
|
*
|
|
* 通用交互物 Actor 基类。场景中的每个交互物(冰箱、门、NPC 等)
|
|
* 均为该类的实例或其子类的实例。
|
|
*
|
|
* 组成:
|
|
* - UStaticMeshComponent* MeshComp(根组件,承载可视模型)
|
|
* - UInteractableComponent* InteractableComp(交互逻辑与数据)
|
|
*
|
|
* 子类可覆盖 OnInteractStarted / OnInteractEnded 以实现类型特定行为,
|
|
* 如门开关时的 Mesh 旋转、拾取物的消失效果等。
|
|
*/
|
|
UCLASS()
|
|
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; }
|
|
|
|
// === 可被子类覆盖的交互回调 ===
|
|
|
|
/**
|
|
* 交互开始时调用(门开关切换、状态恢复时也调用)。
|
|
* 默认实现:门类型根据开关状态对 Mesh 做 Yaw 旋转(开门+90度/关门0度)。
|
|
*/
|
|
UFUNCTION(BlueprintNativeEvent, Category = "Interact")
|
|
void OnInteractStarted(UInteractableComponent* Comp);
|
|
virtual void OnInteractStarted_Implementation(UInteractableComponent* Comp);
|
|
|
|
/** 交互结束时调用。默认为空实现,子类可覆盖。 */
|
|
UFUNCTION(BlueprintNativeEvent, Category = "Interact")
|
|
void OnInteractEnded(UInteractableComponent* Comp);
|
|
virtual void OnInteractEnded_Implementation(UInteractableComponent* Comp);
|
|
|
|
protected:
|
|
|
|
/** 交互物的可视模型 */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
|
|
UStaticMeshComponent* MeshComp;
|
|
|
|
/** 交互物的交互组件(数据 + 检测 + 状态) */
|
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
|
|
UInteractableComponent* InteractableComp;
|
|
};
|