public override Node Create(Vector2 pos) { UnityTextureInput node = CreateInstance <UnityTextureInput> (); node.rect = new Rect(pos.x, pos.y, 150, 150); node.name = "UnityTextureInput"; node.CreateOutput("Texture", "TextureParam", NodeSide.Right, 50); return(node); }
[EventHandlerAttribute(EventType.DragPerform, 90)] // Priority over hundred to make it call after the GUI private static void HandleDragAndDrop(NodeEditorInputInfo inputInfo) { if (inputInfo.inputEvent.type == EventType.DragUpdated || (inputInfo.inputEvent.type == EventType.DragPerform)) { //Debug.LogError("handle drag " + inputInfo.inputEvent.type); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (inputInfo.inputEvent.type == EventType.DragPerform && DragAndDrop.objectReferences.Length > 0 && (DragAndDrop.objectReferences[0] is Texture2D)) { Debug.Log(" drag texture " + DragAndDrop.objectReferences[0]); UnityTextureInput node = (UnityTextureInput) Node.Create("UnityTextureInput", NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos)); node.m_Input = DragAndDrop.objectReferences[0] as Texture2D; inputInfo.inputEvent.Use(); } else if (inputInfo.inputEvent.type == EventType.DragPerform && DragAndDrop.GetGenericData("GenericDragColumnDragging") != null) { DragAndDrop.AcceptDrag(); //Debug.Log("dragged generic data "+ DragAndDrop.GetGenericData("GenericDragColumnDragging")); List <UnityEditor.IMGUI.Controls.TreeViewItem> _data = DragAndDrop.GetGenericData("GenericDragColumnDragging") as List <UnityEditor.IMGUI.Controls.TreeViewItem>; var draggedElements = new List <TreeElement>(); foreach (var x in _data) { draggedElements.Add(((TreeViewItem <MyTreeElement>)x).data); } var srcItem = draggedElements[0] as MyTreeElement; if (srcItem.m_Canvas) { SubTreeNode node = (SubTreeNode) Node.Create("SubTreeNode", NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos)); node.SubCanvas = srcItem.m_Canvas; string assetPath = AssetDatabase.GetAssetPath(node.SubCanvas); // Debug.Log("drag and drop asset canvas path >" + assetPath + "<"); if (assetPath.Length > 0) { node.m_CanvasGuid = AssetDatabase.AssetPathToGUID(assetPath); Debug.LogError(" set canvasGuid from asset >" + node.m_CanvasGuid + "<"); string fname = Path.GetFileName(assetPath); fname = Path.ChangeExtension(fname, ""); node.name = "Sub:" + fname; } node.OnLoadCanvas(); } else { Node node = Node.Create(srcItem.m_NodeID, NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos)); } inputInfo.inputEvent.Use(); } else if (inputInfo.inputEvent.type == EventType.DragPerform && DragAndDrop.objectReferences.Length > 0 && (DragAndDrop.objectReferences[0] is NodeCanvas)) { DragAndDrop.AcceptDrag(); // Debug.Log(" drag and drop " + DragAndDrop.objectReferences[0] + " co ord " + Event.current.mousePosition); SubTreeNode node = (SubTreeNode) Node.Create("SubTreeNode", NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos)); node.SubCanvas = (NodeCanvas)DragAndDrop.objectReferences[0]; string assetPath = AssetDatabase.GetAssetPath(node.SubCanvas); // Debug.Log("drag and drop asset canvas path >" + assetPath + "<"); if (assetPath.Length > 0) { node.m_CanvasGuid = AssetDatabase.AssetPathToGUID(assetPath); Debug.LogError(" set canvasGuid from asset >" + node.m_CanvasGuid + "<"); string fname = Path.GetFileName(assetPath); fname = Path.ChangeExtension(fname, ""); node.name = "Sub:" + fname; } inputInfo.inputEvent.Use(); node.OnLoadCanvas(); } } }