Exemple #1
0
        protected virtual void AddOutputPort(Port port)
        {
            var view = PortView.Create(port, ConnectorListener);

            Outputs.Add(view);
            outputContainer.Add(view);
        }
Exemple #2
0
        protected virtual void AddInputPort(Port 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.FindPropertyRelative(port.fieldName);
                if (prop != null)
                {
                    var field = new PropertyField(prop, " ");
                    field.Bind(m_SerializedNode.serializedObject);
                    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);
        }
Exemple #3
0
        protected virtual void AddInputPort(Port port)
        {
            var view = PortView.Create(port, ConnectorListener);

            // If we're exposing a control element via reflection: include it in the view
            var reflection = NodeReflection.GetNodeType(Target.GetType());
            var element    = reflection.GetPortByName(port.Name)?.GetControlElement(this);

            if (element != null)
            {
                var container = new VisualElement();
                container.AddToClassList("property-field-container");
                container.Add(element);

                view.SetEditorField(container);
            }

            Inputs.Add(view);
            inputContainer.Add(view);
        }
Exemple #4
0
        private VisualElement AddItem(string property_path, int index)
        {
            var port_name = $"{this.list_name}[{index}]";
            var port      = parent_node.GetPort(port_name);
            var prop      = m_SerializedList.GetArrayElementAtIndex(index);

            if (port == null)
            {
                Debug.Log("Added port!");
                port = new Port {
                    name    = port_name,
                    isInput = false,
                    acceptsMultipleConnections = false,
                    type      = list_type,
                    fieldName = prop.propertyPath
                };
                parent_node.AddPort(port);
                m_SerializedList.serializedObject.Update();
            }
            var view = PortView.Create(port, port.type, m_ConnectorListener);

            view.hideEditorFieldOnConnection = false;

            var field = new PropertyField(prop, "");

            field.Bind(m_SerializedList.serializedObject);
            field.RegisterCallback((FocusOutEvent e) => m_OnPropertyChange());

            var container = new VisualElement();

            container.AddToClassList("property-field-container");
            container.style.flexDirection = FlexDirection.Row;
            var remove_button = new Button(() => {
                m_UpdateBinding();
                m_SerializedList.DeleteArrayElementAtIndex(index);
                m_SerializedList.serializedObject.ApplyModifiedProperties();
                m_UpdateBinding();
                int new_size    = m_SerializedList.arraySize;
                var canvas      = GetFirstAncestorOfType <CanvasView>();
                var connections = new List <Edge>(items[index].connections);
                foreach (var connection in connections)
                {
                    canvas.RemoveEdge(connection, false);
                }
                for (int i = index; i < new_size; i++)
                {
                    connections = new List <Edge>(items[i + 1].connections);
                    foreach (Edge connection in connections)
                    {
                        var connect_to = connection.input;
                        canvas.RemoveEdge(connection, false);
                        if (connect_to != null)
                        {
                            canvas.AddEdge(new Edge {
                                input  = connect_to,
                                output = items[i]
                            }, false);
                        }
                    }
                }
                canvas.DirtyAll();
                // Remove the last port from the list!
                parent_node.RemovePort(parent_node.GetPort($"{list_name}[{new_size}]"));
                m_SerializedList.serializedObject.Update();
                m_UpdateBinding();
                m_OnPropertyChange();
            });

            remove_button.text                          = "-";
            remove_button.style.color                   = new StyleColor(UnityEngine.Color.white);
            remove_button.style.backgroundColor         = new StyleColor(UnityEngine.Color.red);
            remove_button.style.marginBottom            = new StyleLength(0.0);
            remove_button.style.marginLeft              = new StyleLength(0.0);
            remove_button.style.marginTop               = new StyleLength(0.0);
            remove_button.style.marginRight             = new StyleLength(0.0);
            remove_button.style.borderBottomLeftRadius  = new StyleLength(0.0);
            remove_button.style.borderTopLeftRadius     = new StyleLength(0.0);
            remove_button.style.borderTopRightRadius    = new StyleLength(0.0);
            remove_button.style.borderBottomRightRadius = new StyleLength(0.0);
            container.Add(remove_button);
            container.Add(field);
            field.style.flexGrow = new StyleFloat(1.0f);

            view.SetEditorField(container);

            this.items.Add(view);
            Add(view);
            m_OnPropertyChange();
            return(view);
        }