浏览代码

add event dispatcher that convert Unity Events (DragUpdate, DragRelease, DragExit) to PointerEvents (Mac side)

/zxw-support_editor_dragdrop
Xingwei Zhu 3 年前
当前提交
588a4fd8
共有 11 个文件被更改,包括 124 次插入1 次删除
  1. 10
      com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs
  2. 27
      com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs
  3. 22
      com.unity.uiwidgets/Runtime/gestures/converter.cs
  4. 2
      com.unity.uiwidgets/Runtime/ui/pointer.cs
  5. 2
      com.unity.uiwidgets/Runtime/widgets/binding.cs
  6. 2
      engine/src/lib/ui/window/pointer_data.h
  7. 8
      engine/src/lib/ui/window/pointer_data_packet_converter.cc
  8. 4
      engine/src/shell/platform/embedder/embedder.cc
  9. 2
      engine/src/shell/platform/embedder/embedder.h
  10. 4
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.h
  11. 42
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm

10
com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs


var pos = _getPointerPosition(position: evt.mousePosition);
_wrapper.OnMouseScroll(delta: delta, pos: pos);
}
//only available in EditorWindow
else if (evt.type == EventType.DragUpdated) {
var pos = _getPointerPosition(position: evt.mousePosition);
_wrapper.OnDragUpdateInEditor(pos: pos);
}
//only available in EditorWindow
else if (evt.type == EventType.DragPerform || evt.type == EventType.DragExited) {
var pos = _getPointerPosition(position: evt.mousePosition);
_wrapper.OnDragReleaseInEditor(pos: pos);
}
else if (evt.isKey) {
_wrapper.OnKeyDown(e: evt);
Event.current.Use();

27
com.unity.uiwidgets/Runtime/engine/UIWidgetsPanelWrapper.cs


public void OnPointerLeave() {
UIWidgetsPanel_onMouseLeave(ptr: _ptr);
}
public void OnDragUpdateInEditor(Vector2? pos) {
if (pos == null) {
return;
}
UIWidgetsPanel_onDragUpdateInEditor(ptr: _ptr, x: pos.Value.x, y: pos.Value.y);
}
public void OnDragReleaseInEditor(Vector2? pos) {
if (pos == null) {
return;
}
UIWidgetsPanel_onDragReleaseInEditor(ptr: _ptr, x: pos.Value.x, y: pos.Value.y);
}
public void OnKeyDown(Event e) {
int modifier = 0;

[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onScroll(IntPtr ptr, float x, float y, float px, float py);
#if UNITY_EDITOR
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onDragUpdateInEditor(IntPtr ptr, float x ,float y);
[DllImport(dllName: NativeBindings.dllName)]
static extern void UIWidgetsPanel_onDragReleaseInEditor(IntPtr ptr, float x ,float y);
#else
static void UIWidgetsPanel_onDragUpdateInEditor(IntPtr ptr, float x, float y) { throw new NotImplementedException(); }
static void UIWidgetsPanel_onDragReleaseInEditor(IntPtr ptr, float x ,float y) { throw new NotImplementedException(); }
#endif
}
#endregion

22
com.unity.uiwidgets/Runtime/gestures/converter.cs


case ui.PointerSignalKind.none:
D.assert(false); // This branch should already have 'none' filtered out.
break;
case ui.PointerSignalKind.editorDragMove: {
Debug.Log($"c++ side editor drag move {position}");
yield return new PointerDragFromEditorHoverEvent(
timeStamp: timeStamp,
pointer: datum.pointerIdentifier,
kind: kind,
device: datum.device,
position: position
);
break;
}
case ui.PointerSignalKind.editorDragRelease: {
Debug.Log($"c++ side editor drag release {position}");
yield return new PointerDragFromEditorReleaseEvent(
timeStamp: timeStamp,
pointer: datum.pointerIdentifier,
kind: kind,
device: datum.device,
position: position
);
break;
}
case ui.PointerSignalKind.unknown:
// Ignore unknown signals.
break;

2
com.unity.uiwidgets/Runtime/ui/pointer.cs


public enum PointerSignalKind {
none,
scroll,
editorDragMove,
editorDragRelease,
unknown,
}

2
com.unity.uiwidgets/Runtime/widgets/binding.cs


_renderViewElement = null;
}
internal void scheduleAttachRootWidget(Widget rootWidget) {
public void scheduleAttachRootWidget(Widget rootWidget) {
Timer.run(() => {
attachRootWidget(rootWidget);
return null;

2
engine/src/lib/ui/window/pointer_data.h


enum class SignalKind : int64_t {
kNone,
kScroll,
kEditorDragUpdate,
kEditorDragRelease
};
int64_t time_stamp;

8
engine/src/lib/ui/window/pointer_data_packet_converter.cc


converted_pointers.push_back(pointer_data);
break;
}
case PointerData::SignalKind::kEditorDragUpdate: {
converted_pointers.push_back(pointer_data);
break;
}
case PointerData::SignalKind::kEditorDragRelease: {
converted_pointers.push_back(pointer_data);
break;
}
default: {
// Ignores unknown signal kind.
break;

4
engine/src/shell/platform/embedder/embedder.cc


return PointerData::SignalKind::kNone;
case kUIWidgetsPointerSignalKindScroll:
return PointerData::SignalKind::kScroll;
case kUIWidgetsPointerSignalKindEditorDragUpdate:
return PointerData::SignalKind::kEditorDragUpdate;
case kUIWidgetsPointerSignalKindEditorDragRelease:
return PointerData::SignalKind::kEditorDragRelease;
}
return PointerData::SignalKind::kNone;
}

2
engine/src/shell/platform/embedder/embedder.h


typedef enum {
kUIWidgetsPointerSignalKindNone,
kUIWidgetsPointerSignalKindScroll,
kUIWidgetsPointerSignalKindEditorDragUpdate,
kUIWidgetsPointerSignalKindEditorDragRelease
} UIWidgetsPointerSignalKind;
typedef struct {

4
engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.h


void OnMouseLeave();
void OnDragUpdateInEditor(float x, float y);
void OnDragReleaseInEditor(float x, float y);
bool NeedUpdateByPlayerLoop();
bool NeedUpdateByEditorLoop();

42
engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm


}
}
void UIWidgetsPanel::OnDragUpdateInEditor(float x, float y)
{
if (process_events_) {
UIWidgetsPointerEvent event = {};
event.x = x;
event.y = y;
SetEventPhaseFromCursorButtonState(&event);
event.signal_kind = UIWidgetsPointerSignalKind::kUIWidgetsPointerSignalKindEditorDragUpdate;
SendPointerEventWithData(event);
}
}
void UIWidgetsPanel::OnDragReleaseInEditor(float x, float y)
{
if (process_events_) {
UIWidgetsPointerEvent event = {};
event.x = x;
event.y = y;
SetEventPhaseFromCursorButtonState(&event);
event.signal_kind = UIWidgetsPointerSignalKind::kUIWidgetsPointerSignalKindEditorDragRelease;
SendPointerEventWithData(event);
}
}
static uint64_t ConvertToUIWidgetsButton(int button) {
switch (button) {
case -1:

UIWIDGETS_API(void)
UIWidgetsPanel_onScroll(UIWidgetsPanel* panel, float x, float y, float px, float py) {
panel->OnScroll(x, y, px, py);
}
UIWIDGETS_API(void)
UIWidgetsPanel_onDragUpdateInEditor(UIWidgetsPanel* panel, float x, float y) {
if (!panel->NeedUpdateByEditorLoop()) {
return;
}
panel->OnDragUpdateInEditor(x, y);
}
UIWIDGETS_API(void)
UIWidgetsPanel_onDragReleaseInEditor(UIWidgetsPanel* panel, float x, float y) {
if (!panel->NeedUpdateByEditorLoop()) {
return;
}
panel->OnDragReleaseInEditor(x, y);
}
} // namespace uiwidgets
正在加载...
取消
保存