/// <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> public static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState) { if (!editorState.drawing) { return; } // Store and restore later on in case of this being a nested Canvas NodeCanvas prevNodeCanvas = curNodeCanvas; NodeEditorState prevEditorState = curEditorState; curNodeCanvas = nodeCanvas; curEditorState = editorState; if (Event.current.type == EventType.Repaint) { // Draw Background when Repainting GUI.BeginClip(curEditorState.canvasRect); float width = NodeEditorGUI.Background.width / curEditorState.zoom; float height = NodeEditorGUI.Background.height / curEditorState.zoom; Vector2 offset = curEditorState.zoomPos + curEditorState.panOffset / curEditorState.zoom; offset = new Vector2(offset.x % width - width, offset.y % height - height); int tileX = Mathf.CeilToInt((curEditorState.canvasRect.width + (width - offset.x)) / width); int tileY = Mathf.CeilToInt((curEditorState.canvasRect.height + (height - offset.y)) / height); for (int x = 0; x < tileX; x++) { for (int y = 0; y < tileY; y++) { GUI.DrawTexture(new Rect(offset.x + x * width, offset.y + y * height, width, height), NodeEditorGUI.Background); } } GUI.EndClip(); } // Check the inputs InputEvents(); 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, false); //GUILayout.Label ("Scaling is Great!"); -> TODO: Test by changing the last bool parameter // ---- BEGIN SCALE ---- // Some features which require drawing (zoomed) if (curEditorState.navigate) { // Draw a curve to the origin/active node for orientation purposes RTEditorGUI.DrawLine((curEditorState.selectedNode != null? curEditorState.selectedNode.rect.center : curEditorState.panOffset) + curEditorState.zoomPanAdjust, ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom, Color.black, null, 3); RepaintClients(); } if (curEditorState.connectOutput != null) { // Draw the currently drawn connection NodeOutput output = curEditorState.connectOutput; Vector2 startPos = output.GetGUIKnob().center; Vector2 endPos = ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom; Vector2 endDir = output.GetDirection(); NodeEditorGUI.DrawConnection(startPos, endDir, endPos, NodeEditorGUI.GetSecondConnectionVector(startPos, endPos, endDir), ConnectionTypes.GetTypeData(output.type).col); RepaintClients(); } if (curEditorState.makeTransition != null) { // Draw the currently made transition RTEditorGUI.DrawLine(curEditorState.makeTransition.rect.center + curEditorState.zoomPanAdjust, ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom, Color.grey, null, 3); RepaintClients(); } // Push the active node at the bottom 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++) { Node node = curNodeCanvas.nodes [nodeCnt]; node.DrawTransitions(); node.DrawConnections(); } // Draw the nodes for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++) { Node node = curNodeCanvas.nodes [nodeCnt]; node.DrawNode(); if (Event.current.type == EventType.Repaint) { node.DrawKnobs(); } } // ---- END SCALE ---- // End scaling group GUIScaleUtility.EndScale(); // Check events with less priority than node GUI controls LateEvents(); curNodeCanvas = prevNodeCanvas; curEditorState = prevEditorState; }