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

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

相关推荐
我命由我123451 小时前
Photoshop - Photoshop 工具栏(58)锐化工具
学习·ui·职场和发展·求职招聘·职场发展·学习方法·photoshop
小雨下雨的雨2 小时前
Flutter 框架跨平台鸿蒙开发 —— Flex 控件之响应式弹性布局
flutter·ui·华为·harmonyos·鸿蒙系统
沐墨染3 小时前
敏感词智能检索前端组件设计:树形组织过滤与多维数据分析
前端·javascript·vue.js·ui·数据挖掘·数据分析
zhangzhangkeji3 小时前
UE5 C++(UObject 的实例化 19-3):类 UWorld,模板函数 NewObject<>(...),
ue5
zhangzhangkeji15 小时前
UE5 C++(14-1):UPROPERTY 宏、属性说明符和元数据说明符, visible,edit,Blueprint读写,Category 存储目录
ue5
Zhichao_9720 小时前
【UE5.3 C++】ARPG游戏 05-准备角色攻击的武器和动画
游戏·ue5
zhangzhangkeji1 天前
UE5 C++(15-3):UFUNCTION 的 meta 元数据, DisplayName ,同 UPROPERTY 的 meta
ue5
小雨下雨的雨1 天前
Flutter 框架跨平台鸿蒙开发 —— Center 控件之完美居中之道
flutter·ui·华为·harmonyos·鸿蒙
小小工匠1 天前
LLM - A2UI:Google 引领的生成式 UI 革命
ui·a2ui
小雨下雨的雨1 天前
Flutter 框架跨平台鸿蒙开发 —— Placeholder 控件之布局雏形美学
flutter·ui·华为·harmonyos·鸿蒙系统