#pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "InteractiveObjectBase.generated.h" UENUM(BlueprintType) enum class EInteractiveObjectState : uint8 { Normal UMETA(DisplayName="正常"), Hovered UMETA(DisplayName="悬停高亮"), Selected UMETA(DisplayName="已选中"), Disabled UMETA(DisplayName="不可交互"), }; DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnObjectStateChanged, EInteractiveObjectState, NewState); /** * AInteractiveObjectBase * * 所有可交互 3D 物件的基类。 * 当前场景中的可交互物件包括: * - AComputePointActor(超算数据点)—— 已实现 * - 其他演示物件(TODO: 根据需求添加子类) * * 子类需要: * 1. 重写 OnHovered / OnSelected / OnDeselected(或响应 OnStateChanged 委托) * 2. 将根 Component 设置为可被射线检测(SetCollisionResponseToChannel) * 3. 可选:重写 GetInfoTitle / GetInfoBody 供信息卡使用 */ UCLASS(Abstract, BlueprintType, Blueprintable) class PLANETCLIENT_API AInteractiveObjectBase : public AActor { GENERATED_BODY() public: AInteractiveObjectBase(); // ----------------------------------------------------------------------- // 状态变更委托 // ----------------------------------------------------------------------- UPROPERTY(BlueprintAssignable, Category="Planet|Interactive") FOnObjectStateChanged OnStateChanged; // ----------------------------------------------------------------------- // 状态 API(由 PlanetPlayerController 调用) // ----------------------------------------------------------------------- UFUNCTION(BlueprintCallable, Category="Planet|Interactive") void SetInteractiveState(EInteractiveObjectState NewState); UFUNCTION(BlueprintPure, Category="Planet|Interactive") EInteractiveObjectState GetInteractiveState() const { return CurrentState; } UFUNCTION(BlueprintPure, Category="Planet|Interactive") bool IsSelected() const { return CurrentState == EInteractiveObjectState::Selected; } UFUNCTION(BlueprintPure, Category="Planet|Interactive") bool IsHovered() const { return CurrentState == EInteractiveObjectState::Hovered; } // ----------------------------------------------------------------------- // 信息卡内容(子类可重写提供具体文本) // ----------------------------------------------------------------------- // 信息卡标题,默认返回 Actor 名 UFUNCTION(BlueprintNativeEvent, BlueprintPure, Category="Planet|Interactive") FText GetInfoTitle() const; // 信息卡正文,返回富文本格式的详情 UFUNCTION(BlueprintNativeEvent, BlueprintPure, Category="Planet|Interactive") FText GetInfoBody() const; // 信息卡图标(可选,返回空则不显示图标) UFUNCTION(BlueprintNativeEvent, BlueprintPure, Category="Planet|Interactive") UTexture2D* GetInfoIcon() const; protected: // 子类重写这三个函数来处理视觉状态变化 UFUNCTION(BlueprintNativeEvent, Category="Planet|Interactive") void OnHovered(); UFUNCTION(BlueprintNativeEvent, Category="Planet|Interactive") void OnSelected(); UFUNCTION(BlueprintNativeEvent, Category="Planet|Interactive") void OnDeselected(); UFUNCTION(BlueprintNativeEvent, Category="Planet|Interactive") void OnRestored(); // 从任何状态回到 Normal private: EInteractiveObjectState CurrentState = EInteractiveObjectState::Normal; };