Example #1
0
        /// <summary>
        /// Draws the Node Canvas on the screen in the rect specified by editorState without one-time wrappers like GUISkin and OverlayGUI. Made for nested Canvases (WIP)
        /// </summary>
        private static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
        {
            if (!editorState.drawing)
            {
                return;
            }

            BeginEditingCanvas(nodeCanvas, editorState);
            if (curNodeCanvas == null || curEditorState == null || !curEditorState.drawing)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {             // Draw Background when Repainting
                // Offset from origin in tile units
                Vector2 tileOffset = new Vector2(-(curEditorState.zoomPos.x * curEditorState.zoom + curEditorState.panOffset.x) / NodeEditorGUI.Background.width,
                                                 ((curEditorState.zoomPos.y - curEditorState.canvasRect.height) * curEditorState.zoom + curEditorState.panOffset.y) / NodeEditorGUI.Background.height);
                // Amount of tiles
                Vector2 tileAmount = new Vector2(Mathf.Round(curEditorState.canvasRect.width * curEditorState.zoom) / NodeEditorGUI.Background.width,
                                                 Mathf.Round(curEditorState.canvasRect.height * curEditorState.zoom) / NodeEditorGUI.Background.height);
                // Draw tiled background
                GUI.DrawTextureWithTexCoords(curEditorState.canvasRect, NodeEditorGUI.Background, new Rect(tileOffset, tileAmount));
            }

            // Handle input events
            NodeEditorInputSystem.HandleInputEvents(curEditorState);
            if (Event.current.type != EventType.Layout)
            {
                curEditorState.ignoreInput = new List <Rect> ();
            }

            // We're using a custom scale method, as default one is messing up clipping rect
            Rect canvasRect = curEditorState.canvasRect;

            curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, NodeEditorGUI.isEditorWindow, false);

            // ---- BEGIN SCALE ----

            // Some features which require zoomed drawing:

            if (curEditorState.navigate)
            {             // Draw a curve to the origin/active node for orientation purposes
                Vector2 startPos = (curEditorState.selectedNode != null? curEditorState.selectedNode.rect.center : curEditorState.panOffset) + curEditorState.zoomPanAdjust;
                Vector2 endPos   = Event.current.mousePosition;
                RTEditorGUI.DrawLine(startPos, endPos, Color.green, null, 3);
                RepaintClients();
            }

            if (curEditorState.connectKnob != null)
            {             // Draw the currently drawn connection
                curEditorState.connectKnob.DrawConnection(Event.current.mousePosition);
                RepaintClients();
            }

            // Draw the groups below everything else
            for (int groupCnt = 0; groupCnt < curNodeCanvas.groups.Count; groupCnt++)
            {
                NodeGroup group = curNodeCanvas.groups[groupCnt];
                if (Event.current.type == EventType.Layout)
                {
                    group.isClipped = !curEditorState.canvasViewport.Overlaps(group.fullAABBRect);
                }
                if (!group.isClipped)
                {
                    group.DrawGroup();
                }
            }

            // Push the active node to the top of the draw order.
            if (Event.current.type == EventType.Layout && curEditorState.selectedNode != null)
            {
                curNodeCanvas.nodes.Remove(curEditorState.selectedNode);
                curNodeCanvas.nodes.Add(curEditorState.selectedNode);
            }

            // Draw the transitions and connections. Has to be drawn before nodes as transitions originate from node centers
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes [nodeCnt].DrawConnections();
            }

            // Draw the nodes
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = curNodeCanvas.nodes [nodeCnt];
                if (Event.current.type == EventType.Layout)
                {
                    node.isClipped = !curEditorState.canvasViewport.Overlaps(curNodeCanvas.nodes[nodeCnt].fullAABBRect);
                }
                if (!node.isClipped)
                {
                    node.DrawNode();
                    if (Event.current.type == EventType.Repaint)
                    {
                        node.DrawKnobs();
                    }
                }
            }

            // ---- END SCALE ----

            // End scaling group
            GUIScaleUtility.EndScale();

            // Handle input events with less priority than node GUI controls
            NodeEditorInputSystem.HandleLateInputEvents(curEditorState);

            EndEditingCanvas();
        }
Example #2
0
        /// <summary>
        /// Draws the Node Canvas on the screen in the rect specified by editorState without one-time wrappers like GUISkin and OverlayGUI. Made for nested Canvases (WIP)
        /// </summary>
        private static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState)
        {
            if (!editorState.drawing)
            {
                return;
            }

            BeginEditingCanvas(nodeCanvas, editorState);
            if (curNodeCanvas == null || curEditorState == null || !curEditorState.drawing)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                //绘制NodeEditor背景
                EditorGUI.DrawRect(curEditorState.canvasRect, new Color(28 / 255f, 28 / 255f, 28 / 255f));
            }

            // Handle input events
            NodeEditorInputSystem.HandleInputEvents(curEditorState);

            HandleMultipleSelect();

            if (Event.current.type != EventType.Layout)
            {
                curEditorState.ignoreInput = new List <Rect>();
            }

            // We're using a custom scale method, as default one is messing up clipping rect
            Rect canvasRect = curEditorState.canvasRect;

            curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom,
                                                                      NodeEditorGUI.isEditorWindow, false);

            // 开始绘制缩放区域
            if (curEditorState.connectKnob != null)
            {
                // Draw the currently drawn connection
                curEditorState.connectKnob.DrawConnection(Event.current.mousePosition);
                RepaintClients();
            }

            // Draw the groups below everything else
            for (int groupCnt = 0; groupCnt < curNodeCanvas.groups.Count; groupCnt++)
            {
                NodeGroup group = curNodeCanvas.groups[groupCnt];
                if (Event.current.type == EventType.Layout)
                {
                    group.isClipped = !curEditorState.canvasViewport.Overlaps(group.fullAABBRect);
                }
                if (!group.isClipped)
                {
                    group.DrawGroup();
                }
            }

            // Draw the transitions and connections. Has to be drawn before nodes as transitions originate from node centers
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                curNodeCanvas.nodes[nodeCnt].DrawConnections();
            }

            // Draw the nodes
            for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++)
            {
                Node node = curNodeCanvas.nodes[nodeCnt];
                if (Event.current.type == EventType.Layout)
                {
                    node.isClipped = !curEditorState.canvasViewport.Overlaps(curNodeCanvas.nodes[nodeCnt].fullAABBRect);
                }
                if (node.isClipped)
                {
                    continue;
                }

                node.DrawNode();
                if (Event.current.type == EventType.Repaint)
                {
                    node.DrawKnobs();
                }
            }

            // ---- END SCALE ----

            // End scaling group
            GUIScaleUtility.EndScale();

            // Handle input events with less priority than node GUI controls
            NodeEditorInputSystem.HandleLateInputEvents(curEditorState);

            EndEditingCanvas();
        }