Esempio n. 1
0
 // Constructor
 public NodeLink(
     Node fromNode, Outlet fromOutlet,
     Node toNode, Inlet toInlet
 )
 {
     _fromNode = fromNode;
     _fromOutlet = fromOutlet;
     _toNode = toNode;
     _toInlet = toInlet;
 }
Esempio n. 2
0
 // Constructor
 public NodeLink(
     Node fromNode, Outlet fromOutlet,
     Node toNode, Inlet toInlet
     )
 {
     _fromNode   = fromNode;
     _fromOutlet = fromOutlet;
     _toNode     = toNode;
     _toInlet    = toInlet;
 }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
        // Enumerate all the links from a given outlet.
        public NodeLink[] EnumerateLinksFrom(Outlet outlet, Patch patch)
        {
            if (_cachedLinks == null)
            {
                CacheLinks(patch);
            }

            var temp = new List <NodeLink>();

            foreach (var link in _cachedLinks)
            {
                if (link.fromOutlet == outlet)
                {
                    temp.Add(link);
                }
            }

            return(temp.ToArray());
        }
Esempio n. 6
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();
            }
        }
Esempio n. 7
0
 public WiringState(Node node, Outlet outlet)
 {
     this.node   = node;
     this.outlet = outlet;
 }
Esempio n. 8
0
        // Try to create a link between two nodes.
        // Returns true if the link is established successfully.
        public static bool TryLinkNodes(
            NodeBase nodeFrom, Outlet outlet,
            NodeBase nodeTo, MethodInfo targetMethod
            )
        {
            var triggerEvent = outlet.boundEvent;
            // Determine the type of the target action.
            var actionType = GetUnityActionToInvokeMethod(targetMethod);

            if (actionType == null)
            {
                return(false);                    // invalid target method type
            }
            // Create an action that is bound to the target method.
            var targetAction = Delegate.CreateDelegate(
                actionType, nodeTo, targetMethod
                );

            if (triggerEvent is UnityEvent)
            {
                // The trigger event has no parameter.
                // Add the action to the event with a default parameter.
                if (actionType == typeof(UnityAction))
                {
                    UnityEventTools.AddVoidPersistentListener(
                        triggerEvent, (UnityAction)targetAction
                        );
                    return(true);
                }
                if (actionType == typeof(UnityAction <float>))
                {
                    UnityEventTools.AddFloatPersistentListener(
                        triggerEvent, (UnityAction <float>)targetAction, 1.0f
                        );
                    return(true);
                }
                //if (actionType == typeof(UnityAction<object>))
                //{
                //    UnityEventTools.AddPersistentListener(
                //        triggerEvent, (UnityAction<object>)targetAction,
                //        );
                //    return true;
                //}
            }
            else if (triggerEvent is UnityEvent <float> )
            {
                // The trigger event has a float parameter.
                // Then the target method should have a float parameter too.
                if (actionType == typeof(UnityAction <float>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <float>)triggerEvent,
                        (UnityAction <float>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <int> )
            {
                // The trigger event has a float parameter.
                // Then the target method should have a float parameter too.
                if (actionType == typeof(UnityAction <int>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <int>)triggerEvent,
                        (UnityAction <int>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <string> )
            {
                // The trigger event has a float parameter.
                // Then the target method should have a float parameter too.
                if (actionType == typeof(UnityAction <string>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <string>)triggerEvent,
                        (UnityAction <string>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Vector3> )
            {
                // The trigger event has a Vector3 parameter.
                // Then the target method should have a Vector3 parameter too.
                if (actionType == typeof(UnityAction <Vector3>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Vector3>)triggerEvent,
                        (UnityAction <Vector3>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Quaternion> )
            {
                // The trigger event has a Quaternion parameter.
                // Then the target method should have a Quaternion parameter too.
                if (actionType == typeof(UnityAction <Quaternion>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Quaternion>)triggerEvent,
                        (UnityAction <Quaternion>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Color> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <Color>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Color>)triggerEvent,
                        (UnityAction <Color>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <GameObject> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <GameObject>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <GameObject>)triggerEvent,
                        (UnityAction <GameObject>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Transform> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <Transform>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Transform>)triggerEvent,
                        (UnityAction <Transform>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Collision> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <Collision>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Collision>)triggerEvent,
                        (UnityAction <Collision>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Collider> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <Collider>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Collider>)triggerEvent,
                        (UnityAction <Collider>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Rigidbody> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <Rigidbody>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Rigidbody>)triggerEvent,
                        (UnityAction <Rigidbody>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Collision2D> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <Collision2D>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Collision2D>)triggerEvent,
                        (UnityAction <Collision2D>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Collider2D> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <Collider2D>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Collider2D>)triggerEvent,
                        (UnityAction <Collider2D>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Rigidbody2D> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <Rigidbody2D>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Rigidbody2D>)triggerEvent,
                        (UnityAction <Rigidbody2D>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <ContactPoint> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <ContactPoint>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <ContactPoint>)triggerEvent,
                        (UnityAction <ContactPoint>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <ContactPoint2D> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <ContactPoint2D>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <ContactPoint2D>)triggerEvent,
                        (UnityAction <ContactPoint2D>)targetAction
                        );
                    return(true);
                }
            }
            else if (triggerEvent is UnityEvent <Bounds> )
            {
                // The trigger event has a color parameter.
                // Then the target method should have a color parameter too.
                if (actionType == typeof(UnityAction <Bounds>))
                {
                    // Add the action to the event.
                    UnityEventTools.AddPersistentListener(
                        (UnityEvent <Bounds>)triggerEvent,
                        (UnityAction <Bounds>)targetAction
                        );
                    return(true);
                }
            }

            if (actionType == typeof(UnityAction))
            {
                UnityEventTools.AddVoidPersistentListener(triggerEvent, (UnityAction)targetAction);
                return(true);
            }
            return(false); // trigger-target mismatch
        }
Esempio n. 9
0
 public WiringState(Node node, Outlet outlet)
 {
     this.node = node;
     this.outlet = outlet;
 }
Esempio n. 10
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();
        }
Esempio n. 11
0
 public OutletButtonRecord(Node node, Outlet outlet)
 {
     this.node   = node;
     this.outlet = outlet;
 }
Esempio n. 12
0
 public OutletButtonRecord(Node node, Outlet outlet)
 {
     this.node = node;
     this.outlet = outlet;
 }
Esempio n. 13
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();
        }
Esempio n. 14
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();
            }
        }
Esempio n. 15
0
        // Enumerate all the links from a given outlet.
        public NodeLink[] EnumerateLinksFrom(Outlet outlet, Patch patch)
        {
            if (_cachedLinks == null) CacheLinks(patch);

            var temp = new List<NodeLink>();

            foreach (var link in _cachedLinks)
                if (link.fromOutlet == outlet) temp.Add(link);

            return temp.ToArray();
        }