public void ProcessNodeInput(Node node, int inputId, Rect bigRect, Rect smallRect) { Event currentEvent = Event.current; EventType eventType = currentEvent.type; if (_node != null)//draging { if (!bigRect.Contains(currentEvent.mousePosition)) { return; } Link link = node.Inputs[inputId]; bool validate = NodeCollector.ValidateTypes(link.Type, _node.CashedOutputType) || NodeCollector.ValidateTypes(_node.CashedOutputType, link.Type); if (eventType == EventType.Repaint && validate) { _hoverInput = true; _inputPosition = GetNodeInputPosition(node, inputId); } if (eventType == EventType.MouseUp && currentEvent.button == 0) { Undo.RecordObject(Window._nodeDataContainer, "Change Link"); if (validate) { link.NodeId = _node.NodeId; } } } else// { if (eventType == EventType.MouseDown && currentEvent.button == 0 && smallRect.Contains(currentEvent.mousePosition)) { Link link = node.Inputs[inputId]; Node inNode = Window._nodeData.GetNode(link); if (inNode != null) { Undo.RecordObject(Window._nodeDataContainer, "Change Link"); _node = inNode; link.NodeId = Node.NoNodeID; DefaultNode.ToDefault(link, Window._nodeData); _hoverInput = false; Window.RebuildGraph(); currentEvent.Use(); } } } }
public static void ToDefault(Link link, NodeData nodeData) { if (link.NoDefaults) { return; } if (link.NodeId > NoNodeID) { return; } int nodeID = link.NodeId < NoNodeID ? link.NodeId : link.LastDefaultNode; Node defaultNode = nodeID < NoNodeID?nodeData.GetNode(link.NodeId) : null; if (defaultNode == null || !NodeCollector.ValidateTypes(link.Type, defaultNode.OutputType)) { defaultNode = nodeData.CreateDefaultNode(link.Type); } link.LastDefaultNode = link.NodeId = defaultNode != null ? defaultNode.NodeId : NoNodeID; }