Пример #1
0
        // Tie the nodeView to its data
        public void ConnectToData(AbstractMaterialNode inNode, IEdgeConnectorListener connectorListener)
        {
            if (inNode == null)
            {
                return;
            }

            // Set references
            node  = inNode;
            title = "";
            m_ConnectorListener = connectorListener;

            viewDataKey = node.guid.ToString();

            // Set the VisualElement's position
            SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));
            AddSlots(node.GetSlots <MaterialSlot>());

            // Removing a divider that made the ui a bit ugly
            VisualElement contents = mainContainer.Q("contents");
            VisualElement divider  = contents?.Q("divider");

            if (divider != null)
            {
                divider.RemoveFromHierarchy();
            }
        }
Пример #2
0
        public static PortView Create(
            Port port,
            Type type,
            IEdgeConnectorListener connectorListener
            )
        {
            if (type == null)
            {
                Debug.Log($"Port {port.name} has null type");
            }
            var view = new PortView(
                Orientation.Horizontal,
                port.isInput ? Direction.Input : Direction.Output,
                port.acceptsMultipleConnections ? Capacity.Multi : Capacity.Single,
                type
                )
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener),
                portName        = port.name,
                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);
        }
Пример #3
0
 public BasePortView(BasePort port, IEdgeConnectorListener connectorListener) : this(
         orientation : port.orientation == BasePort.Orientation.Horizontal ? Orientation.Horizontal : Orientation.Vertical,
         direction : port.direction == BasePort.Direction.Input ? Direction.Input : Direction.Output,
         capacity : port.capacity == BasePort.Capacity.Single ? Capacity.Single : Capacity.Multi,
         port.type, connectorListener)
 {
 }
Пример #4
0
 protected virtual void InitEdgeConnector(IEdgeConnectorListener listener)
 {
     dragHelper = new BaseEdgeDragHelper(listener);
     activators.Add(new ManipulatorActivationFilter {
         button = MouseButton.LeftMouse
     });
 }
 public BaseEdgeConnector(IEdgeConnectorListener listener) : base()
 {
     dragHelper = new BaseEdgeDragHelper(listener);
     active     = false;
     activators.Add(new ManipulatorActivationFilter {
         button = MouseButton.LeftMouse
     });
 }
Пример #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="node">Node that needs view</param>
        /// <param name="edgeConnectorListener">Edge connector listener for this view</param>
        public BaseNodeView(SNode node, IEdgeConnectorListener edgeConnectorListener)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/BaseNodeView"));

            Node = node;
            EdgeConnectorListener = edgeConnectorListener;

            title = ObjectNames.NicifyVariableName(node.NodeType.Name);
            base.SetPosition(new Rect(node.Position, Vector2.zero));

            foreach (var port in Node.Ports)
            {
                AddPort(port);
            }

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

            if (Node.PropertyBlock.GetType() != typeof(PropertyBlock))
            {
                _propertiesExpander = new VisualElement()
                {
                    name = "properties-expander"
                };
                {
                    var divider = new VisualElement()
                    {
                        name = "divider"
                    };
                    {
                        divider.AddToClassList("horizontal");
                    }
                    _propertiesExpander.Add(divider);

                    _propertiesToggle = new VisualElement()
                    {
                        name = "properties-toggle"
                    };
                    {
                        _propertiesToggle.AddManipulator(new Clickable(TogglePropertiesView));

                        var icon = new VisualElement()
                        {
                            name = "icon"
                        };
                        _propertiesToggle.Add(icon);
                    }
                    _propertiesExpander.Add(_propertiesToggle);
                }
                contents.Add(_propertiesExpander);
            }

            Node.PortsChanged += NodeOnPortsChanged;

            RefreshPorts();
            RefreshExpandedState();
        }
Пример #7
0
        public static Port Create(IEdgeConnectorListener connectorListener, Direction direction, string name)
        {
            var port = new FSMNodePort(Orientation.Horizontal, direction, Capacity.Multi, null)
            {
                m_EdgeConnector = new EdgeConnector <FSMEdgeView>(connectorListener),
            };

            port.AddManipulator(port.m_EdgeConnector);
            port.portName = name;
            return(port);
        }
Пример #8
0
        public static Port Create(MaterialSlot slot, IEdgeConnectorListener connectorListener)
        {
            var port = new ShaderPort(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output, null)
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener),
            };

            port.AddManipulator(port.m_EdgeConnector);
            port.slot        = slot;
            port.portName    = slot.displayName;
            port.visualClass = slot.concreteValueType.ToClassName();
            return(port);
        }
Пример #9
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="port">Port that needs view</param>
        /// <param name="portOrientation">Orientation of port</param>
        /// <param name="edgeConnectorListener">Edge connector listener for a port</param>
        public BasePortView(SPort port, Orientation portOrientation, IEdgeConnectorListener edgeConnectorListener)
            : base(portOrientation,
                   port.Direction == PortDirection.Input ? Direction.Input : Direction.Output,
                   port.Capacity == PortCapacity.Multiple ? Capacity.Multi : Capacity.Single,
                   port.Type)
        {
            Port            = port;
            portName        = ObjectNames.NicifyVariableName(port.Id);
            m_EdgeConnector = CreateEdgeConnector(edgeConnectorListener);
            this.AddManipulator(m_EdgeConnector);

            tooltip = port.Type.ToString();
        }
        public NodeGraphView(GraphTypeMetadata graphTypeMetadata)
        {
            styleSheets.Add(Resources.Load <StyleSheet>(ResourceAssetPaths.NodeGraphView_StyleSheet));

            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
            CustomContentDragger customContentDragger = new CustomContentDragger();

            this.AddManipulator(customContentDragger);
            SecondarySelectionDragger secondarySelectionDragger = new SecondarySelectionDragger();

            this.AddManipulator(secondarySelectionDragger); // Order here matters because the SecondarySelectionDragger allows the event to propagate
            this.AddManipulator(new SelectionDragger());
            this.AddManipulator(new RectangleSelector());

            // Grid lines
            m_gridBackground = new GridBackground();
            Insert(0, m_gridBackground);
            m_gridBackground.StretchToParentSize();

            // Minimap
            m_miniMap = new MiniMap {
                anchored = true
            };
            m_miniMap.SetPosition(new Rect(0, 0, 200, 200));
            this.RegisterCallback <GeometryChangedEvent>((GeometryChangedEvent evt) => { m_miniMap.SetPosition(new Rect(evt.newRect.xMax - 210, evt.newRect.yMax - 210, 200, 200)); });
            Add(m_miniMap);

            GraphTypeMetadata    = graphTypeMetadata;
            m_nodeCreationWindow = ScriptableObject.CreateInstance <NodeCreationWindow>();
            m_nodeCreationWindow.Setup(this, GraphTypeMetadata);

            nodeCreationRequest = context =>
            {
                SearchWindow.Open(new SearchWindowContext(context.screenMousePosition, 0, 0), m_nodeCreationWindow);
            };
            graphViewChanged += OnGraphViewChanged;

            m_edgeConectorListener  = new EdgeConnectorListener(this);
            serializeGraphElements += CopyAndSerializeGraphElements;
            unserializeAndPaste    += UnserializeAndPasteGraphElements;
            canPasteSerializedData += CanUnserializeAndPaste;

            RegisterCallback <MouseMoveEvent>(x => { m_mousePosition = x.localMousePosition; });
            RegisterCallback <MouseUpEvent>(x => { OnMouseClick?.Invoke(); });
            Undo.undoRedoPerformed += () => { SetNodeCollection(NodeGraph); };

            m_graphAxesController = new GraphAxesController(this, customContentDragger, secondarySelectionDragger);
            Add(m_graphAxesController);
            m_graphAxesController.PlaceBehind(contentViewContainer);
            m_graphAxesController.SetEnable(true);
        }
Пример #11
0
        public static Port Create(LogicSlot logicSlot, IEdgeConnectorListener connectorListener)
        {
            var port = new LogicPort(Orientation.Horizontal,
                                     logicSlot.isInputSlot ? Direction.Input : Direction.Output,
                                     logicSlot.isInputSlot ? Capacity.Single : Capacity.Multi,
                                     null)
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener),
            };

            port.AddManipulator(port.m_EdgeConnector);
            port.Slot = logicSlot;
            return(port);
        }
Пример #12
0
        public static Port Create(PortDescription portDescription, IEdgeConnectorListener connectorListener)
        {
            var port = new PortView(Orientation.Horizontal,
                                    portDescription.isInputSlot ? Direction.Input : Direction.Output,
                                    portDescription.isInputSlot ? Capacity.Single : Capacity.Multi,
                                    null)
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener),
            };

            port.AddManipulator(port.m_EdgeConnector);
            port.PortDescription = portDescription;
            return(port);
        }
        public static PortView Create(Port port, IEdgeConnectorListener connectorListener)
        {
            Direction direction = port.Direction == PortDirection.Input ? Direction.Input : Direction.Output;
            Capacity  capacity  = port.Capacity == PortCapacity.Multiple ? Capacity.Multi : Capacity.Single;

            var view = new PortView(Orientation.Horizontal, direction, capacity, port.Type)
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener),
                portName        = port.Name,
                Target          = port
            };

            view.AddManipulator(view.m_EdgeConnector);
            return(view);
        }
Пример #14
0
        public static Port Create(NodeSlot slot, IEdgeConnectorListener connectorListener)
        {
            var port = new NodePort(Orientation.Horizontal, slot.isInputSlot ? Direction.Input : Direction.Output,
                                    slot.isInputSlot || slot.allowMultipleConnections ? Capacity.Single : Capacity.Multi, null)
            {
                m_EdgeConnector = new EdgeConnector <UnityEditor.Experimental.UIElements.GraphView.Edge>(connectorListener),
            };

            port.AddManipulator(port.m_EdgeConnector);
            port.slot        = slot;
            port.portName    = slot.displayName;
            port.portType    = slot.valueType.Type;
            port.visualClass = slot.valueType.Type.Name;
            return(port);
        }
Пример #15
0
        public void Initialize(NodeEditor nodeEditor, IEdgeConnectorListener connectorListener)
        {
            AddStyleSheetPath("Styles/LogicNodeView");

            _connectorListener = connectorListener;
            NodeEditor         = nodeEditor;
            title = NodeEditor.NodeType();

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

            var controlsContainer = new VisualElement {
                name = "controls"
            };

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

                foreach (var propertyInfo in
                         nodeEditor.GetType().GetProperties(BindingFlags.Instance |
                                                            BindingFlags.Public |
                                                            BindingFlags.NonPublic))
                {
                    foreach (INodeControlAttribute attribute in
                             propertyInfo.GetCustomAttributes(typeof(INodeControlAttribute), false))
                    {
                        _controlItems.Add(attribute.InstantiateControl(nodeEditor, propertyInfo));
                    }
                }
            }
            contents.Add(controlsContainer);

            List <PortDescription> foundSlots = new List <PortDescription>();

            nodeEditor.GetSlots(foundSlots);
            AddSlots(foundSlots);

            SetPosition(new Rect(nodeEditor.Position.x, nodeEditor.Position.y, 0, 0));
            base.expanded = nodeEditor.Expanded;
            RefreshExpandedState();
        }
Пример #16
0
        protected virtual void CreateNodeView()
        {
            Assert.IsNull(View);
            View = CreateView();

            rootVisualElement.Clear();
            rootVisualElement.Add(View);
            View.StretchToParentSize();

            View.AddManipulator(new ContentDragger());
            View.AddManipulator(new SelectionDragger());
            View.AddManipulator(new RectangleSelector());
            View.AddManipulator(new ClickSelector());

            EdgeConnectorListener = CreateEdgeConnectorListener();
        }
Пример #17
0
        public static VisualPort Create(PortDescription description, IEdgeConnectorListener connectorListener)
        {
            var port = new VisualPort(Orientation.Horizontal,
                                      description.IsInputSlot ? Direction.Input : Direction.Output,
                                      description.AllowMultipleConnections ? Capacity.Multi : Capacity.Single,
                                      null)
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener)
            };

            port.AddManipulator(port.m_EdgeConnector);
            port.PortDescription = description;
            port.visualClass     = "type" + port.PortDescription.PortType.Name;
            port.m_portGraphics.AddToClassList("type" + port.PortDescription.PortType.Name);
            return(port);
        }
Пример #18
0
        public static Port Create(string portName, Direction portDirection, IEdgeConnectorListener connectorListener, Type type, UdonNodeData data, int index, Orientation orientation = Orientation.Horizontal)
        {
            Capacity capacity = Capacity.Single;

            if (portDirection == Direction.Input && type == null || portDirection == Direction.Output && type != null)
            {
                capacity = Capacity.Multi;
            }
            var port = new UdonPort(orientation, portDirection, capacity, type)
            {
                m_EdgeConnector = new EdgeConnector <Edge>(connectorListener),
            };

            port.portName        = portName;
            port._udonNodeData   = data;
            port._nodeValueIndex = index;

            port.SetupPort();
            return(port);
        }
Пример #19
0
        public PortView(NodeView owner,
                        Orientation portOrientation,
                        Direction portDirection,
                        Capacity capacity,
                        Type type,
                        int index,
                        Color portColor,
                        IEdgeConnectorListener edgeConnectorListener)
            : base(portOrientation, portDirection, capacity, type)
        {
            Node                 = owner;
            PortIndex            = index;
            this.m_EdgeConnector = new EdgeConnector <EdgeView>(edgeConnectorListener);
            this.AddManipulator(m_EdgeConnector);

            if (portColor != Color.clear) // Clear implies custom color was not implemented!
            {
                this.portColor = portColor;
            }
        }
Пример #20
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);
        }
Пример #21
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="editorViewFactory">Factory to use for creating additional views</param>
        public BaseGraphView(IGraphEditorViewFactory editorViewFactory)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/BaseGraphView"));

            _editorViewFactory     = editorViewFactory;
            _edgeConnectorListener = new EdgeConnectorListener(this);

            _background = new GridBackground()
            {
                name = "GridBackground"
            };
            Add(_background);

            _graphTypeLabel = new Label()
            {
                name = "GraphTypeLabel"
            };
            Add(_graphTypeLabel);

            _graphTypeLabel.SendToBack();
            _background.SendToBack();

            graphViewChanged += OnGraphViewChanged;
        }
Пример #22
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);
            }
        }
        public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManager, IEdgeConnectorListener connectorListener, GraphView graphView)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/MaterialNodeView"));
            styleSheets.Add(Resources.Load <StyleSheet>($"Styles/ColorMode"));
            AddToClassList("MaterialNode");

            if (inNode == null)
            {
                return;
            }

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

            m_GraphView = graphView;

            m_ConnectorListener = connectorListener;
            node        = inNode;
            viewDataKey = node.guid.ToString();
            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))
                    {
                        m_ControlItems.Add(attribute.InstantiateControl(node, propertyInfo));
                    }
                }
            }
            if (m_ControlItems.childCount > 0)
            {
                contents.Add(controlsContainer);
            }

            if (node.hasPreview)
            {
                // Add actual preview which floats on top of the node
                m_PreviewContainer = new VisualElement
                {
                    name          = "previewContainer",
                    cacheAsBitmap = true,
                    style         = { overflow = Overflow.Hidden },
                    pickingMode   = PickingMode.Ignore
                };
                m_PreviewImage = new Image
                {
                    name        = "preview",
                    pickingMode = PickingMode.Ignore,
                    image       = Texture2D.whiteTexture,
                };
                {
                    // Add preview collapse button on top of preview
                    var collapsePreviewButton = new VisualElement {
                        name = "collapse"
                    };
                    collapsePreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    collapsePreviewButton.AddManipulator(new Clickable(() =>
                    {
                        node.owner.owner.RegisterCompleteObjectUndo("Collapse Preview");
                        UpdatePreviewExpandedState(false);
                    }));
                    m_PreviewImage.Add(collapsePreviewButton);
                }
                m_PreviewContainer.Add(m_PreviewImage);

                // Hook up preview image to preview manager
                m_PreviewRenderData = previewManager.GetPreview(inNode);
                m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture;
                UpdatePreviewTexture();

                // Add fake preview which pads out the node to provide space for the floating preview
                m_PreviewFiller = new VisualElement {
                    name = "previewFiller"
                };
                m_PreviewFiller.AddToClassList("expanded");
                {
                    var previewDivider = new VisualElement {
                        name = "divider"
                    };
                    previewDivider.AddToClassList("horizontal");
                    m_PreviewFiller.Add(previewDivider);

                    var expandPreviewButton = new VisualElement {
                        name = "expand"
                    };
                    expandPreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    expandPreviewButton.AddManipulator(new Clickable(() =>
                    {
                        node.owner.owner.RegisterCompleteObjectUndo("Expand Preview");
                        UpdatePreviewExpandedState(true);
                    }));
                    m_PreviewFiller.Add(expandPreviewButton);
                }
                contents.Add(m_PreviewFiller);

                UpdatePreviewExpandedState(node.previewExpanded);
            }

            // Add port input container, which acts as a pixel cache for all port inputs
            m_PortInputContainer = new VisualElement
            {
                name          = "portInputContainer",
                cacheAsBitmap = true,
                style         = { overflow = Overflow.Hidden },
                pickingMode   = PickingMode.Ignore
            };
            Add(m_PortInputContainer);

            AddSlots(node.GetSlots <MaterialSlot>());
            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();

            m_TitleContainer = this.Q("title");

            var masterNode = node as IMasterNode;

            if (masterNode != null)
            {
                AddToClassList("master");

                if (!masterNode.IsPipelineCompatible(GraphicsSettings.renderPipelineAsset))
                {
                    AttachMessage("The current render pipeline is not compatible with this master node.", ShaderCompilerMessageSeverity.Error);
                }
            }

            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 = new VisualElement();
            AddDefaultSettings();

            // Add Node type specific settings
            var nodeTypeSettings = node as IHasSettings;

            if (nodeTypeSettings != null)
            {
                m_Settings.Add(nodeTypeSettings.CreateSettingsElement());
            }

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

            if (m_Settings.childCount > 0)
            {
                m_ButtonContainer = new VisualElement {
                    name = "button-container"
                };
                m_ButtonContainer.style.flexDirection = FlexDirection.Row;
                m_ButtonContainer.Add(m_SettingsButton);
                m_ButtonContainer.Add(m_CollapseButton);
                m_TitleContainer.Add(m_ButtonContainer);
            }
        }
Пример #24
0
        public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManager, IEdgeConnectorListener connectorListener)
        {
            AddStyleSheetPath("Styles/MaterialNodeView");
            AddToClassList("MaterialNode");

            if (inNode == null)
            {
                return;
            }

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

            m_ConnectorListener = connectorListener;
            node           = inNode;
            persistenceKey = node.guid.ToString();
            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))
                    {
                        m_ControlItems.Add(attribute.InstantiateControl(node, propertyInfo));
                    }
                }
            }
            if (m_ControlItems.childCount > 0)
            {
                contents.Add(controlsContainer);
            }

            if (node.hasPreview)
            {
                // Add actual preview which floats on top of the node
                m_PreviewContainer = new VisualElement
                {
                    name            = "previewContainer",
                    clippingOptions = ClippingOptions.ClipAndCacheContents,
                    pickingMode     = PickingMode.Ignore
                };
                m_PreviewImage = new Image
                {
                    name        = "preview",
                    pickingMode = PickingMode.Ignore,
                    image       = Texture2D.whiteTexture,
                };
                {
                    // Add preview collapse button on top of preview
                    var collapsePreviewButton = new VisualElement {
                        name = "collapse"
                    };
                    collapsePreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    collapsePreviewButton.AddManipulator(new Clickable(() =>
                    {
                        node.owner.owner.RegisterCompleteObjectUndo("Collapse Preview");
                        UpdatePreviewExpandedState(false);
                    }));
                    m_PreviewImage.Add(collapsePreviewButton);
                }
                m_PreviewContainer.Add(m_PreviewImage);

                // Hook up preview image to preview manager
                m_PreviewRenderData = previewManager.GetPreview(inNode);
                m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture;
                UpdatePreviewTexture();

                // Add fake preview which pads out the node to provide space for the floating preview
                m_PreviewFiller = new VisualElement {
                    name = "previewFiller"
                };
                m_PreviewFiller.AddToClassList("expanded");
                {
                    var previewDivider = new VisualElement {
                        name = "divider"
                    };
                    previewDivider.AddToClassList("horizontal");
                    m_PreviewFiller.Add(previewDivider);

                    var expandPreviewButton = new VisualElement {
                        name = "expand"
                    };
                    expandPreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    expandPreviewButton.AddManipulator(new Clickable(() =>
                    {
                        node.owner.owner.RegisterCompleteObjectUndo("Expand Preview");
                        UpdatePreviewExpandedState(true);
                    }));
                    m_PreviewFiller.Add(expandPreviewButton);
                }
                contents.Add(m_PreviewFiller);

                UpdatePreviewExpandedState(node.previewExpanded);
            }

            // 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 <MaterialSlot>());
            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 PreviewNode)
             * {
             *  var resizeHandle = new Label { name = "resize", text = "" };
             *  resizeHandle.AddManipulator(new Draggable(OnResize));
             *  Add(resizeHandle);
             *  UpdateSize();
             * }*/

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

            m_PortInputContainer.SendToBack();
            if (node.hasPreview)
            {
                m_PreviewFiller.BringToFront();
            }
        }
Пример #25
0
        public void Initialize(AbstractLogicNodeEditor logicNodeEditor, IEdgeConnectorListener connectorListener)
        {
            this.LoadAndAddStyleSheet("Styles/LogicNodeView");

            if (logicNodeEditor is IInputNode)
            {
                AddToClassList("input");
            }
            else if (logicNodeEditor is IOutputNode)
            {
                AddToClassList("output");
            }

            _connectorListener = connectorListener;
            LogicNodeEditor    = logicNodeEditor;
            title = LogicNodeEditor.NodeType();

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

            var controlsContainer = new VisualElement {
                name = "controls"
            };

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

                foreach (var propertyInfo in
                         logicNodeEditor.GetType().GetProperties(BindingFlags.Instance |
                                                                 BindingFlags.Public |
                                                                 BindingFlags.NonPublic))
                {
                    foreach (INodeControlAttribute attribute in
                             propertyInfo.GetCustomAttributes(typeof(INodeControlAttribute), false))
                    {
                        _controlItems.Add(attribute.InstantiateControl(logicNodeEditor, propertyInfo));
                    }
                }
            }
            contents.Add(controlsContainer);

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

            List <LogicSlot> foundSlots = new List <LogicSlot>();

            logicNodeEditor.GetSlots(foundSlots);
            AddPorts(foundSlots);

            SetPosition(new Rect(logicNodeEditor.Position.x, logicNodeEditor.Position.y, 0, 0));
            UpdatePortInputs();
            base.expanded = logicNodeEditor.Expanded;
            RefreshExpandedState();
            UpdatePortInputVisibilities();
        }
Пример #26
0
        public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManager, IEdgeConnectorListener connectorListener, MaterialGraphView graphView)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/MaterialNodeView"));
            styleSheets.Add(Resources.Load <StyleSheet>($"Styles/ColorMode"));
            AddToClassList("MaterialNode");

            if (inNode == null)
            {
                return;
            }

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

            m_GraphView = graphView;
            mainContainer.style.overflow = StyleKeyword.None;    // Override explicit style set in base class
            m_ConnectorListener          = connectorListener;
            node        = inNode;
            viewDataKey = node.objectId;
            UpdateTitle();

            // Add disabled overlay
            Add(new VisualElement()
            {
                name = "disabledOverlay", pickingMode = PickingMode.Ignore
            });

            // 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))
                    {
                        m_ControlItems.Add(attribute.InstantiateControl(node, propertyInfo));
                    }
                }
            }
            if (m_ControlItems.childCount > 0)
            {
                contents.Add(controlsContainer);
            }

            // Add dropdowns container
            var dropdownContainer = new VisualElement {
                name = "dropdowns"
            };

            {
                m_DropdownsDivider = new VisualElement {
                    name = "divider"
                };
                m_DropdownsDivider.AddToClassList("horizontal");
                dropdownContainer.Add(m_DropdownsDivider);
                m_DropdownItems = new VisualElement {
                    name = "items"
                };
                dropdownContainer.Add(m_DropdownItems);
                UpdateDropdownEntries();
            }
            if (m_DropdownItems.childCount > 0)
            {
                contents.Add(dropdownContainer);
            }

            if (node.hasPreview)
            {
                // Add actual preview which floats on top of the node
                m_PreviewContainer = new VisualElement
                {
                    name        = "previewContainer",
                    style       = { overflow = Overflow.Hidden },
                    pickingMode = PickingMode.Ignore
                };
                m_PreviewImage = new Image
                {
                    name        = "preview",
                    pickingMode = PickingMode.Ignore,
                    image       = Texture2D.whiteTexture,
                };
                {
                    // Add preview collapse button on top of preview
                    var collapsePreviewButton = new VisualElement {
                        name = "collapse"
                    };
                    collapsePreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    collapsePreviewButton.AddManipulator(new Clickable(() =>
                    {
                        SetPreviewExpandedStateOnSelection(false);
                    }));
                    m_PreviewImage.Add(collapsePreviewButton);
                }
                m_PreviewContainer.Add(m_PreviewImage);

                // Hook up preview image to preview manager
                m_PreviewRenderData = previewManager.GetPreviewRenderData(inNode);
                m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture;
                UpdatePreviewTexture();

                // Add fake preview which pads out the node to provide space for the floating preview
                m_PreviewFiller = new VisualElement {
                    name = "previewFiller"
                };
                m_PreviewFiller.AddToClassList("expanded");
                {
                    var previewDivider = new VisualElement {
                        name = "divider"
                    };
                    previewDivider.AddToClassList("horizontal");
                    m_PreviewFiller.Add(previewDivider);

                    var expandPreviewButton = new VisualElement {
                        name = "expand"
                    };
                    expandPreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    expandPreviewButton.AddManipulator(new Clickable(() =>
                    {
                        SetPreviewExpandedStateOnSelection(true);
                    }));
                    m_PreviewFiller.Add(expandPreviewButton);
                }
                contents.Add(m_PreviewFiller);

                UpdatePreviewExpandedState(node.previewExpanded);
            }

            base.expanded = node.drawState.expanded;
            AddSlots(node.GetSlots <MaterialSlot>());

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

            m_TitleContainer = this.Q("title");

            if (node is BlockNode blockData)
            {
                AddToClassList("blockData");
                m_TitleContainer.RemoveFromHierarchy();
            }
            else
            {
                SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));
            }

            // Update active state
            SetActive(node.isActive);

            // Register OnMouseHover callbacks for node highlighting
            RegisterCallback <MouseEnterEvent>(OnMouseHover);
            RegisterCallback <MouseLeaveEvent>(OnMouseHover);

            ShaderGraphPreferences.onAllowDeprecatedChanged += UpdateTitle;
        }
        public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManager, IEdgeConnectorListener connectorListener)
        {
            AddStyleSheetPath("Styles/MaterialNodeView");
            AddToClassList("MaterialNode");

            if (inNode == null)
            {
                return;
            }

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

            m_ConnectorListener = connectorListener;
            node           = inNode;
            persistenceKey = node.guid.ToString();
            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))
                    {
                        m_ControlItems.Add(attribute.InstantiateControl(node, propertyInfo));
                    }
                }
            }
            if (m_ControlItems.childCount > 0)
            {
                contents.Add(controlsContainer);
            }

            if (node.hasPreview)
            {
                // Add actual preview which floats on top of the node
                m_PreviewContainer = new VisualElement
                {
                    name            = "previewContainer",
                    clippingOptions = ClippingOptions.ClipAndCacheContents,
                    pickingMode     = PickingMode.Ignore
                };
                m_PreviewImage = new Image
                {
                    name        = "preview",
                    pickingMode = PickingMode.Ignore,
                    image       = Texture2D.whiteTexture,
                };
                {
                    // Add preview collapse button on top of preview
                    var collapsePreviewButton = new VisualElement {
                        name = "collapse"
                    };
                    collapsePreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    collapsePreviewButton.AddManipulator(new Clickable(() =>
                    {
                        node.owner.owner.RegisterCompleteObjectUndo("Collapse Preview");
                        UpdatePreviewExpandedState(false);
                    }));
                    m_PreviewImage.Add(collapsePreviewButton);
                }
                m_PreviewContainer.Add(m_PreviewImage);

                // Hook up preview image to preview manager
                m_PreviewRenderData = previewManager.GetPreview(inNode);
                m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture;
                UpdatePreviewTexture();

                // Add fake preview which pads out the node to provide space for the floating preview
                m_PreviewFiller = new VisualElement {
                    name = "previewFiller"
                };
                m_PreviewFiller.AddToClassList("expanded");
                {
                    var previewDivider = new VisualElement {
                        name = "divider"
                    };
                    previewDivider.AddToClassList("horizontal");
                    m_PreviewFiller.Add(previewDivider);

                    var expandPreviewButton = new VisualElement {
                        name = "expand"
                    };
                    expandPreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    expandPreviewButton.AddManipulator(new Clickable(() =>
                    {
                        node.owner.owner.RegisterCompleteObjectUndo("Expand Preview");
                        UpdatePreviewExpandedState(true);
                    }));
                    m_PreviewFiller.Add(expandPreviewButton);
                }
                contents.Add(m_PreviewFiller);

                UpdatePreviewExpandedState(node.previewExpanded);
            }

            // 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 <MaterialSlot>());
            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);
            }

            var masterNode = node as IMasterNode;

            if (masterNode != null)
            {
                if (!masterNode.IsPipelineCompatible(RenderPipelineManager.currentPipeline))
                {
                    IconBadge wrongPipeline = IconBadge.CreateError("The current render pipeline is not compatible with this node preview.");
                    Add(wrongPipeline);
                    VisualElement title = this.Q("title");
                    wrongPipeline.AttachTo(title, SpriteAlignment.LeftCenter);
                }
            }

            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);
            }
        }
Пример #28
0
        public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManager, IEdgeConnectorListener connectorListener)
        {
            AddToClassList("MaterialNode");

            if (inNode == null)
            {
                return;
            }

            m_ConnectorListener = connectorListener;
            node           = inNode;
            persistenceKey = node.guid.ToString();
            UpdateTitle();

            m_ControlsContainer = new VisualElement
            {
                name = "controls"
            };
            extensionContainer.Add(m_ControlsContainer);
            m_ControlsDivider = new VisualElement {
                name = "divider"
            };
            m_ControlsDivider.AddToClassList("horizontal");

            if (node.hasPreview)
            {
                m_PreviewContainer = new VisualElement {
                    name = "previewContainer"
                };
                m_PreviewContainer.AddToClassList("expanded");
                {
                    m_PreviewTextureView = new PreviewTextureView
                    {
                        name        = "preview",
                        pickingMode = PickingMode.Ignore,
                        image       = Texture2D.whiteTexture
                    };
                    m_PreviewRenderData = previewManager.GetPreview(inNode);
                    m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture;
                    UpdatePreviewTexture();

                    var collapsePreviewButton = new VisualElement {
                        name = "collapse"
                    };
                    collapsePreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    collapsePreviewButton.AddManipulator(new Clickable(() =>
                    {
                        node.owner.owner.RegisterCompleteObjectUndo("Collapse Preview");
                        UpdatePreviewExpandedState(false);
                    }));
                    UpdatePreviewExpandedState(node.previewExpanded);
                    m_PreviewTextureView.Add(collapsePreviewButton);

                    var expandPreviewButton = new VisualElement {
                        name = "expand"
                    };
                    expandPreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    expandPreviewButton.AddManipulator(new Clickable(() =>
                    {
                        node.owner.owner.RegisterCompleteObjectUndo("Expand Preview");
                        UpdatePreviewExpandedState(true);
                    }));
                    m_PreviewContainer.Add(expandPreviewButton);
                }

                extensionContainer.Add(m_PreviewContainer);
            }

            m_ControlViews = new List <VisualElement>();
            foreach (var propertyInfo in node.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                foreach (IControlAttribute attribute in propertyInfo.GetCustomAttributes(typeof(IControlAttribute), false))
                {
                    m_ControlViews.Add(attribute.InstantiateControl(node, propertyInfo));
                }
            }
            m_Attachers = new List <Attacher>(node.GetInputSlots <MaterialSlot>().Count());

            AddSlots(node.GetSlots <MaterialSlot>());
            UpdateSlotAttachers();
            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));
            UpdateControls();

            if (node is PreviewNode)
            {
                var resizeHandle = new Label {
                    name = "resize", text = ""
                };
                resizeHandle.AddManipulator(new Draggable(OnResize));
                Add(resizeHandle);
                UpdateSize();
            }
        }
Пример #29
0
 public BaseEdgeConnector(IEdgeConnectorListener listener) : base()
 {
     graphView = (listener as BaseEdgeConnectorListener)?.graphView;
     active    = false;
     InitEdgeConnector(listener);
 }
Пример #30
0
        public void Initialize(AbstractMaterialNode inNode, PreviewManager previewManager, IEdgeConnectorListener connectorListener, MaterialGraphView graphView)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/MaterialNodeView"));
            styleSheets.Add(Resources.Load <StyleSheet>($"Styles/ColorMode"));
            AddToClassList("MaterialNode");

            if (inNode == null)
            {
                return;
            }

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

            m_GraphView = graphView;
            mainContainer.style.overflow = StyleKeyword.None;    // Override explicit style set in base class
            m_ConnectorListener          = connectorListener;
            node        = inNode;
            viewDataKey = node.objectId;
            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))
                    {
                        m_ControlItems.Add(attribute.InstantiateControl(node, propertyInfo));
                    }
                }
            }
            if (m_ControlItems.childCount > 0)
            {
                contents.Add(controlsContainer);
            }

            if (node.hasPreview)
            {
                // Add actual preview which floats on top of the node
                m_PreviewContainer = new VisualElement
                {
                    name        = "previewContainer",
                    style       = { overflow = Overflow.Hidden },
                    pickingMode = PickingMode.Ignore
                };
                m_PreviewImage = new Image
                {
                    name        = "preview",
                    pickingMode = PickingMode.Ignore,
                    image       = Texture2D.whiteTexture,
                };
                {
                    // Add preview collapse button on top of preview
                    var collapsePreviewButton = new VisualElement {
                        name = "collapse"
                    };
                    collapsePreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    collapsePreviewButton.AddManipulator(new Clickable(() =>
                    {
                        SetPreviewExpandedStateOnSelection(false);
                    }));
                    m_PreviewImage.Add(collapsePreviewButton);
                }
                m_PreviewContainer.Add(m_PreviewImage);

                // Hook up preview image to preview manager
                m_PreviewRenderData = previewManager.GetPreviewRenderData(inNode);
                m_PreviewRenderData.onPreviewChanged += UpdatePreviewTexture;
                UpdatePreviewTexture();

                // Add fake preview which pads out the node to provide space for the floating preview
                m_PreviewFiller = new VisualElement {
                    name = "previewFiller"
                };
                m_PreviewFiller.AddToClassList("expanded");
                {
                    var previewDivider = new VisualElement {
                        name = "divider"
                    };
                    previewDivider.AddToClassList("horizontal");
                    m_PreviewFiller.Add(previewDivider);

                    var expandPreviewButton = new VisualElement {
                        name = "expand"
                    };
                    expandPreviewButton.Add(new VisualElement {
                        name = "icon"
                    });
                    expandPreviewButton.AddManipulator(new Clickable(() =>
                    {
                        SetPreviewExpandedStateOnSelection(true);
                    }));
                    m_PreviewFiller.Add(expandPreviewButton);
                }
                contents.Add(m_PreviewFiller);

                UpdatePreviewExpandedState(node.previewExpanded);
            }

            base.expanded = node.drawState.expanded;
            AddSlots(node.GetSlots <MaterialSlot>());

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

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

            m_TitleContainer = this.Q("title");

            if (node is IMasterNode)
            {
                AddToClassList("master");
                bool validTarget = false;
                foreach (Target activeTarget in node.owner.validTargets)
                {
                    //if we have a valid active target implementation and render pipeline, don't display the error
                    if (activeTarget.IsPipelineCompatible(GraphicsSettings.currentRenderPipeline))
                    {
                        validTarget = true;
                        break;
                    }
                }

                //if no active target implementations are valid with the current pipeline, display the error
                m_GraphView.graph.messageManager?.ClearAllFromProvider(this);
                if (!validTarget)
                {
                    m_GraphView.graph.messageManager?.AddOrAppendError(this, node.objectId,
                                                                       new ShaderMessage("The active Master Node is not compatible with the current Render Pipeline," +
                                                                                         " or no Render Pipeline is assigned." +
                                                                                         " Assign a Render Pipeline in the graphics settings that is compatible with this Master Node.",
                                                                                         ShaderCompilerMessageSeverity.Error));
                }
            }

            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 = new VisualElement();
            AddDefaultSettings();

            // Add Node type specific settings
            var nodeTypeSettings = node as IHasSettings;

            if (nodeTypeSettings != null)
            {
                m_Settings.Add(nodeTypeSettings.CreateSettingsElement());
            }

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

            if (m_Settings.childCount > 0)
            {
                m_ButtonContainer = new VisualElement {
                    name = "button-container"
                };
                m_ButtonContainer.style.flexDirection = FlexDirection.Row;
                m_ButtonContainer.Add(m_SettingsButton);
                m_ButtonContainer.Add(m_CollapseButton);
                m_TitleContainer.Add(m_ButtonContainer);
            }

            // Register OnMouseHover callbacks for node highlighting
            RegisterCallback <MouseEnterEvent>(OnMouseHover);
            RegisterCallback <MouseLeaveEvent>(OnMouseHover);
        }