1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-06 23:34:54 +08:00

Added Drop event to Node Graph (#157)

Override NodeGraphEditor.OnDropObjects to deal with items dropped into the graph through DragAndDrop
This commit is contained in:
William Henry 2019-06-28 18:04:39 -04:00 committed by Thor Brigsted
parent 8d64843d42
commit 9b239c3564
2 changed files with 13 additions and 0 deletions

View File

@ -52,6 +52,14 @@ namespace XNodeEditor {
wantsMouseMove = true;
Event e = Event.current;
switch (e.type) {
case EventType.DragUpdated:
case EventType.DragPerform:
DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
if (e.type == EventType.DragPerform) {
DragAndDrop.AcceptDrag();
graphEditor.OnDropObjects(DragAndDrop.objectReferences);
}
break;
case EventType.MouseMove:
//Keyboard commands will not get correct mouse position from Event
lastMousePosition = e.mousePosition;

View File

@ -70,6 +70,11 @@ namespace XNodeEditor {
return NodeEditorPreferences.GetTypeColor(type);
}
/// <summary> Deal with objects dropped into the graph through DragAndDrop </summary>
public virtual void OnDropObjects(UnityEngine.Object[] objects) {
Debug.Log("No OnDropItems override defined for " + GetType());
}
/// <summary> Create a node and save it in the graph asset </summary>
public virtual void CreateNode(Type type, Vector2 position) {
XNode.Node node = target.AddNode(type);