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); } }