Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit e3b5991

Browse files
authored
Merge pull request #268 from Unity-Technologies/zxw/support_editor_dragdrop
Add support to Editor Drag&Drop
2 parents bfcb537 + 9d8a708 commit e3b5991

31 files changed

+952
-13
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System.Collections.Generic;
2+
using uiwidgets;
3+
using Unity.UIWidgets.Editor;
4+
using Unity.UIWidgets.gestures;
5+
using Unity.UIWidgets.widgets;
6+
using UnityEditor;
7+
using UnityEngine;
8+
9+
namespace UIWidgetsEditorWindowSample
10+
{
11+
public class UnityObjectDraggingWindow : UIWidgetsEditorPanel
12+
{
13+
[MenuItem("UIWidgets/EditorSample/UnityObjectDragging")]
14+
public static void CountDemo()
15+
{
16+
CreateWindow<UnityObjectDraggingWindow>();
17+
}
18+
19+
protected override void onEnable()
20+
{
21+
AddFont("Material Icons", new List<string> {"MaterialIcons-Regular.ttf"}, new List<int> {0});
22+
AddFont("CupertinoIcons", new List<string> {"CupertinoIcons.ttf"}, new List<int> {0});
23+
AddFont("GalleryIcons", new List<string> {"gallery/GalleryIcons.ttf"}, new List<int> {0});
24+
}
25+
26+
protected override void main()
27+
{
28+
editor_ui_.runEditorApp(new MyApp());
29+
}
30+
31+
public class MyApp : StatelessWidget
32+
{
33+
public override Widget build(BuildContext context)
34+
{
35+
return
36+
new Container(color: Colors.green, child:
37+
new Center(child:
38+
new UnityObjectDetector(
39+
child: new Container(color: Colors.blue, width: 200f, height: 200f,
40+
child: new Center(child: new Text("Drag UnityObject or file to me"))),
41+
onEnter: (details) =>
42+
{
43+
Debug.Log("enter");
44+
},
45+
onHover: (details =>
46+
{
47+
Debug.Log("position = " + details.position);
48+
}),
49+
onExit: () =>
50+
{
51+
Debug.Log("on exit");
52+
},
53+
onRelease: (details) =>
54+
{
55+
Debug.Log("on release");
56+
}
57+
)
58+
)
59+
);
60+
}
61+
}
62+
}
63+
}

Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/UnityObjectDragging.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ void Input_OnGUIEvent(Event evt) {
158158
var pos = _getPointerPosition(position: evt.mousePosition);
159159
_wrapper.OnMouseScroll(delta: delta, pos: pos);
160160
}
161+
else if (evt.type == EventType.DragUpdated) {
162+
var pos = _getPointerPosition(position: evt.mousePosition);
163+
_wrapper.OnDragUpdateInEditor(pos: pos);
164+
}
165+
else if (evt.type == EventType.DragPerform || evt.type == EventType.DragExited) {
166+
var pos = _getPointerPosition(position: evt.mousePosition);
167+
_wrapper.OnDragReleaseInEditor(pos: pos);
168+
}
161169
else if (evt.isKey) {
162170
_wrapper.OnKeyDown(e: evt);
163171
Event.current.Use();

com.unity.uiwidgets/Editor/gesture.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Unity.UIWidgets.gestures;
4+
using Unity.UIWidgets.ui;
5+
6+
namespace Unity.UIWidgets.widgets {
7+
public class UiWidgetsEditorBinding : UiWidgetsBinding {
8+
public new static UiWidgetsEditorBinding instance {
9+
get { return (UiWidgetsEditorBinding) UiWidgetsBinding.instance; }
10+
set { UiWidgetsBinding.instance = value; }
11+
}
12+
13+
public static UiWidgetsEditorBinding ensureInitializedForEditor() {
14+
if (UiWidgetsEditorBinding.instance == null) {
15+
return new UiWidgetsEditorBinding();
16+
}
17+
18+
return UiWidgetsEditorBinding.instance;
19+
}
20+
21+
public EditorMouseTracker editorMouseTracker {
22+
get { return _editorMouseTracker; }
23+
}
24+
25+
EditorMouseTracker _editorMouseTracker;
26+
27+
private void initEditorMouseTracker(EditorMouseTracker tracker = null) {
28+
_editorMouseTracker?.dispose();
29+
_editorMouseTracker = tracker ?? new EditorMouseTracker(pointerRouter, hitTestMouseTrackers);
30+
}
31+
32+
public EditorMouseTrackerAnnotation hitTestMouseTrackers(Offset position) {
33+
List<EditorMouseTrackerAnnotation> annotations =
34+
new List<EditorMouseTrackerAnnotation>(renderView.layer.findAllAnnotations<EditorMouseTrackerAnnotation>(
35+
position * renderView.configuration.devicePixelRatio
36+
).annotations);
37+
38+
if (annotations is null || annotations.Count == 0) {
39+
return null;
40+
}
41+
42+
return annotations[0];
43+
}
44+
45+
protected override void initInstances() {
46+
base.initInstances();
47+
48+
addPersistentFrameCallback(_handlePersistentFrameCallbackForEditor);
49+
initEditorMouseTracker();
50+
}
51+
52+
private void _handlePersistentFrameCallbackForEditor(TimeSpan timeStamp) {
53+
_editorMouseTracker.schedulePostFrameCheck();
54+
}
55+
}
56+
57+
public static class editor_ui_ {
58+
public static void runEditorApp(Widget app) {
59+
var instance = UiWidgetsEditorBinding.ensureInitializedForEditor();
60+
instance.scheduleAttachRootWidget(app);
61+
instance.scheduleWarmUpFrame();
62+
}
63+
}
64+
}

com.unity.uiwidgets/Editor/gesture/binding.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)