Exemplo n.º 1
0
        //the anchor passed to ths function must be in the `anchors` list
        void RenderAnchor(AnchorField anchorField, Anchor anchor, ref Rect renderRect)
        {
            //visual parameters for anchors:
            Vector2 anchorSize = new Vector2(13, 13);
            Vector2 margin     = new Vector2(0, 2);

            if (anchor.forcedY != -1)
            {
                renderRect.yMin = anchor.forcedY;
            }

            anchor.rect = new Rect(renderRect.min + margin, anchorSize);

            //anchor name:
            string anchorName = anchorField.name;

            if (!String.IsNullOrEmpty(anchor.name))
            {
                anchorName = anchor.name;
            }

            //anchor color:
            if (anchor.color != new Color(0, 0, 0, 0))
            {
                GUI.color = anchor.color;
            }
            else
            {
                GUI.color = ColorTheme.GetAnchorColor(anchor.colorSchemeName);
            }

            //highlight mode to GUI color:
            if (graphRef.editorEvents.isDraggingLink || graphRef.editorEvents.isDraggingNewLink)
            {
                if (anchor.highlighMode != AnchorHighlight.None)
                {
                    if (anchor.isLinkable)
                    {
                        GUI.color = highlightModeToColor[anchor.highlighMode];
                    }
                    else
                    {
                        GUI.color = ColorTheme.disabledAnchorColor;
                    }
                }
            }

            //Draw the anchor:
            GUI.DrawTexture(anchor.rect, anchorTexture, ScaleMode.ScaleToFit);

            //Draw the anchor name if not null
            if (!string.IsNullOrEmpty(anchorName))
            {
                Rect    anchorNameRect = anchor.rect;
                Vector2 textSize       = GUI.skin.label.CalcSize(new GUIContent(anchorName));
                if (anchorField.anchorType == AnchorType.Input)
                {
                    anchorNameRect.position += new Vector2(-6, -2);
                }
                else
                {
                    anchorNameRect.position += new Vector2(-textSize.x + 4, -2);
                }
                anchorNameRect.size = textSize + new Vector2(15, 4);                 //add the anchorLabel size
                GUI.depth           = 10;
                GUI.Label(anchorNameRect, anchorName, (anchorField.anchorType == AnchorType.Input) ? inputAnchorLabelStyle : outputAnchorLabelStyle);
            }

            //error display (required unlinked anchors)
            if (anchor.visibility == Visibility.Visible &&
                anchorField.required &&
                !anchorField.multiple &&
                anchor.anchorType == AnchorType.Input &&
                anchor.linkCount == 0)
            {
                Rect errorIconRect = new Rect(anchor.rect);
                errorIconRect.size      = Vector2.one * 17;
                errorIconRect.position += new Vector2(-6, -10);
                GUI.color = Color.red;
                GUI.DrawTexture(errorIconRect, errorIcon);
                GUI.color = Color.white;
            }

            //debug:
            if (anchor.debug)
            {
                GUIContent debugContent = new GUIContent("c:" + anchor.linkCount + "|i:" + anchor.fieldIndex);

                Rect debugRect = anchor.rect;
                debugRect.xMax += 50;
                if (anchor.anchorType == AnchorType.Output)
                {
                    debugRect.x -= EditorStyles.label.CalcSize(debugContent).x;
                }
                EditorGUI.DrawRect(debugRect, Color.white * .8f);
                GUI.Label(debugRect, debugContent);
            }
        }