Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }