Exemple #1
0
 // Constructor
 public NodeLink(
     Node fromNode, Outlet fromOutlet,
     Node toNode, Inlet toInlet
 )
 {
     _fromNode = fromNode;
     _fromOutlet = fromOutlet;
     _toNode = toNode;
     _toInlet = toInlet;
 }
Exemple #2
0
        // Rescan the patch.
        public void Rescan()
        {
            _nodeList.Clear();
            _instanceIDToNodeMap.Clear();

            // Enumerate all the node instances.
            foreach (var i in _instance.GetComponentsInChildren<Wiring.NodeBase>())
            {
                var node = new Node(i);
                _nodeList.Add(node);
                _instanceIDToNodeMap.Add(i.GetInstanceID(), node);
            }
        }
Exemple #3
0
 public WiringState(Node node, Outlet outlet)
 {
     this.node = node;
     this.outlet = outlet;
 }
Exemple #4
0
 public WiringState(Node node, Inlet inlet)
 {
     this.node = node;
     this.inlet = inlet;
 }
Exemple #5
0
        // Show the inlet/outlet context menu .
        void ShowNodeButtonMenu(Node node, Inlet inlet, Outlet outlet)
        {
            var menu = new GenericMenu();

            if (inlet != null)
            {
                // "New Connection"
                menu.AddItem(
                    new GUIContent("New Connection"), false,
                    BeginWiring, new WiringState(node, inlet)
                );

                // Disconnection items
                foreach (var targetNode in _patch.nodeList)
                {
                    var link = targetNode.TryGetLinkTo(node, inlet, _patch);
                    if (link == null) continue;

                    var label = "Disconnect/" + targetNode.displayName;
                    menu.AddItem(new GUIContent(label), false, RemoveLink, link);
                }
            }
            else
            {
                // "New Connection"
                menu.AddItem(
                    new GUIContent("New Connection"), false,
                    BeginWiring, new WiringState(node, outlet)
                );

                // Disconnection items
                foreach (var link in node.EnumerateLinksFrom(outlet, _patch))
                {
                    var label = "Disconnect/" + link.toNode.displayName;
                    menu.AddItem(new GUIContent(label), false, RemoveLink, link);
                }
            }

            menu.ShowAsContext();
        }
Exemple #6
0
 public OutletButtonRecord(Node node, Outlet outlet)
 {
     this.node = node;
     this.outlet = outlet;
 }
Exemple #7
0
 public InletButtonRecord(Node node, Inlet inlet)
 {
     this.node = node;
     this.inlet = inlet;
 }
Exemple #8
0
 public DeleteNodeRecord(Node node)
 {
     this.node = node;
 }
Exemple #9
0
        // Add a node instance to the patch.
        public void AddNodeInstance(Wiring.NodeBase nodeInstance)
        {
            // Append to the hierarchy.
            nodeInstance.transform.parent = _instance.transform;

            // Register to this patch representation.
            var node = new Node(nodeInstance);
            _nodeList.Add(node);
            _instanceIDToNodeMap.Add(nodeInstance.GetInstanceID(), node);
        }
Exemple #10
0
        // Remove all links to a given node.
        public void RemoveLinksTo(Node targetNode, Patch patch)
        {
            if (_cachedLinks == null) CacheLinks(patch);

            foreach (var link in _cachedLinks)
                if (link.toNode == targetNode)
                    RemoveLink(link.fromOutlet, link.toNode, link.toInlet);
        }
Exemple #11
0
        // Remove a link to a given node/inlet.
        public void RemoveLink(Outlet outlet, Node targetNode, Inlet inlet)
        {
            Undo.RecordObject(_instance, "Remove Link");

            // Retrieve the target method (inlet) information.
            var targetMethod = targetNode._instance.GetType().GetMethod(inlet.methodName);

            // Remove the link.
            LinkUtility.RemoveLinkNodes(
                _instance, outlet.boundEvent,
                targetNode._instance, targetMethod
            );

            // Clear the cache and update information.
            _cachedLinks = null;
            _serializedObject.Update();
        }
Exemple #12
0
        // Try to make a link from the outlet to a given node/inlet.
        public void TryLinkTo(Outlet outlet, Node targetNode, Inlet inlet)
        {
            Undo.RecordObject(_instance, "Link To Node");

            // Retrieve the target method (inlet) information.
            var targetMethod = targetNode._instance.GetType().GetMethod(inlet.methodName);

            // Try to create a link.
            var result = LinkUtility.TryLinkNodes(
                _instance, outlet.boundEvent,
                targetNode._instance, targetMethod
            );

            // Clear the cache and update information.
            if (result) {
                _cachedLinks = null;
                _serializedObject.Update();
            }
        }
Exemple #13
0
        // If this node has a link to a given inlet, return it.
        public NodeLink TryGetLinkTo(Node targetNode, Inlet inlet, Patch patch)
        {
            if (_cachedLinks == null) CacheLinks(patch);

            foreach (var link in _cachedLinks)
                if (link.toInlet == inlet) return link;

            return null;
        }