跳至主要內容
Umg.UI焦点问题

UI焦点问题

导言

最近在做道具轮盘,大致流程是按下某个按键,弹出一个轮盘,使用鼠标或者手柄来选择某个插槽。 本篇记录一下实现中的一些坑。

实现原理


FVector2D URadialWheelWidget::GetWheelCenterPosition()
{
	if (!WheelOverlay)
	{
		return FVector2D::ZeroVector;
	}

	// 获取 Overlay 的几何信息
	const FGeometry& Geometry = WheelOverlay->GetCachedGeometry();

	// 本地中心点
	const FVector2D LocalCenter = Geometry.GetLocalSize() * 0.5f;

	// 转换到绝对屏幕坐标
	FVector2D PixelPosition;
	FVector2D ViewportPosition;
	USlateBlueprintLibrary::LocalToViewport(this, Geometry, LocalCenter, PixelPosition, ViewportPosition);

	// 加上DPI缩放
	return ViewportPosition * UWidgetLayoutLibrary::GetViewportScale(this);
}
void URadialWheelWidget::CalcAngleAndDistanceFromDir(const FVector2D& Dir, float& OutAngle, double& OutDistance) const
{
	OutDistance = Dir.Size();

	if (!Dir.IsNearlyZero())
	{
	    // Y 翻转
		OutAngle = FMath::RadiansToDegrees(FMath::Atan2(Dir.Y, Dir.X)) + 90.f;
		OutAngle = FRotator::ClampAxis(OutAngle);
	}
	else
	{
		OutDistance = 0.0;
		OutAngle = 0.f;
	}
}
FVector2D URadialWheelWidget::GetMousePosition()
{
    float Angle = 0.f;
	double Distance = 0.0;

	//1. 获取鼠标在屏幕中的绝对位置(考虑DPI缩放)
	const FVector2D MousePos = UWidgetLayoutLibrary::GetMousePositionOnViewport(this) *
							UWidgetLayoutLibrary::GetViewportScale(this);
    //2.获取轮盘中心坐标
	const FVector2D Center = GetWheelCenterPosition();
    //3.计算偏移向量
	const FVector2D Dir = MousePos - Center;
	
	//4.计算角度和距离
	CalcAngleAndDistanceFromDir(Dir, Angle, Distance);
}
	

Mr.Si大约 1 分钟unreal
Umg.ListView

导读

ListView & TileView

UTileView : public UListView

Mr.Si大约 5 分钟unreal
P0.插件开发

闲聊

新建插件开始

等待IED编译后点击窗口-就能看到你创建的插件了


Mr.Si大约 8 分钟unreal
LY5.Lyra-装备系统

概念

各模块职责分析

类图

ULyraEquipmentDefinition(装备定义模块)

核心类: • ULyraEquipmentDefinitionFLyraEquipmentActorToSpawn

职责: • 定义装备的静态属性(如生成的Actor类型、附加点信息) • 配置装备授予的能力集(AbilitySets)


Mr.Si大约 2 分钟unreal
NT-2.4|网络优化|结构体

本章概要

以方向为例,优化方向结构体的网络传输

问题

UENUM(BlueprintType)
enum class EDirectionType : uint8
{
	Forward UMETA(DisplayName = "Forward"),
	Backward UMETA(DisplayName = "Backward"),
	Left UMETA(DisplayName = "Left"),
	Right UMETA(DisplayName = "Right"),
	Invalid UMETA(DisplayName = "Invalid")
};

Mr.Si大约 2 分钟unreal