/// <summary> /// Draws the node transitions. /// </summary> public void DrawTransitions() { for (int cnt = 0; cnt < transitions.Count; cnt++) { Vector2 StartPoint = transitions[cnt].startNode.rect.center + NodeEditor.curEditorState.zoomPanAdjust; Vector2 EndPoint = transitions[cnt].endNode.rect.center + NodeEditor.curEditorState.zoomPanAdjust; NodeEditorGUI.DrawLine(StartPoint, EndPoint, Color.grey, null, 3); Rect selectRect = new Rect(0, 0, 20, 20); selectRect.center = Vector2.Lerp(StartPoint, EndPoint, 0.5f); if (GUI.Button(selectRect, "#")) { // TODO: Select } } }
/// <summary> /// Draws the Node Canvas on the screen in the rect specified by editorState /// </summary> public static void DrawSubCanvas(NodeCanvas nodeCanvas, NodeEditorState editorState) { if (!editorState.drawing) { return; } 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 = new Vector2((curEditorState.panOffset.x / curEditorState.zoom) % width - width, (curEditorState.panOffset.y / curEditorState.zoom) % 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++) { Rect texRect = new Rect(offset.x + x * width, offset.y + y * height, width, height); GUI.DrawTexture(texRect, NodeEditorGUI.Background); } } GUI.EndClip(); } // Check the inputs InputEvents(curEditorState.ignoreInput); curEditorState.ignoreInput = new List <Rect> (); // We're using a custom scale methode, as default one is messing up clipping rect Rect canvasRect = curEditorState.canvasRect; curEditorState.zoomPanAdjust = GUIScaleUtility.BeginScale(ref canvasRect, curEditorState.zoomPos, curEditorState.zoom, true); //GUILayout.Label ("Scaling is Great!"); -> Test by changin 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 NodeEditorGUI.DrawLine(curEditorState.activeNode != null? curEditorState.activeNode.rect.center + curEditorState.zoomPanAdjust : curEditorState.panOffset, ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom, Color.black, null, 3); if (Repaint != null) { Repaint(); } } if (curEditorState.connectOutput != null) { // Draw the currently drawn connection NodeOutput output = curEditorState.connectOutput; DrawConnection(output.GetGUIKnob().center, output.GetDirection(), ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom, Vector2.right, ConnectionTypes.GetTypeData(output.type).col); if (Repaint != null) { Repaint(); } } if (curEditorState.makeTransition != null) { // Draw the currently made transition NodeEditorGUI.DrawLine(curEditorState.makeTransition.rect.center + curEditorState.zoomPanAdjust, ScreenToGUIPos(mousePos) + curEditorState.zoomPos * curEditorState.zoom, Color.grey, null, 3); if (Repaint != null) { Repaint(); } } // Push the active cell at the bottom of the draw order. if (Event.current.type == EventType.Layout && curEditorState.activeNode != null) { curNodeCanvas.nodes.Remove(curEditorState.activeNode); curNodeCanvas.nodes.Add(curEditorState.activeNode); } // Draw the transitions. Has to be called before nodes as transitions originate from node centers for (int nodeCnt = 0; nodeCnt < curNodeCanvas.nodes.Count; nodeCnt++) { curNodeCanvas.nodes [nodeCnt].DrawTransitions(); } 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++) { curNodeCanvas.nodes [nodeCnt].DrawNode(); curNodeCanvas.nodes [nodeCnt].DrawKnobs(); } // ---- END SCALE ---- // End scaling group GUIScaleUtility.EndScale(); // Check events with less priority than node GUI controls LateEvents(curEditorState.ignoreInput); curNodeCanvas = prevNodeCanvas; curEditorState = prevEditorState; }