public virtual void OnRenderAnchorConnection(T anchor, AnchorConnection connection) { if (connection.target == null || anchor.parent.parent != connection.target.parent.parent) { NodifyEditorUtilities.SafeDestroy(connection.gameObject); return; } Rect contentRect = GetContentRect(anchor); object targetRenderer = NodifyEditorUtilities.FindAnchorRenderer(connection.target.GetType()); if (targetRenderer != null) { Rect targetRect = (Rect)targetRenderer.GetType().GetMethod("GetContentRect").Invoke(targetRenderer, new object[] { connection.target }); Vector2 bezierStartPoint = contentRect.center; Vector2 bezierEndPoint = targetRect.center; float sizePercentage = 1f / NodifyEditorUtilities.currentSelectedGroup.editorZoomAmount; float lineSize = 2 * sizePercentage; NodifyEditorUtilities.DrawBezier(bezierStartPoint, bezierEndPoint, new Color(0, 0, 0, .25f), lineSize, 50); GUISkin skin = Resources.Load <GUISkin>("Styles/Nodify2EditorSkin"); GUIStyle minusButtonStyle = NodifyEditorUtilities.FindStyleByName(skin, "Node Anchor Remove"); GUIStyle connectionArrowStyle = NodifyEditorUtilities.FindStyleByName(skin, "Node Anchor Field Connection Arrow"); Vector2 centerPoint = NodifyEditorUtilities.PointOnBezier(bezierStartPoint, bezierEndPoint, .5f, 25); this.OnRenderAnchorConnectionMinusButton(anchor, connection, minusButtonStyle, connectionArrowStyle, centerPoint, bezierStartPoint, bezierEndPoint); } }
public virtual void OnRender(T anchor) { object parentRenderer = NodifyEditorUtilities.FindNodeRenderer(anchor.parent.GetType()); if (parentRenderer != null) { Rect parentRect = (Rect)parentRenderer.GetType().GetMethod("GetContentRect").Invoke(parentRenderer, new object[] { anchor.parent }); Rect contentRect = GetContentRect(anchor); if (contentRect.size != Vector2.zero) { float sizePercentage = 1f / NodifyEditorUtilities.currentSelectedGroup.editorZoomAmount; float lineSize = 2 * sizePercentage; NodifyEditorUtilities.DrawBezier(parentRect.center, contentRect.center, Color.black, lineSize, 15); GUIContent anchorContent = GetContent(anchor); GUIStyle anchorStyle = GetRenderStyle(anchor); if (anchorContent != null && anchorStyle != null) { GUI.Box(contentRect, GetContent(anchor), GetRenderStyle(anchor)); } } } }
public virtual void OnRenderNodeConnection(T anchor, NodeConnection connection) { if (connection.target == null || anchor.parent.parent != connection.target.parent) { NodifyEditorUtilities.SafeDestroy(connection.gameObject); return; } Rect contentRect = GetContentRect(anchor); object targetRenderer = NodifyEditorUtilities.FindNodeRenderer(connection.target.GetType()); if (targetRenderer != null) { Rect targetRect = (Rect)targetRenderer.GetType().GetMethod("GetContentRect").Invoke(targetRenderer, new object[] { connection.target }); Vector2 bezierStartPoint = NodifyEditorUtilities.ClosestPointOnRectangle(targetRect.center, contentRect); Vector2 bezierEndPoint = NodifyEditorUtilities.ClosestPointOnRectangle(bezierStartPoint, targetRect); if (anchor.type == AnchorType.METHOD) { Vector2 towardsStartCenter = (contentRect.center - bezierStartPoint).normalized; Vector2 towardsTargetCenter = (targetRect.center - bezierEndPoint).normalized; bezierStartPoint = new Vector2(bezierStartPoint.x + (towardsStartCenter.x * 10), bezierStartPoint.y + (towardsStartCenter.y * 10)); bezierEndPoint = new Vector2(bezierEndPoint.x + (towardsTargetCenter.x * 10), bezierEndPoint.y + (towardsTargetCenter.y * 10)); } Color bezierColor = Color.black; if (connection.state == ConnectionState.RUN) { bezierColor = Color.green; } if (connection.state == ConnectionState.ERROR) { bezierColor = Color.red; } float sizePercentage = 1f / NodifyEditorUtilities.currentSelectedGroup.editorZoomAmount; float lineSize = 2 * sizePercentage; NodifyEditorUtilities.DrawBezier(bezierStartPoint, bezierEndPoint, bezierColor, lineSize, Mathf.Abs(bezierEndPoint.y - bezierStartPoint.y) / 2); GUISkin skin = Resources.Load <GUISkin>("Styles/Nodify2EditorSkin"); GUIStyle minusButtonStyle = NodifyEditorUtilities.FindStyleByName(skin, "Node Anchor Remove"); GUIStyle connectionArrowStyle = NodifyEditorUtilities.FindStyleByName(skin, "Node Anchor Method Connection Arrow"); Vector2 centerPoint = NodifyEditorUtilities.PointOnBezier(bezierStartPoint, bezierEndPoint, .5f, Mathf.Abs(bezierEndPoint.y - bezierStartPoint.y) / 2); this.OnRenderNodeConnectionMinusButton(anchor, connection, minusButtonStyle, connectionArrowStyle, centerPoint, bezierStartPoint, bezierEndPoint); } }
public void DrawCurrentConnectingAnchor(Anchor anchor) { object renderer = Nodify.Editor.NodifyEditorUtilities.FindAnchorRenderer(anchor.GetType()); Rect contentRect = (Rect)renderer.GetType().GetMethod("GetContentRect").Invoke(renderer, new object[] { anchor }); Rect targetPosition = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 2, 2); NodifyEditorUtilities.DrawBezier(contentRect.center, targetPosition.center, Color.black, 2, 75); this.Repaint(); }