private void DrawInspector()
        {
            var inspectorPos = new Rect(position.width - InspectorWidth, 16, InspectorWidth, position.height - 32);

            var bg = NodePreferences.Instance.InsepctorTexture2D;

            GUI.DrawTexture(inspectorPos, bg);

            GUILayout.BeginArea(inspectorPos);
            if (LoadedGraph != null)
            {
                var style   = NodeStyles.Instance.InspectorTitleLabel;
                var content = new GUIContent(LoadedGraph.name);
                var size    = style.CalcSize(content);

                EditorGUILayout.LabelField(content, style, GUILayout.Height(size.y));

                if (SelectedNodes != null && SelectedNodes.Count > 0)
                {
                    EditorGUILayout.LabelField("Selected Nodes:");

                    for (var i = 0; i < SelectedNodes.Count; i++)
                    {
                        var nodeData = LoadedGraph.FindNodeData(SelectedNodes[i]);
                        if (nodeData != null)
                        {
                            EditorGUILayout.LabelField(nodeData.NodeName);
                        }
                    }
                }
            }

            GUILayout.EndArea();
        }
Exemple #2
0
        private void ShowNodeContextMenu(string hoverNode)
        {
            var menu = new GenericMenu();
            var node = LoadedGraph.FindNodeData(hoverNode);

            foreach (var nodeContextMethod in NodeCache.NodeContextMethods)
            {
                var methodInfo = nodeContextMethod.Value;
                if (methodInfo != null)
                {
                    menu.AddItem(new GUIContent(nodeContextMethod.Key.MethodName), false,
                                 () => { methodInfo.Invoke(this, new object[] { node }); });
                }
            }

            menu.ShowAsContext();
        }
        private void ControlActions()
        {
            var evt = Event.current;

            switch (evt.type)
            {
            case EventType.MouseDown:
                if (evt.button == 0)
                {
                    SelectActions();
                }
                else if (evt.button == 1)
                {
                    var node = MouseOverNode();
                    if (node != null)
                    {
                        ShowNodeContextMenu(node);
                    }
                    else
                    {
                        ShowGraphContextMenu();
                    }
                }

                break;

            case EventType.MouseUp:
                if (_hoverPort != null)
                {
                    var targetPort = MouseOverPort();
                    if (targetPort != null)
                    {
                        var sourcePortData = LoadedGraph.Ports[_hoverPort];
                        var targetPortData = LoadedGraph.Ports[targetPort];

                        if (sourcePortData.VerifyConnection(targetPortData))
                        {
                            if (_hoveringConnection != null)
                            {
                                var inPort = sourcePortData.Direction == PortDirection.In
                                        ? sourcePortData.PortId
                                        : targetPortData.PortId;
                                var outPort = sourcePortData.Direction == PortDirection.Out
                                        ? sourcePortData.PortId
                                        : targetPortData.PortId;

                                _hoveringConnection.Connection.InPortId  = inPort;
                                _hoveringConnection.Connection.OutPortId = outPort;
                                _hoveringConnection.Hovering             = false;
                            }
                            else
                            {
                                var connectionType = LoadedGraph.DefaultConnectionType;
                                if (sourcePortData.OverrideConnectionType != null)
                                {
                                    connectionType = sourcePortData.OverrideConnectionType;
                                }

                                CreateNewConnection(connectionType, sourcePortData, targetPortData);
                            }
                        }
                    }
                    else
                    {
                        if (_hoveringConnection != null)
                        {
                            LoadedGraph.RemoveConnectionById(_hoveringConnection.ConnectionId);
                            AssetDatabase.SaveAssets();
                        }
                    }
                }

                _hoveringConnection = null;
                _hoverNode          = null;
                _hoverPort          = null;
                Repaint();
                break;

            case EventType.MouseDrag:
                if (evt.alt)
                {
                    PanBackground(evt);
                }
                else
                {
                    if (_hoverNode != null)
                    {
                        if (SelectedNodes != null && SelectedNodes.Count > 0)
                        {
                            for (var i = 0; i < SelectedNodes.Count; i++)
                            {
                                var selection  = SelectedNodes[i];
                                var selectNode = LoadedGraph.FindNodeData(selection);

                                var headerPos = selectNode.HeaderRect;
                                var bodyPos   = selectNode.BodyRect;

                                headerPos.position += evt.delta * _zoom.x;
                                bodyPos.position   += evt.delta * _zoom.x;

                                selectNode.HeaderRect = headerPos;
                                selectNode.BodyRect   = bodyPos;
                            }
                        }

                        evt.Use();
                    }
                }

                Repaint();

                break;

            case EventType.ScrollWheel:
                Zoom(evt.delta.y);
                Repaint();
                break;
            }
        }