public virtual void Draw(Vector2 origin)
    {
        this.origin = origin;
        var newRect = GUILayout.Window(nodeData.id, GetWindowRectInternal(), (id) =>
        {
            DrawContents();
            HandleEvents();
            GUI.DragWindow();
        }, new GUIContent(), GUIStyle);

        if (Event.current.type == EventType.Repaint)
        {
            size = newRect.size;
        }

        foreach (var nodeConnector in nodeConnectors.Values)
        {
            nodeConnector.Draw();
        }

        if (dragging)
        {
            nodeData.graphPosition = NodeEditorUtilities.RoundVectorToIntegerValues(newRect.position - origin);
        }

        if (postDraw != null)
        {
            var temp = postDraw;
            postDraw = null;
            temp.Invoke();
        }
    }
Exemple #2
0
    protected override void OnHandleEvents()
    {
        if (CurrentTarget == null || Settings == null)
        {
            return;
        }

        if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
        {
            var genericMenu   = new GenericMenu();
            var mousePosition = Event.current.mousePosition;
            foreach (var connectableType in GetConnectableTypes())
            {
                genericMenu.AddItem(new GUIContent("Create/" + connectableType.Name), false, () =>
                {
                    var nodePosition = NodeEditorUtilities.RoundVectorToIntegerValues(ConvertScreenCoordsToZoomCoords(mousePosition));
                    GetNodeGraphData(CurrentTarget).CreateNode(connectableType, nodePosition, connectableType.Name);
                });
            }

            genericMenu.ShowAsContext();
            Event.current.Use();
        }
        else if (Event.current.type == EventType.MouseMove ||
                 Event.current.type == EventType.MouseDrag)
        {
            Repaint();
        }
        else if (Event.current.type == EventType.ValidateCommand)
        {
            if (Event.current.commandName == "UndoRedoPerformed")
            {
                AssetDatabase.SaveAssets();
            }

            Repaint();
        }

        if (PostDraw != null)
        {
            var temp = PostDraw;
            PostDraw = null;
            temp.Invoke();
        }
    }