当前位置: 首页 > news >正文

虚幻引擎5 GAS开发俯视角RPG游戏 P06-28 构建属性菜单小部件控制器

1.创建属性菜单小部件控制器

Source/CC_Aura/Public/UI/WidgetController/CC_AttributeMenuWidgetController.h:

// 版权归陈超所有#pragma once#include "CoreMinimal.h"
#include "UI/WidgetController/CC_WidgetController.h"
#include "CC_AttributeMenuWidgetController.generated.h"/*** */
UCLASS(Blueprintable)
class CC_AURA_API UCC_AttributeMenuWidgetController : public UCC_WidgetController
{GENERATED_BODY()public://广播初始值virtual void BroadcastInitialValues() override;//依赖的绑定回调函数virtual void BindCallbacksToDependencies() override;};

Source/CC_Aura/Private/UI/WidgetController/CC_AttributeMenuWidgetController.cpp:

// 版权归陈超所有#include "UI/WidgetController/CC_AttributeMenuWidgetController.h"void UCC_AttributeMenuWidgetController::BroadcastInitialValues()
{}void UCC_AttributeMenuWidgetController::BindCallbacksToDependencies()
{}

2.构建蓝图函数库:

添加静态函数,能随地得到小部件的控制器

Source/CC_Aura/Public/BlueprintFunctionLibrary/CC_BlueprintFunctionLibrary.h

// 版权归陈超所有#pragma once#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CC_BlueprintFunctionLibrary.generated.h"class UCC_AttributeMenuWidgetController;
class UCC_OverlayWidgetController;
/*** */
UCLASS()
class CC_AURA_API UCC_BlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{GENERATED_BODY()public:UFUNCTION(BlueprintPure, Category="CC_BlueprintFunctionLibrary|OverlayWidgetController")static UCC_OverlayWidgetController* GetOverlayWidgetController(const UObject* WorldContextObject);UFUNCTION(BlueprintPure, Category="CC_BlueprintFunctionLibrary|AttributeMenuWidgetController")static UCC_AttributeMenuWidgetController* GetAttributeMenuWidgetController(const UObject* WorldContextObject);};

Source/CC_Aura/Private/BlueprintFunctionLibrary/CC_BlueprintFunctionLibrary.cpp:

// 版权归陈超所有#include "BlueprintFunctionLibrary/CC_BlueprintFunctionLibrary.h"#include "Kismet/GameplayStatics.h"
#include "Player/CC_PlayerState.h"
#include "UI/HUD/CC_HUD.h"
#include "UI/WidgetController/CC_WidgetController.h"UCC_OverlayWidgetController* UCC_BlueprintFunctionLibrary::GetOverlayWidgetController(const UObject* WorldContextObject)
{APlayerController* PlayerController = UGameplayStatics::GetPlayerController(WorldContextObject, 0);if (!PlayerController) return nullptr;ACC_HUD* CC_HUD = Cast<ACC_HUD>(PlayerController->GetHUD());if (!CC_HUD) return nullptr;ACC_PlayerState* PlayerState = PlayerController->GetPlayerState<ACC_PlayerState>();if (!PlayerState) return nullptr;UAbilitySystemComponent* AbilitySystemComponent = PlayerState->GetAbilitySystemComponent();if (!AbilitySystemComponent) return nullptr;UAttributeSet* AttributeSet = PlayerState->GetAttributeSet();if (!AttributeSet) return nullptr;FWidgetControllerParams WidgetControllerParams(PlayerController, PlayerState, AbilitySystemComponent, AttributeSet);return CC_HUD->GetOverlayWidgetController(WidgetControllerParams);
}UCC_AttributeMenuWidgetController* UCC_BlueprintFunctionLibrary::GetAttributeMenuWidgetController(const UObject* WorldContextObject)
{APlayerController* PlayerController = UGameplayStatics::GetPlayerController(WorldContextObject, 0);if (!PlayerController) return nullptr;ACC_HUD* CC_HUD = Cast<ACC_HUD>(PlayerController->GetHUD());if (!CC_HUD) return nullptr;ACC_PlayerState* PlayerState = PlayerController->GetPlayerState<ACC_PlayerState>();if (!PlayerState) return nullptr;UAbilitySystemComponent* AbilitySystemComponent = PlayerState->GetAbilitySystemComponent();if (!AbilitySystemComponent) return nullptr;UAttributeSet* AttributeSet = PlayerState->GetAttributeSet();if (!AttributeSet) return nullptr;FWidgetControllerParams WidgetControllerParams(PlayerController, PlayerState, AbilitySystemComponent, AttributeSet);return CC_HUD->GetAttributeMenuWidgetController(WidgetControllerParams);
}

其中,在CC_HUD类中,添加属性菜单控制器,以及获取方法:

Source/CC_Aura/Public/UI/HUD/CC_HUD.h:

	UPROPERTY()TObjectPtr<UCC_AttributeMenuWidgetController> AttributeMenuWidgetController;	UPROPERTY(EditAnywhere)TSubclassOf<UCC_AttributeMenuWidgetController> AttributeMenuWidgetControllerClass;
UCC_AttributeMenuWidgetController* GetAttributeMenuWidgetController(const FWidgetControllerParams& FWCParams);

Source/CC_Aura/Private/UI/HUD/CC_HUD.cpp:

UCC_AttributeMenuWidgetController* ACC_HUD::GetAttributeMenuWidgetController(const FWidgetControllerParams& FWCParams)
{if (AttributeMenuWidgetController == nullptr)	{AttributeMenuWidgetController = NewObject<UCC_AttributeMenuWidgetController>(this, AttributeMenuWidgetControllerClass);		AttributeMenuWidgetController->SetWidgetControllerParams(FWCParams);		}return AttributeMenuWidgetController;
}

3.创建属性菜单小部件控制器蓝图BP_AttributeMenuWidgetController:

在HUD中配置:

4.在WBP_AttributeMenu中添加控制器:

验证:

在回调函数中,打印控制器:

效果:

http://www.dtcms.com/a/557369.html

相关文章:

  • 线程协作——生产者消费者问题:
  • ROS2系列 (14) : 服务通信介绍——双向通信的核心机制
  • C语言入门(十三):操作符详解(1)
  • 化妆品设计网站家用宽带做网站
  • 雄安建设集团 网站湖北做网站教程哪家好
  • 晋城市 制作网站织梦网站文章发布模板下载
  • Microsoft Speech TTS微软语音识别ISpeechRecoGrammar,ISpeechRecoResult
  • 【Java 开发日记】运行时有出现过什么异常?
  • 企业门户网站设计扬州网页设计培训
  • 从大模型中的chat_template了解jinja模板语法
  • Pandas--数据选择与索引
  • Linux下编译WebSocket++
  • 淄博哪家公司做网站最好莱钢吧贴吧
  • 调试的艺术:从崩溃到洞察的全面指南
  • 深入洞察:大模型服务之MaaS平台
  • 1024.5不是数位和--------题解
  • 加强门户网站建设的通知博客和网站的区别
  • 阿里云网站建站网站建设的公司这个
  • 基于AWS多区域部署的高可用性与灾难恢复架构设计
  • 海外注册域名的网站好石家庄专业网站营销
  • HTML CSS八股
  • 免费网页源代码网站个人微信营销
  • 【项目实战1 -瑞吉外卖|day23 】
  • QuickLook:文件预览
  • 使用QKeyEvent keyPress(QEvent::KeyPress, key模拟键盘发送事件,会导致主程序卡死
  • 512-Spring AI Alibaba 字段分类分级 Graph 示例
  • 网站开发培训中心wordpress怎么建页面
  • 朝阳做网站哪家公司好推广广告投放
  • 我是程序员吗?
  • 在线excel数据导入导出框架