Exemplo n.º 1
0
        static void     CreateLink(PWGraph graph, PWGraphCommand command, string inputCommand)
        {
            //get nodes from the graph:
            PWNode fromNode, toNode;

            GetNodes(graph, command, out fromNode, out toNode, inputCommand);

            //Create the first linkable anchors we found:
            foreach (var outAnchor in fromNode.outputAnchors)
            {
                foreach (var inAnchor in toNode.inputAnchors)
                {
                    if (PWAnchorUtils.AnchorAreAssignable(outAnchor, inAnchor))
                    {
                        //if the input anchor is already linked, find another
                        if (inAnchor.linkCount == 1)
                        {
                            continue;
                        }

                        graph.CreateLink(outAnchor, inAnchor);
                        return;
                    }
                }
            }

            Debug.LogError("Can't link " + fromNode + " with " + toNode);
        }
Exemplo n.º 2
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;
         }
     }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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));
        }