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
我們需要獲取當前用來拾取物品的鍵位