示例#1
0
        protected virtual void AddOutputPort(NodePort port)
        {
            var view = PortView.Create(port, port.type, m_ConnectorListener);

            outputs.Add(view);
            outputContainer.Add(view);
        }
示例#2
0
        protected virtual void AddInputPort(NodePort port)
        {
            var view = PortView.Create(port, port.type, m_ConnectorListener);

            // If we want to display an inline editable field as part
            // of the port, create a new PropertyField and bind it.
            if (port.fieldName != null)
            {
                var prop = m_SerializedNode.FindProperty(port.fieldName);
                if (prop != null)
                {
                    var field = new PropertyField(prop, " ");
                    field.Bind(m_SerializedNode);
                    field.RegisterCallback((FocusOutEvent e) => OnPropertyChange());

                    var container = new VisualElement();
                    container.AddToClassList("property-field-container");
                    container.Add(field);

                    view.SetEditorField(container);
                }
            }

            inputs.Add(view);
            inputContainer.Add(view);
        }
示例#3
0
        public static PortView Create(
            NodePort port,
            Type type,
            IEdgeConnectorListener connectorListener
            )
        {
            var view = new PortView(
                Orientation.Horizontal,
                port.isInput ? Direction.Input : Direction.Output,
                port.isMulti ? Capacity.Multi : Capacity.Single,
                type
                )
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener),
                portName        = port.portName,
                target          = port
            };

            // Override default connector text with the human-readable port name
            // TODO: Apparently the edge connector (Edge.output.portName) is based on whatever
            // is in this label. So re-labeling it will inadvertedly change the port name.
            // (or it might be a two way binding). So natively, we won't be able to have multiple
            // ports with the same name.
            // view.m_ConnectorText.text = refPort.displayName;

            view.AddManipulator(view.m_EdgeConnector);
            return(view);
        }
示例#4
0
        protected void AddOutputPort(NodePort port)
        {
            var view = PortView.Create(
                port,
                m_SerializedNode.FindProperty(port.fieldName),
                port.type,
                m_ConnectorListener
                );

            outputs.Add(view);
            outputContainer.Add(view);
        }
示例#5
0
        /// <summary>
        /// Return true if this port can be connected with an edge to the given port
        /// </summary>
        public bool IsCompatibleWith(PortView other)
        {
            if (other.node == node || other.direction == direction)
            {
                return(false);
            }

            // TODO: Loop detection to ensure nobody is making a cycle
            // (for certain use cases, that is)

            // Check for type cast support in the direction of output port -> input port
            return((other.direction == Direction.Input && portType.IsCastableTo(other.portType, true)) ||
                   (other.direction == Direction.Output && other.portType.IsCastableTo(portType, true)));
        }
示例#6
0
        public void CreateNode(NodeReflectionData data, Vector2 screenPosition, PortView connectedPort = null)
        {
            var windowRoot          = m_EditorWindow.rootVisualElement;
            var windowMousePosition = m_EditorWindow.rootVisualElement.ChangeCoordinatesTo(
                windowRoot.parent,
                screenPosition - m_EditorWindow.position.position
                );

            var graphMousePosition = contentViewContainer.WorldToLocal(windowMousePosition);

            var node = data.CreateInstance();

            node.graphPosition = graphMousePosition;

            m_Graph.AddNode(node);

            // Add a node to the visual graph
            var editorType = NodeReflection.GetNodeEditorType(data.type);
            var element    = Activator.CreateInstance(editorType) as NodeView;

            element.Initialize(node, m_EdgeListener);

            AddElement(element);

            AssetDatabase.AddObjectToAsset(node, m_Graph);
            AssetDatabase.SaveAssets();

            // If there was a provided existing port to connect to, find the best
            // candidate port on the new node and connect.
            if (connectedPort != null)
            {
                var edge = new Edge();

                if (connectedPort.direction == Direction.Input)
                {
                    edge.input  = connectedPort;
                    edge.output = element.GetCompatibleOutputPort(connectedPort);
                }
                else
                {
                    edge.output = connectedPort;
                    edge.input  = element.GetCompatibleInputPort(connectedPort);
                }

                ConnectNodes(edge);
            }

            Dirty(element);
        }
示例#7
0
        public static PortView Create(
            NodePort port,
            SerializedProperty prop,
            Type type,
            IEdgeConnectorListener connectorListener
            )
        {
            var view = new PortView(
                Orientation.Horizontal,
                port.isInput ? Direction.Input : Direction.Output,
                port.isMulti ? Capacity.Multi : Capacity.Single,
                type
                )
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener),
                portName        = port.portName,
                target          = port
            };

            // Override default connector text with the human-readable port name
            // TODO: Apparently the edge connector (Edge.output.portName) is based on whatever
            // is in this label. So re-labeling it will inadvertedly change the port name.
            // (or it might be a two way binding). So natively, we won't be able to have multiple
            // ports with the same name.
            // view.m_ConnectorText.text = refPort.displayName;

            view.AddManipulator(view.m_EdgeConnector);

            // Bind to the underlying field
            if (prop != null && port.isInput) // TODO refPort.isEditable)
            {
                view.m_PropertyField = new PropertyField(prop, " ");
                view.m_PropertyField.Bind(prop.serializedObject);
                view.m_ConnectorBox.parent.Add(view.m_PropertyField);
            }

            return(view);
        }
示例#8
0
 public void OpenSearch(Vector2 screenPosition, PortView connectedPort = null)
 {
     m_SearchProvider.connectedPort = connectedPort;
     SearchWindow.Open(new SearchWindowContext(screenPosition), m_SearchProvider);
 }
示例#9
0
 public PortView GetCompatibleOutputPort(PortView input)
 {
     return(outputs.Find((port) => port.IsCompatibleWith(input)));
 }