void HandleBoxSelection(Rect boundsScreenSpace) { bool multiSelect = keyboardState.ShiftPressed; bool selectedStateChanged = false; foreach (var node in graph.Nodes) { // node bounds in world space var nodeBounds = new Rect(node.Bounds); // convert the position to screen space nodeBounds.position = camera.WorldToScreen(nodeBounds.position); var selected = nodeBounds.Overlaps(boundsScreenSpace); if (multiSelect) { if (selected) { selectedStateChanged |= SetSelectedState(node, selected); } } else { selectedStateChanged |= SetSelectedState(node, selected); } } if (selectedStateChanged) { OnNodeSelectionChanged(); } }
public static void DrawGraphLink(GraphRendererContext rendererContext, GraphLink link, GraphCamera camera) { if (link.Input == null || link.Output == null) { // Link not initialized yet. nothing to draw return; } Vector2 startPos = camera.WorldToScreen(link.Output.WorldPosition); Vector2 endPos = camera.WorldToScreen(link.Input.WorldPosition); var tangentStrength = link.GetTangentStrength(); Vector3 startTan = startPos + link.Output.Tangent * tangentStrength; Vector3 endTan = endPos + link.Input.Tangent * tangentStrength; var lineColor = new Color(1, 1, 1, 0.75f); Handles.DrawBezier(startPos, endPos, startTan, endTan, lineColor, null, 3); // Draw the arrow cap var rotation = Quaternion.FromToRotation(new Vector3(1, 0, 0), link.Input.Tangent.normalized); float arrowSize = 10.0f; float arrowWidth = 0.5f; var arrowTails = new Vector2[] { rotation *new Vector3(1, arrowWidth) * arrowSize, rotation *new Vector3(1, -arrowWidth) * arrowSize, }; Handles.color = lineColor; //Handles.DrawPolyLine(arrowTails); Handles.DrawLine(endPos, endPos + arrowTails[0]); Handles.DrawLine(endPos, endPos + arrowTails[1]); Handles.DrawLine(endPos + arrowTails[0], endPos + arrowTails[1]); }
void DrawMessage(GraphRendererContext rendererContext, CommentNode node, GraphCamera camera) { var style = new GUIStyle(GUI.skin.GetStyle("Label")); style.alignment = TextAnchor.UpperLeft; var miniFontBaseSize = 20; style.normal.textColor = node.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR; if (camera.ZoomLevel >= 2) { float scaledFontSize = style.fontSize; if (scaledFontSize == 0) { scaledFontSize = miniFontBaseSize; } scaledFontSize = Mathf.Max(1.0f, scaledFontSize / camera.ZoomLevel); style.fontSize = Mathf.RoundToInt(scaledFontSize); style.font = CommentNodeRenderUtils.GetRenderFont(); } GUI.backgroundColor = node.background; // Update the node bounds var padding = new Vector2(10, 10); var textSize = style.CalcSize(new GUIContent(node.message)); var nodeSize = textSize + padding * 2; Rect boxBounds; { var positionScreen = camera.WorldToScreen(node.Position); var sizeScreen = nodeSize / camera.ZoomLevel; boxBounds = new Rect(positionScreen, sizeScreen); } Rect textBounds; { var positionScreen = camera.WorldToScreen(node.Position + padding); var sizeScreen = textSize / camera.ZoomLevel; textBounds = new Rect(positionScreen, sizeScreen); } GUI.Box(boxBounds, ""); style.normal.textColor = textColor; GUI.Label(textBounds, node.message, style); { var nodeBounds = node.Bounds; nodeBounds.size = nodeSize; node.Bounds = nodeBounds; } }
public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { // Draw the background base texture DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_BG); var style = GUI.skin.GetStyle("Label"); style.alignment = TextAnchor.MiddleCenter; var positionScreen = camera.WorldToScreen(node.Position); var pinHeight = node.OutputPins[0].BoundsOffset.height; var labelBounds = new Rect(positionScreen.x, positionScreen.y, node.Bounds.width, node.Bounds.height - pinHeight / 2); style.normal.textColor = node.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR; GUI.Label(labelBounds, node.Caption, style); // Draw the foreground frame textures DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_FRAME); if (node.Selected) { DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_SELECTION); } // Draw the pins base.Draw(rendererContext, node, camera); }
protected virtual void DrawTextCentered(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera, string text, Vector2 offset) { var style = GUI.skin.GetStyle("Label"); style.alignment = TextAnchor.MiddleCenter; var positionScreen = camera.WorldToScreen(node.Position + offset); var labelSize = new Vector2(node.Bounds.width, node.Bounds.height) / camera.ZoomLevel; var labelBounds = new Rect(positionScreen.x, positionScreen.y, labelSize.x, labelSize.y); style.normal.textColor = node.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR; var originalFont = style.font; var originalFontSize = style.fontSize; var miniFontBaseSize = 20; if (camera.ZoomLevel >= 2) { float scaledFontSize = originalFontSize; if (scaledFontSize == 0) { scaledFontSize = miniFontBaseSize; } scaledFontSize = Mathf.Max(1.0f, scaledFontSize / camera.ZoomLevel); style.fontSize = Mathf.RoundToInt(scaledFontSize); style.font = UnityEditor.EditorStyles.miniFont; } GUI.Label(labelBounds, text, style); style.font = originalFont; style.fontSize = originalFontSize; }
public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { // Draw the background base texture DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_BG); var style = GUI.skin.GetStyle("Label"); style.alignment = TextAnchor.MiddleCenter; var emitterNode = node as MarkerEmitterNode; var title = (emitterNode.Marker != null) ? emitterNode.Marker.Caption : "{NONE}"; var positionScreen = camera.WorldToScreen(node.Position); var labelBounds = new Rect(positionScreen.x, positionScreen.y, node.Bounds.width, node.Bounds.height - 5); style.normal.textColor = node.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR; GUI.Label(labelBounds, title, style); // Draw the foreground frame textures DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_EMITTER_NODE_FRAME); if (node.Selected) { DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MARKER_NODE_SELECTION); } // Draw the pins base.Draw(rendererContext, node, camera); }
protected void DrawBackgroundBox(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { var screenPosition = camera.WorldToScreen(node.Bounds.position); var screenBounds = new Rect(screenPosition.x, screenPosition.y, node.Bounds.width, node.Bounds.height); GUI.backgroundColor = getBackgroundColor(node); GUI.Box(screenBounds, ""); }
public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_BG); var thumbObject = GetThumbObject(node); var visualNode = node as VisualNode; if (thumbObject != null) { Texture texture = AssetThumbnailCache.Instance.GetThumb(thumbObject); if (texture != null) { var positionWorld = new Vector2(12, 12) + visualNode.Position; var positionScreen = camera.WorldToScreen(positionWorld); GUI.DrawTexture(new Rect(positionScreen.x, positionScreen.y, 96, 96), texture); } } else { var style = GUI.skin.GetStyle("Label"); style.alignment = TextAnchor.MiddleCenter; var positionScreen = camera.WorldToScreen(visualNode.Position); var labelBounds = new Rect(positionScreen.x, positionScreen.y, visualNode.Bounds.width, visualNode.Bounds.height); style.normal.textColor = visualNode.Selected ? GraphEditorConstants.TEXT_COLOR_SELECTED : GraphEditorConstants.TEXT_COLOR; GUI.Label(labelBounds, "None", style); } DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_FRAME); base.Draw(rendererContext, node, camera); if (node.Selected) { DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_SELECTION); } }
protected void DrawNodeTexture(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera, string textureName) { var shadowTexture = rendererContext.Resources.GetResource <Texture2D>(textureName); if (shadowTexture != null) { var center = camera.WorldToScreen(node.Bounds.center); var position = center; position.x -= shadowTexture.width / 2.0f; position.y -= shadowTexture.height / 2.0f; var size = new Vector2(shadowTexture.width, shadowTexture.height); var rect = new Rect(position.x, position.y, size.x, size.y); GUI.DrawTexture(rect, shadowTexture); } }
protected virtual void DrawThumbnail(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { var thumbObject = GetThumbObject(node); var visualNode = node as VisualNode; var thumbnailSize = 96 / camera.ZoomLevel; if (thumbObject != null) { Texture texture = AssetThumbnailCache.Instance.GetThumb(thumbObject); if (texture != null) { var positionWorld = new Vector2(12, 12) + visualNode.Position; var positionScreen = camera.WorldToScreen(positionWorld); GUI.DrawTexture(new Rect(positionScreen.x, positionScreen.y, thumbnailSize, thumbnailSize), texture); } } else { DrawTextCentered(rendererContext, node, camera, "None"); } }
public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { var domainNode = node as SCBaseDomainNode; var ringTexture = rendererContext.Resources.GetResource <Texture2D>(DungeonEditorResources.TEXTURE_CURSOR_RING_SOLID); var bounds = camera.WorldToScreen(node.Bounds); var color = GetNodeColor(domainNode); GUI.DrawTexture(bounds, ringTexture, ScaleMode.ScaleToFit, true, 1.0f, color, 0, 0); // Draw the domain, if we are snapped if (domainNode.IsSnapped && !domainNode.Dragging) { const float DomainSizeHi = 0.75f; const float DomainSizeLo = 0.15f; var domainRectSize = bounds.size; if (domainNode.RuleDomain == SCRuleNodeDomain.Corner) { domainRectSize = Vector2.one * (SCBaseDomainNode.TileSize * DomainSizeLo); } else if (domainNode.RuleDomain == SCRuleNodeDomain.Tile) { domainRectSize = Vector2.one * (SCBaseDomainNode.TileSize * DomainSizeHi); } else if (domainNode.RuleDomain == SCRuleNodeDomain.Edge) { var coords = domainNode.GetHalfGridLogicalCoords(); var localSize = (coords.x == 1) ? new Vector2(DomainSizeHi, DomainSizeLo) : new Vector2(DomainSizeLo, DomainSizeHi); domainRectSize = localSize * SCBaseDomainNode.TileSize; } domainRectSize /= camera.ZoomLevel; var domainBounds = new Rect(bounds.center - domainRectSize / 2.0f, domainRectSize); var domainColor = color; domainColor.a *= 0.5f; var origColor = GUI.color; GUI.color = domainColor; GUI.Box(domainBounds, ""); GUI.color = origColor; } }
public static void Draw(GraphRendererContext rendererContext, GraphPin pin, GraphCamera camera) { var pinBounds = new Rect(pin.GetBounds()); var positionWorld = pin.Node.Position + pinBounds.position; var positionScreen = camera.WorldToScreen(positionWorld); pinBounds.position = positionScreen; pinBounds.size /= camera.ZoomLevel; var originalColor = GUI.backgroundColor; GUI.backgroundColor = GetPinColor(pin); GUI.Box(pinBounds, ""); GUI.backgroundColor = originalColor; // Draw the pin texture var pinTexture = rendererContext.Resources.GetResource <Texture2D>(DungeonEditorResources.TEXTURE_PIN_GLOW); if (pinTexture != null) { GUI.DrawTexture(pinBounds, pinTexture); } }