예제 #1
0
        public NodeDisplayContainers(NodeView nodeView, NodeViewDrawer nodeViewDrawer)
        {
            NodeView       = nodeView;
            NodeViewDrawer = nodeViewDrawer;

            HeaderContainer      = new VisualElement();
            HeaderContainer.name = "header-container";
            NodeView.Insert(0, HeaderContainer);

            PreTitleContainer = CreateBaseElement("pre-title-container", LightGray);
            NodeView.titleContainer.Insert(0, PreTitleContainer);

            PostTitleContainer = CreateBaseElement("post-title-container", LightGray);
            NodeView.titleContainer.Add(PostTitleContainer);

            PrimaryBodyContainer = CreateBaseElement("upper-body-container", DarkGray);
            NodeView.Q <VisualElement>("contents")?.Insert(1, PrimaryBodyContainer);

            SecondaryBodyContainer = CreateBaseElement("body-container", DarkGray);
            NodeView.extensionContainer.Add(SecondaryBodyContainer);

            FooterContainer      = new VisualElement();
            FooterContainer.name = "footer-container";
            NodeView.Add(FooterContainer);

            AllOutportsContainer = CreateBaseElement("all-ports-container", MediumGray);
            NodeView.outputContainer.Add(AllOutportsContainer);

            TitleElement       = NodeView.Q <VisualElement>("title");
            NodeBordersElement = NodeView.Q <VisualElement>("node-border");

            //VisualElement SelectionBorder = NodeView.Q<VisualElement>("selection-border");
            //NodeBordersElement.Add(SelectionBorder);

            UpdateColor();
        }
        public NodeView(ANode node,
                        SerializedProperty serializedNode,
                        NodeGraphView nodeGraphView,
                        IEdgeConnectorListener edgeConnectorListener,
                        NodeViewDrawer nodeViewDrawer) : base()
        {
            if (serializedNode == null)
            {
                return;
            }

            Node                    = node;
            NodeType                = Node.GetType();
            SerializedNode          = serializedNode;
            m_nodeGraphView         = nodeGraphView;
            m_edgeConnectorListener = edgeConnectorListener;

            NodeId = SerializedNode.FindPropertyRelative(ANode.IdVarname).stringValue;

            m_nodeViewDrawer        = nodeViewDrawer;
            m_nodeDisplayContainers = new NodeDisplayContainers(this, m_nodeViewDrawer);
            m_nodeViewDrawer.SetNodeView(this, SerializedNode, nodeGraphView.NodeGraph, m_nodeDisplayContainers);
            m_nodeViewDrawer.OnSetup();

            title = m_nodeViewDrawer.DisplayName;

            bool isEntryNode = (typeof(BuiltInNodes.EntryNode)).IsAssignableFrom(NodeType);

            if (isEntryNode)
            {
                this.capabilities = this.capabilities & (~Capabilities.Deletable);
            }

            if (!isEntryNode)
            {
                //Add ports
                m_inport = new PortView(this,
                                        Orientation.Horizontal,
                                        Direction.Input,
                                        Port.Capacity.Single,
                                        typeof(bool),
                                        0,
                                        m_nodeViewDrawer.NodeColor,
                                        m_edgeConnectorListener);
                m_inport.portName = "";
                m_nodeDisplayContainers.SetInport(m_inport);
            }

            CreateOutports();

            // Draw node
            m_nodeViewDrawer.Repaint(m_outports);

            RefreshExpandedState();
            RefreshPorts();

            Vector2 pos = SerializedNode.FindPropertyRelative(ANode.PositionVarName).vector2Value;

            SetPosition(new Rect(pos, Vector2.zero));

            //this.RegisterCallback<GeometryChangedEvent>((GeometryChangedEvent gce) => { Debug.Log(gce.newRect.position); });
        }