UMG拖放控制

来源:互联网 发布:centos jdk1.7 安装 编辑:程序博客网 时间:2024/05/17 02:52

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 ClassDrag Drop Operation Class Class The object classyou want to construct

Tag

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

Payload

ObjectReferenceThe 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

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

Pivot

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

Offset

Vector2D StructureA 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 ReferenceDrag 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


原创粉丝点击