Ejemplo n.º 1
0
        public BlackboardFieldView(GraphData graph,
                                   ShaderInput input,
                                   Texture icon,
                                   string text,
                                   string typeText) : base(icon, text, typeText)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/ShaderGraphBlackboard"));
            m_Graph   = graph;
            m_Input   = input;
            this.name = "blackboardFieldView";
            ShaderGraphPreferences.onAllowDeprecatedChanged += UpdateTypeText;

            // add the right click context menu
            IManipulator contextMenuManipulator = new ContextualMenuManipulator(AddContextMenuOptions);

            this.AddManipulator(contextMenuManipulator);

            var nameTextField = this.Q("textField") as TextField;
            var textinput     = nameTextField.Q(TextField.textInputUssName);

            // When a display name is changed through the BlackboardPill, this callback handle it
            textinput.RegisterCallback <FocusOutEvent>(e =>
            {
                this.RegisterPropertyChangeUndo("Change Display Name");

                if (nameTextField.text != m_Input.displayName)
                {
                    m_Input.SetDisplayNameAndSanitizeForGraph(m_Graph, nameTextField.text);
                }

                // This gets triggered on property creation so need to check for inspector update trigger being valid (which it might not be at the time)
                if (this.m_inspectorUpdateTrigger != null)
                {
                    this.MarkNodesAsDirty(true, ModificationScope.Topological);
                }
                else
                {
                    DirtyNodes(ModificationScope.Topological);
                }
            });

            m_NameLabelField = this.Q("title-label") as Label;

            // Set callback association for display name updates
            m_Input.displayNameUpdateTrigger += UpdateDisplayNameText;
        }
Ejemplo n.º 2
0
        public PropertyNodeView(PropertyNode node, EdgeConnectorListener edgeConnectorListener)
            : base(null, ShaderPort.Create(node.GetOutputSlots <MaterialSlot>().First(), edgeConnectorListener))
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNodeView"));
            this.node   = node;
            viewDataKey = node.objectId.ToString();
            userData    = node;

            // Getting the generatePropertyBlock property to see if it is exposed or not
            UpdateIcon();

            // Setting the position of the node, otherwise it ends up in the center of the canvas
            SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));

            // Removing the title label since it is not used and taking up space
            this.Q("title-label").RemoveFromHierarchy();

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

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

            // Registering the hovering callbacks for highlighting
            RegisterCallback <MouseEnterEvent>(OnMouseHover);
            RegisterCallback <MouseLeaveEvent>(OnMouseHover);

            // add the right click context menu
            IManipulator contextMenuManipulator = new ContextualMenuManipulator(AddContextMenuOptions);

            this.AddManipulator(contextMenuManipulator);

            // Set callback association for display name updates
            property.displayNameUpdateTrigger += node.UpdateNodeDisplayName;
        }