UMG拖放控制

UMG 中图标拖动需要三步,可以用来实现物品栏,快捷键的设置。

1.在需要拖动的窗口重载一下函数On Mouse Button Down:在此时开启拖放检测,拖放检测会在鼠标按下过程中一直持续。


图一:On Mouse Button Down

2. 在允许拖动的窗口重载以下函数On Drag Detected:当拖动事件被侦测到,创建Drag Drop Operation, 如图二所示:

图二:On Drag Detected

DragDrop Operation 函数如下表所示:

图三:Creates a new drag dropoperation

其中各参数如下表所示:

表一:Creates drag drop operation 各参数

Inputs

In

Exec

Class

DragDrop Operation Class
Drag Drop Operation Class Class The object classyou want to construct

Tag

String
A simple string tag you can optionally use toprovide extra metadata about the operation.

Payload

ObjectReference
The payload of the drag operation. This can beany UObject that you want to pass along as dragged data. If you were buildingan inventory screen this would be the UObject representing the item being movedto another slot.

Default Drag Visual

WidgetReference
The Drag Visual is the widget to display whendragging the item. Normally people create a new widget to represent thetemporary drag.

Pivot

EDragPivotEnum
Controls where the drag widget visual willappear when dragged relative to the pointer performing the drag operation.

Offset

Vector2D Structure
A percentage offset (-1..+1) from the Pivotlocation, the percentage is of the desired size of the dragged visual.
Outputs

Out

Exec

Return Value

DragDrop Operation Reference
Drag Drop Operation Reference Return Value Theconstructed object




3. 在允许Drop 操作的窗口重载OnDrop函数,实现放下操作:


图四:On Drop

其中ED_OnSetAndDelete 为Event Dispatcher, 其目的是为了将该拖放操作传递给顶层模块,在顶层模型进行进一步的操作。

Event OnSetAndDelete 事件从Operation 中解析出传递过来的数据,从DestinationUserWidget 中得到拖拽目的地的控件。

(注意要把允许Drag Drop 操作的窗口的Root 设置其Visibility参数为Visible,(默认为SelfHitTestInvisible).这样才能接收拖放事件。)

 

[Reference]

1. https://docs.unrealengine.com/latest/INT/BlueprintAPI/UserInterface/CreateDrag_DropOperation/index.html

2.https://github.com/BasicCoder/Intership_UE4


  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值