public NodeGraphView(GraphTypeMetadata graphTypeMetadata)
        {
            styleSheets.Add(Resources.Load <StyleSheet>(ResourceAssetPaths.NodeGraphView_StyleSheet));

            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
            CustomContentDragger customContentDragger = new CustomContentDragger();

            this.AddManipulator(customContentDragger);
            SecondarySelectionDragger secondarySelectionDragger = new SecondarySelectionDragger();

            this.AddManipulator(secondarySelectionDragger); // Order here matters because the SecondarySelectionDragger allows the event to propagate
            this.AddManipulator(new SelectionDragger());
            this.AddManipulator(new RectangleSelector());

            // Grid lines
            m_gridBackground = new GridBackground();
            Insert(0, m_gridBackground);
            m_gridBackground.StretchToParentSize();

            // Minimap
            m_miniMap = new MiniMap {
                anchored = true
            };
            m_miniMap.SetPosition(new Rect(0, 0, 200, 200));
            this.RegisterCallback <GeometryChangedEvent>((GeometryChangedEvent evt) => { m_miniMap.SetPosition(new Rect(evt.newRect.xMax - 210, evt.newRect.yMax - 210, 200, 200)); });
            Add(m_miniMap);

            GraphTypeMetadata    = graphTypeMetadata;
            m_nodeCreationWindow = ScriptableObject.CreateInstance <NodeCreationWindow>();
            m_nodeCreationWindow.Setup(this, GraphTypeMetadata);

            nodeCreationRequest = context =>
            {
                SearchWindow.Open(new SearchWindowContext(context.screenMousePosition, 0, 0), m_nodeCreationWindow);
            };
            graphViewChanged += OnGraphViewChanged;

            m_edgeConectorListener  = new EdgeConnectorListener(this);
            serializeGraphElements += CopyAndSerializeGraphElements;
            unserializeAndPaste    += UnserializeAndPasteGraphElements;
            canPasteSerializedData += CanUnserializeAndPaste;

            RegisterCallback <MouseMoveEvent>(x => { m_mousePosition = x.localMousePosition; });
            RegisterCallback <MouseUpEvent>(x => { OnMouseClick?.Invoke(); });
            Undo.undoRedoPerformed += () => { SetNodeCollection(NodeGraph); };

            m_graphAxesController = new GraphAxesController(this, customContentDragger, secondarySelectionDragger);
            Add(m_graphAxesController);
            m_graphAxesController.PlaceBehind(contentViewContainer);
            m_graphAxesController.SetEnable(true);
        }
예제 #2
0
    public GraphAxesController(NodeGraphView nodeGraphView, CustomContentDragger contentDragger, SecondarySelectionDragger secondarySelectionDragger)
    {
        this.name                   = "graph-axes-controller";
        m_nodeGraphView             = nodeGraphView;
        m_customContentDragger      = contentDragger;
        m_secondarySelectionDragger = secondarySelectionDragger;

        m_xAxis = new GraphAxis();
        m_yAxis = new GraphAxis();

        VisualElement graphViewContent = m_nodeGraphView.Q <VisualElement>("contentViewContainer");

        Add(m_xAxis);
        Add(m_yAxis);

        RefreshPositions();
        m_nodeGraphView.RegisterCallback <GeometryChangedEvent>(RefreshSizes);
        m_nodeGraphView.viewTransformChanged   += RefreshPositions;
        m_customContentDragger.PositionChanged += RefreshPositions;
        m_secondarySelectionDragger.OnDragging += RefreshPositions; // TODO: This is a hack to get the axes to update when moving nodes around. But it still doesn't work perfectly.
    }