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); }
public static void Draw(GraphRendererContext rendererContext, Vector2 mousePosition) { if (GraphTooltip.message == null || GraphTooltip.message.Trim().Length == 0) { return; } var tooltipPadding = new Vector2(4, 4); var drawPosition = mousePosition + new Vector2(15, 5); var tooltipString = GraphTooltip.message; var style = GUI.skin.GetStyle("label"); var contentSize = style.CalcSize(new GUIContent(tooltipString)); drawPosition -= tooltipPadding; contentSize += tooltipPadding * 2; var bounds = new Rect(drawPosition.x, drawPosition.y, contentSize.x, contentSize.y); GUI.backgroundColor = new Color(.15f, .15f, .15f); GUI.Box(bounds, ""); var innerGlow = rendererContext.Resources.GetResource <Texture2D>(DungeonEditorResources.TEXTURE_PIN_GLOW); GUI.DrawTexture(bounds, innerGlow); style.alignment = TextAnchor.MiddleCenter; GUI.color = Color.white; GUI.Label(bounds, tooltipString, style); }
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 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 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]); }
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}"; DrawTextCentered(rendererContext, node, camera, title, new Vector2(0, -2)); // 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); }
public void Draw(GraphRendererContext rendererContext, GraphCamera camera) { if (!active) { return; } var mouseWorld = camera.ScreenToWorld(mouseScreenPosition); mousePin.Position = mouseWorld; GraphLinkRenderer.DrawGraphLink(rendererContext, link, camera); // Check the pin that comes under the mouse pin var targetPin = graphEditor.GetPinUnderPosition(mouseWorld); if (targetPin != null) { var sourcePin = attachedPin; var pins = new GraphPin[] { sourcePin, targetPin }; Array.Sort(pins, new GraphPinHierarchyComparer()); string errorMessage; if (!GraphSchema.CanCreateLink(pins[0], pins[1], out errorMessage)) { GraphTooltip.message = errorMessage; } } }
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) { var commentNode = node as CommentNode; DrawMessage(rendererContext, commentNode, camera); // Draw the pins base.Draw(rendererContext, node, camera); }
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 virtual void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { // Draw the pins foreach (var pin in node.InputPins) { GraphPinRenderer.Draw(rendererContext, pin, camera); } foreach (var pin in node.OutputPins) { GraphPinRenderer.Draw(rendererContext, pin, camera); } }
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); } }
public override void Draw(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { DrawBackgroundTexture(rendererContext, node, camera); DrawThumbnail(rendererContext, node, camera); DrawFrameTexture(rendererContext, node, camera); base.Draw(rendererContext, node, camera); if (node.Selected) { DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_SELECTION); } }
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 pinHeight = node.OutputPins[0].BoundsOffset.height; DrawTextCentered(rendererContext, node, camera, node.Caption, new Vector2(0, -3)); // 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 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 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); } }
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 override void DrawFrameTexture(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_FRAME); DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_MULTI_GO_NODE_FRAME); }
protected virtual void DrawBackgroundTexture(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera) { DrawNodeTexture(rendererContext, node, camera, DungeonEditorResources.TEXTURE_GO_NODE_BG); }
protected virtual void DrawTextCentered(GraphRendererContext rendererContext, GraphNode node, GraphCamera camera, string text) { DrawTextCentered(rendererContext, node, camera, text, Vector2.zero); }