RPG59.玩家拾取物品三:可拾取物品的提示UI

1。以WarriorWidgetBase作为父类,创建一个子类的userwidget

2.布局为

两个值都为120

3。然后我们需要想办法,在合适的位置,用bool来控制此控件的显示与隐藏。

情况为:当玩家触发与可拾取物体的重叠时,我们将广播一个bool值用来显示可拾取提示

打开PlayerUiComponent.h

复制代码
//控制显示拾取物品的提示
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnStoneInteractedDelegate, bool, bShouldDisplayInputKey);

//控制显示物体
	UPROPERTY(BlueprintCallable,BlueprintAssignable)
	FOnStoneInteractedDelegate OnStoneInteracted;

我们还需要获取player的uicomponent,打开WarriorPlayerGameplayAbility.h

复制代码
//获取玩家UI组件
	UFUNCTION(BlueprintPure, Category = "XMB|Ability")
	UPlayerUIComponent* GetPlayerUIComponentFromActorInfo();

UPlayerUIComponent* UWarriorPlayerGameplayAbility::GetPlayerUIComponentFromActorInfo()
{
	return GetPlayerCharacterFromActorInfo()->GetPlayerUIComponent();
}

然后打开PlayerGA_PickUpStones,处理广播事件,这样子我们就将bool广播出去了

复制代码
void UPlayerGA_PickUpStones::ActivateAbility(const FGameplayAbilitySpecHandle Handle,const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo,const FGameplayEventData* TriggerEventData)
{
	//显示可拾取提示
	GetPlayerUIComponentFromActorInfo()->OnStoneInteracted.Broadcast(true);
	
	Super::ActivateAbility(Handle, ActorInfo, ActivationInfo, TriggerEventData);
}

void UPlayerGA_PickUpStones::EndAbility(const FGameplayAbilitySpecHandle Handle,const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilityActivationInfo ActivationInfo,bool bReplicateEndAbility, bool bWasCancelled)
{
	GetPlayerUIComponentFromActorInfo()->OnStoneInteracted.Broadcast(false);
	
	Super::EndAbility(Handle, ActorInfo, ActivationInfo, bReplicateEndAbility, bWasCancelled);
}

4。接下来处理监听

启动项目,打开Overlay

我们需要获取当前用来拾取物品的键位

相关推荐
AC赳赳老秦8 小时前
DeepSeek 辅助科研项目申报:可行性报告与经费预算框架的智能化撰写指南
数据库·人工智能·科技·mongodb·ui·rabbitmq·deepseek
AI视觉网奇9 小时前
metahuman 购买安装记录
笔记·学习·ue5
速冻鱼Kiel9 小时前
虚幻状态树解析
ue5·游戏引擎·虚幻
Dontla12 小时前
Axure RP(Rapid Prototyper)原型图设计工具介绍
ui·axure·photoshop
晚霞的不甘12 小时前
Flutter for OpenHarmony从基础到专业:深度解析新版番茄钟的倒计时优化
android·flutter·ui·正则表达式·前端框架·鸿蒙
XPii14 小时前
Photoshop应用——将图片变为油画效果
ui·photoshop
灵感菇_15 小时前
Android 列表控件全面解析:ListView 与 RecyclerView
android·ui
晚霞的不甘15 小时前
Flutter for OpenHarmony 实现动态天气与空气质量仪表盘:从 UI 到动画的完整解析
前端·flutter·ui·前端框架·交互
暮志未晚Webgl15 小时前
UE5游戏打包
游戏·ue5
雨季66616 小时前
Flutter 三端应用实战:OpenHarmony “极简文本字符计数器”——量化表达的尺度
开发语言·flutter·ui·交互·dart