コード例 #1
0
        void AddEntries(AbstractNode node, string[] title, List <NodeEntry> nodeEntries)
        {
            if (m_Graph is NodeGraph && !node.allowedInMainGraph)
            {
                return;
            }
            if (connectedPort == null)
            {
                nodeEntries.Add(new NodeEntry
                {
                    node             = node,
                    title            = title,
                    compatibleSlotId = -1
                });
                return;
            }

            var connectedSlot = connectedPort.slot;

            m_Slots.Clear();
            node.GetSlots(m_Slots);
            var hasSingleSlot = m_Slots.Count(s => s.isOutputSlot != connectedSlot.isOutputSlot) == 1;

            m_Slots.RemoveAll(slot =>
            {
                var materialSlot = (NodeSlot)slot;
                return(connectedSlot.isOutputSlot ? !connectedSlot.IsCompatibleWith(materialSlot) : !materialSlot.IsCompatibleWith(connectedSlot));
            });

            if (hasSingleSlot && m_Slots.Count == 1)
            {
                nodeEntries.Add(new NodeEntry
                {
                    node             = node,
                    title            = title,
                    compatibleSlotId = m_Slots.First().id
                });
                return;
            }

            foreach (var slot in m_Slots)
            {
                var entryTitle = new string[title.Length];
                title.CopyTo(entryTitle, 0);
                entryTitle[entryTitle.Length - 1] += ": " + slot.displayName;
                nodeEntries.Add(new NodeEntry
                {
                    title            = entryTitle,
                    node             = node,
                    compatibleSlotId = slot.id
                });
            }
        }
コード例 #2
0
        public void Initialize(AbstractNode inNode, IEdgeConnectorListener connectorListener)
        {
            AddStyleSheetPath("Styles/NodeView");
            AddToClassList("Node");

            if (inNode == null)
            {
                return;
            }

            var contents = this.Q("contents");

            m_ConnectorListener = connectorListener;
            node           = inNode;
            persistenceKey = node.guid.ToString();
            var priorityField = new IntegerField()
            {
                value = node.priority, name = "priority-field", visible = CalculatePriorityVisibility(node)
            };

            priorityField.OnValueChanged(e => node.priority = e.newValue);
            titleContainer.Insert(1, priorityField);
            m_PriorityField = priorityField;
            m_TitleLabel    = titleContainer.First(e => e.name == "title-label");
            m_TitleLabel.RegisterCallback <MouseDownEvent>(OnTitleLabelMouseDown);
            m_TitleField = new TextField
            {
                name    = "title-field",
                value   = inNode.name,
                visible = false
            };
            m_TitleField.style.positionType = PositionType.Absolute;
            m_TitleField.RegisterCallback <FocusOutEvent>(e => { OnEditTitleTextFinished(); });
            m_TitleField.RegisterCallback <KeyDownEvent>(OnTitleTextFieldKeyPressed);
            titleContainer.shadow.Add(m_TitleField);
            UpdateTitle();

            // Add controls container
            var controlsContainer = new VisualElement {
                name = "controls"
            };

            {
                m_ControlsDivider = new VisualElement {
                    name = "divider"
                };
                m_ControlsDivider.AddToClassList("horizontal");
                controlsContainer.Add(m_ControlsDivider);
                m_ControlItems = new VisualElement {
                    name = "items"
                };
                controlsContainer.Add(m_ControlItems);

                // Instantiate control views from node
                foreach (var propertyInfo in node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    foreach (IControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(IControlAttribute), false))
                    {
                        var control = attribute.InstantiateControl(node, new ReflectionProperty(propertyInfo));
                        if (control != null)
                        {
                            m_ControlItems.Add(control);
                        }
                    }
                }

                foreach (var fieldInfo in node.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                {
                    foreach (IControlAttribute attribute in fieldInfo.GetCustomAttributes(typeof(IControlAttribute), false))
                    {
                        var control = attribute.InstantiateControl(node, new ReflectionProperty(fieldInfo));
                        if (control != null)
                        {
                            m_ControlItems.Add(control);
                        }
                    }
                }
            }
            if (m_ControlItems.childCount > 0)
            {
                contents.Add(controlsContainer);
            }

            // Add port input container, which acts as a pixel cache for all port inputs
            m_PortInputContainer = new VisualElement
            {
                name            = "portInputContainer",
                clippingOptions = ClippingOptions.ClipAndCacheContents,
                pickingMode     = PickingMode.Ignore
            };
            Add(m_PortInputContainer);

            AddSlots(node.GetSlots <NodeSlot>());
            UpdatePortInputs();
            base.expanded = node.drawState.expanded;
            RefreshExpandedState();             //This should not be needed. GraphView needs to improve the extension api here
            UpdatePortInputVisibilities();

            SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));

            /*if (node is SubGraphNode)
             * {
             *      RegisterCallback<MouseDownEvent>(OnSubGraphDoubleClick);
             * }*/

            m_PortInputContainer.SendToBack();

            // Remove this after updated to the correct API call has landed in trunk. ------------
            VisualElement m_TitleContainer;
            VisualElement m_ButtonContainer;

            m_TitleContainer = this.Q("title");
            // -----------------------------------------------------------------------------------

            var settings = node as IHasSettings;

            if (settings != null)
            {
                m_NodeSettingsView         = new NodeSettingsView();
                m_NodeSettingsView.visible = false;

                Add(m_NodeSettingsView);

                m_SettingsButton = new VisualElement {
                    name = "settings-button"
                };
                m_SettingsButton.Add(new VisualElement {
                    name = "icon"
                });

                m_Settings = settings.CreateSettingsElement();

                m_SettingsButton.AddManipulator(new Clickable(() =>
                {
                    UpdateSettingsExpandedState();
                }));

                // Remove this after updated to the correct API call has landed in trunk. ------------
                m_ButtonContainer = new VisualElement {
                    name = "button-container"
                };
                m_ButtonContainer.style.flexDirection = StyleValue <FlexDirection> .Create(FlexDirection.Row);

                m_ButtonContainer.Add(m_SettingsButton);
                m_ButtonContainer.Add(m_CollapseButton);
                m_TitleContainer.Add(m_ButtonContainer);
                // -----------------------------------------------------------------------------------
                //titleButtonContainer.Add(m_SettingsButton);
                //titleButtonContainer.Add(m_CollapseButton);

                RegisterCallback <GeometryChangedEvent>(OnGeometryChanged);
            }
        }