官方项目《内容示例》中Common UI部分笔记: 1.1 Activatable Widgets

本文主要面向UMG以及Common UI的初学者

文章目录

效果展示

概要

这个例子非常简单,定义了1+3个Common Activatable Widget

CommonUI_ActivatableWidgets 相当于一个容器包含了其它3个Common Activatable Widget ,CommonUI_ActivatableWidgets 里没有什么逻辑,窗口弹出/切换的逻辑在CommonUI_BaseLayer 里,CommonUI_BaseLayer 通过变量引用了另外两个Common Activatable Widget

Activate和Deactivate

Activate Widget都干了些什么?

cpp 复制代码
void UCommonActivatableWidget::ActivateWidget()
{
	if (!bIsActive)
	{
		InternalProcessActivation();
	}
}

void UCommonActivatableWidget::InternalProcessActivation()
{
	UE_LOG(LogCommonUI, Verbose, TEXT("[%s] -> Activated"), *GetName());

	bIsActive = true;
	NativeOnActivated();
}

void UCommonActivatableWidget::NativeOnActivated()
{
	if (ensureMsgf(bIsActive, TEXT("[%s] has called NativeOnActivated, but isn't actually activated! Never call this directly - call ActivateWidget()")))
	{
		if (bSetVisibilityOnActivated)
		{
			SetVisibility(ActivatedVisibility);
			UE_LOG(LogCommonUI, Verbose, TEXT("[%s] set visibility to [%s] on activation"), *GetName(), *StaticEnum<ESlateVisibility>()->GetDisplayValueAsText(ActivatedVisibility).ToString());
		}

		if (CommonUI::IsEnhancedInputSupportEnabled() && InputMapping)
		{
			if (const ULocalPlayer* LocalPlayer = GetOwningLocalPlayer())
			{
				if (UEnhancedInputLocalPlayerSubsystem* InputSystem = LocalPlayer->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>())
				{
					InputSystem->AddMappingContext(InputMapping, InputMappingPriority);
				}
			}
		}

		BP_OnActivated();
		OnActivated().Broadcast();
		BP_OnWidgetActivated.Broadcast();
	}
}
cpp 复制代码
	UPROPERTY(EditAnywhere, Category = Activation, meta = (InlineEditConditionToggle = "ActivatedVisibility"))
	bool bSetVisibilityOnActivated = false;

在每个Common Activatable Widget 可以通过Activated Visibility以及Dezctivated Visibility来定义该Common Activatable Widget 被激活/取消激活时的可见性行为

可见性绑定

cpp 复制代码
	/**
	 * Visibilities to use for when bound widgets in BindVisibilityToActivation are activated.
	 *
	 * @param	OnActivatedVisibility	- Visibility for when bound widgets are active
	 * @param	OnDeactivatedVisibility - Visibility for when bound widgets are not active, not used if this widget has activation / deactivation visibilities
	 * @param	bInAllActive			- True if we should switch to activated visibility only when all bound widgets are active
	 */

void UCommonActivatableWidget::SetBindVisibilities(ESlateVisibility OnActivatedVisibility, ESlateVisibility OnDeactivatedVisibility, bool bInAllActive)
{
	ActivatedBindVisibility = OnActivatedVisibility;
	DeactivatedBindVisibility = OnDeactivatedVisibility;
	bAllActive = bInAllActive;
}

	/**
	 * Bind our visibility to the activation of another widget, useful for making mouse collisions behave similiar to console navigation w.r.t activation
	 * Will immediately update visibility based on the bound widget activation & visibilites set by SetBindVisibilities.
	 *
	 * @param	ActivatableWidget		- The widget whose activation / deactivation will modify our visibility 
	 */

void UCommonActivatableWidget::BindVisibilityToActivation(UCommonActivatableWidget* ActivatableWidget)
{
	if (ActivatableWidget && !VisibilityBoundWidgets.Contains(ActivatableWidget))
	{
		VisibilityBoundWidgets.Add(ActivatableWidget);
		ActivatableWidget->OnActivated().AddUObject(this, &UCommonActivatableWidget::HandleVisibilityBoundWidgetActivations);
		ActivatableWidget->OnDeactivated().AddUObject(this, &UCommonActivatableWidget::HandleVisibilityBoundWidgetActivations);

		HandleVisibilityBoundWidgetActivations();
	}
}

UI动画

动画播放及用动画触发UI切换

设置Common Activatable Widget的默认焦点

覆盖BP_FetDesiredFocusTarget

相关推荐
电子云与长程纠缠1 小时前
UE5.3中通过编辑器工具创建大纲菜单文件夹
java·ue5·编辑器
DBBH11 小时前
UE5 第三人称学习之动画 control rig
ue5
UTwelve11 小时前
【UE5】一种老派的假反射做法,可以用于移动端,或对反射的速度、清晰度有需求的地方
ue5·虚幻引擎·着色器·虚幻4
UTwelve14 小时前
【UE5】可以实时绘制的体积渲染 【第三章 体积纹理绘制 - 3.绘制体积】
ue5
1204157137 肖哥19 小时前
UE5.4 PCG基础节点
ue5
DBBH2 天前
UE5 材质篇 1 如何偏移顶点
ue5·材质
孤客网络科技工作室2 天前
虚幻引擎5(UE5)学习教程
java·学习·ue5
暮志未晚Webgl2 天前
105. UE5 GAS RPG 搭建主菜单
ue5
异次元的归来2 天前
UE5相机系统初探(一)
ue5·游戏引擎·camera
幻狐boke4 天前
【mod分享】极品飞车9仿虚幻引擎模组,支持光追,高清纹理材质,体验一会虚幻引擎风格的极品9
游戏·游戏引擎·虚幻