UMG 中图标拖动需要三步,可以用来实现物品栏,快捷键的设置。
1.在需要拖动的窗口重载一下函数On Mouse Button Down:在此时开启拖放检测,拖放检测会在鼠标按下过程中一直持续。
图一:On Mouse Button Down
2. 在允许拖动的窗口重载以下函数On Drag Detected:当拖动事件被侦测到,创建Drag Drop Operation, 如图二所示:
图二:On Drag Detected
图三:Creates a new drag dropoperation
其中各参数如下表所示:
表一:Creates drag drop operation 各参数
| 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. |
| Out
Exec
| |
|---|---|
| Return Value DragDrop Operation Reference | Drag Drop Operation Reference Return Value Theconstructed object |
图四:On Drop
其中ED_OnSetAndDelete 为Event Dispatcher, 其目的是为了将该拖放操作传递给顶层模块,在顶层模型进行进一步的操作。
Event OnSetAndDelete 事件从Operation 中解析出传递过来的数据,从DestinationUserWidget 中得到拖拽目的地的控件。
(注意要把允许Drag Drop 操作的窗口的Root 设置其Visibility参数为Visible,(默认为SelfHitTestInvisible).这样才能接收拖放事件。)
[Reference]
2.https://github.com/BasicCoder/Intership_UE4
UE4 UMG 图标拖动实现
本文介绍如何在Unreal Engine 4 (UE4) 中使用UMG(User Interface in the Game)实现图标拖动功能,具体步骤包括重载OnMouseButtonDown、OnDragDetected及OnDrop函数,并详细解释了各函数的作用及参数。
5032

被折叠的 条评论
为什么被折叠?



