/// <summary> /// Renders the graph editor in the editor window /// </summary> /// <param name="bounds">The bounds of the editor window</param> public void Draw(Rect bounds) { if (graph == null) { // Graph is not yet initialized DrawGraphNotInitializedMessage(bounds); return; } var cullingBias = new Vector2(renderCullingBias, renderCullingBias); //var screenBoundsPosition = Vector2.zero - cullingBias; //var screenBoundsSize = bounds.size + cullingBias * 2; var windowWorldPos = camera.ScreenToWorld(Vector2.zero); var windowWorldBounds = new Rect(windowWorldPos, bounds.size * camera.ZoomLevel); windowWorldBounds.position -= cullingBias; windowWorldBounds.size += cullingBias * 2; DrawGrid(windowWorldBounds); DrawBranding(bounds); DrawEditorStats(bounds); DrawOverlay(bounds); // Draw the links cursorDragLink.Draw(rendererContext, camera); foreach (var link in graph.Links) { if (DMathUtils.Intersects(windowWorldBounds, link)) { GraphLinkRenderer.DrawGraphLink(rendererContext, link, camera); } } // Draw the nodes GraphNode[] sortedNodes = graph.Nodes.ToArray(); System.Array.Sort(sortedNodes, new NodeZIndexComparer()); foreach (var node in sortedNodes) { if (node == null) { continue; } // Draw only if this node is visible in the editor if (DMathUtils.Intersects(windowWorldBounds, node.Bounds)) { var renderer = nodeRenderers.GetRenderer(node.GetType()); renderer.Draw(rendererContext, node, camera); } } selectionBox.Draw(editorStyle); DrawHUD(bounds); GraphTooltipRenderer.Draw(rendererContext, lastMousePosition); GraphTooltip.Clear(); }
/// <summary> /// Renders the graph editor in the editor window /// </summary> /// <param name="bounds">The bounds of the editor window</param> public void Draw(Rect bounds) { if (graph == null) { // Graph is not yet initialized DrawGraphNotInitializedMessage(bounds); return; } var windowWorldPos = camera.ScreenToWorld(Vector3.zero); var windowWorldBounds = new Rect(windowWorldPos.x, windowWorldPos.y, bounds.size.x, bounds.size.y); DrawGrid(windowWorldBounds); DrawBranding(bounds); // Draw the links cursorDragLink.Draw(rendererContext, camera); foreach (var link in graph.Links) { if (DMathUtils.Intersects(windowWorldBounds, link)) { GraphLinkRenderer.DrawGraphLink(rendererContext, link, camera); } } // Draw the nodes GraphNode[] sortedNodes = graph.Nodes.ToArray(); System.Array.Sort(sortedNodes, new NodeZIndexComparer()); foreach (var node in sortedNodes) { if (node == null) { continue; } // Draw only if this node is visible in the editor if (DMathUtils.Intersects(windowWorldBounds, node.Bounds)) { var renderer = nodeRenderers.GetRenderer(node.GetType()); renderer.Draw(rendererContext, node, camera); } } selectionBox.Draw(); DrawHUD(bounds); GraphTooltipRenderer.Draw(rendererContext, lastMousePosition); GraphTooltip.Clear(); }