Esempio n. 1
0
 public void RaiseOnLinkStartDragged(PWAnchor anchor)
 {
     if (OnLinkStartDragged != null)
     {
         OnLinkStartDragged(anchor);
     }
 }
Esempio n. 2
0
        //this function will be called twiced, from the two linked anchors
        // and so will receive two different anchor in parameter
        public void OnAfterDeserialize(PWAnchor anchor)
        {
            if (anchor.anchorType == PWAnchorType.Output)
            {
                fromAnchor = anchor;
            }
            else
            {
                toAnchor = anchor;
            }

            if (fromAnchor != null)
            {
                fromNode = fromAnchor.nodeRef;
            }
            if (toAnchor != null)
            {
                toNode = toAnchor.nodeRef;
            }

            //update link color:
            if (fromAnchor != null)
            {
                colorSchemeName = fromAnchor.colorSchemeName;
            }
        }
Esempio n. 3
0
        public PWAnchor CreateNewAnchor()
        {
            PWAnchor newAnchor = new PWAnchor();

            newAnchor.Initialize(this);
            anchors.Add(newAnchor);
            return(newAnchor);
        }
Esempio n. 4
0
 //called once (when link is created only)
 public void Initialize(PWAnchor fromAnchor, PWAnchor toAnchor)
 {
     this.fromAnchor = fromAnchor;
     this.toAnchor   = toAnchor;
     fromNode        = fromAnchor.nodeRef;
     toNode          = toAnchor.nodeRef;
     GUID            = System.Guid.NewGuid().ToString();
 }
Esempio n. 5
0
 //disable anchors which are unlinkable with the anchor in parameter
 public void DisableIfUnlinkable(PWAnchor anchorToLink)
 {
     foreach (var anchor in anchors)
     {
         if (!PWAnchorUtils.AnchorAreAssignable(anchorToLink, anchor))
         {
             anchor.isLinkable = false;
         }
     }
 }
Esempio n. 6
0
        public static bool              AnchorAreAssignable(PWAnchor from, PWAnchor to, bool verbose = false)
        {
            if (from.anchorType == to.anchorType || from.nodeRef == to.nodeRef)
            {
                return(false);
            }

            //swap anchor if from is input and to is output
            Type fromType = (from.anchorType == PWAnchorType.Output) ? from.fieldType : to.fieldType;
            Type toType   = (to.anchorType == PWAnchorType.Input) ? to.fieldType : from.fieldType;

            if (verbose)
            {
                Debug.Log("fromType: " + fromType + ", toType: " + toType);
                Debug.Log(fromType.ToString() + " can be placed into " + toType.ToString() + ": " + AreAssignable(fromType, toType));
            }
            return(AreAssignable(fromType, toType));
        }
Esempio n. 7
0
        //create a link without checking for duplication
        public PWNodeLink       CreateLink(PWAnchor fromAnchor, PWAnchor toAnchor, bool raiseEvents = true)
        {
            PWNodeLink link    = new PWNodeLink();
            PWAnchor   fAnchor = fromAnchor;
            PWAnchor   tAnchor = toAnchor;

            //swap anchors if input/output are reversed
            if (fromAnchor.anchorType != PWAnchorType.Output)
            {
                tAnchor = fromAnchor;
                fAnchor = toAnchor;
            }

            if (!PWAnchorUtils.AnchorAreAssignable(fAnchor, tAnchor))
            {
                Debug.LogWarning("[PWGraph] attempted to create a link between unlinkable anchors: " + fAnchor.fieldType + " into " + tAnchor.fieldType);
                return(null);
            }

            link.Initialize(fAnchor, tAnchor);
            nodeLinkTable.AddLink(link);

            //raise link creation event
            if (OnLinkCreated != null && raiseEvents)
            {
                OnLinkCreated(link);
            }

            link.fromNode.AddLink(link);
            link.toNode.AddLink(link);

            if (OnPostLinkCreated != null && raiseEvents)
            {
                OnPostLinkCreated(link);
            }

            return(link);
        }
Esempio n. 8
0
        public PWNodeLink       SafeCreateLink(PWAnchor fromAnchor, PWAnchor toAnchor)
        {
            PWAnchor fAnchor = fromAnchor;
            PWAnchor tAnchor = toAnchor;

            //swap anchors if input/output are reversed
            if (fromAnchor.anchorType != PWAnchorType.Output)
            {
                tAnchor = fromAnchor;
                fAnchor = toAnchor;
            }

            if (!PWAnchorUtils.AnchorAreAssignable(fAnchor, tAnchor))
            {
                return(null);
            }

            if (tAnchor.linkCount > 0)
            {
                tAnchor.RemoveAllLinks();
            }

            return(CreateLink(fAnchor, tAnchor));
        }
Esempio n. 9
0
        //the anchor passed to ths function must be in the `anchors` list
        void RenderAnchor(PWAnchor anchor, ref Rect renderRect, int index)
        {
            //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 = 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 = PWColorTheme.GetAnchorColor(anchor.colorSchemeName);
            }

            //highlight mode to GUI color:
            if (graphRef.editorEvents.isDraggingLink || graphRef.editorEvents.isDraggingNewLink)
            {
                if (anchor.highlighMode != PWAnchorHighlight.None)
                {
                    if (anchor.isLinkable)
                    {
                        GUI.color = highlightModeToColor[anchor.highlighMode];
                    }
                    else
                    {
                        GUI.color = PWColorTheme.disabledAnchorColor;
                    }
                }
            }
            // GUI.DrawTexture(singleAnchor.anchorRect, anchorDisabledTexture); //???

            //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 (anchorType == PWAnchorType.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, (anchorType == PWAnchorType.Input) ? inputAnchorLabelStyle : outputAnchorLabelStyle);
            }

            //error display (required unlinked anchors)
            if (anchor.visibility == PWVisibility.Visible &&
                required &&
                !multiple &&
                anchor.anchorType == PWAnchorType.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 == PWAnchorType.Output)
                {
                    debugRect.x -= EditorStyles.label.CalcSize(debugContent).x;
                }
                EditorGUI.DrawRect(debugRect, Color.white * .8f);
                GUI.Label(debugRect, debugContent);
            }
        }
Esempio n. 10
0
 public void Reset()
 {
     anchorUnderMouse = null;
 }
Esempio n. 11
0
        static void FindAnchors(PWAnchorField fromAnchorField, PWAnchorField toAnchorField, out PWAnchor fromAnchor, out PWAnchor toAnchor)
        {
            if (fromAnchorField.multiple)
            {
                fromAnchor = fromAnchorField.anchors.Find(a => a.linkCount == 0);
            }
            else
            {
                fromAnchor = fromAnchorField.anchors.First();
            }

            if (toAnchorField.multiple)
            {
                toAnchor = toAnchorField.anchors.Find(a => a.linkCount == 0);
            }
            else
            {
                toAnchor = toAnchorField.anchors.First();
            }
        }
Esempio n. 12
0
 //SafeCreateLink will create link and delete other overlapping links if there are
 public PWNodeLink       SafeCreateLink(PWAnchor anchor)
 {
     return(SafeCreateLink(editorEvents.startedLinkAnchor, anchor));
 }