Exemplo n.º 1
0
        void OnBlackboardDataRenamed(string _oldName, string _newName)
        {
            BlackboardRow blackboardRow = fields[_oldName];

            (blackboardRow.Q(className: "blackboardField") as BlackboardField).text = _newName;
            fields.Remove(_oldName);
            fields[_newName] = blackboardRow;
            MarkDirtyRepaint();
        }
Exemplo n.º 2
0
        void AddInputRow(ShaderInput input, bool addToGraph = false, int index = -1)
        {
            if (m_InputRows.ContainsKey(input))
            {
                return;
            }

            if (addToGraph)
            {
                m_Graph.owner.RegisterCompleteObjectUndo("Create Graph Input");

                // this pathway is mostly used for adding newly inputs to the graph
                // so this is setting up the default state for those inputs
                // here we flag it exposed, if the input type is exposable
                input.generatePropertyBlock = input.isExposable;

                m_Graph.AddGraphInput(input);       // TODO: index after currently selected property
            }

            BlackboardFieldView field = null;
            BlackboardRow       row   = null;

            switch (input)
            {
            case AbstractShaderProperty property:
            {
                var icon = (m_Graph.isSubGraph || property.isExposed) ? exposedIcon : null;
                field = new BlackboardFieldView(m_Graph, property, icon, property.displayName, property.GetPropertyTypeString())
                {
                    userData = property
                };
                field.RegisterCallback <AttachToPanelEvent>(UpdateSelectionAfterUndoRedo);
                property.onBeforeVersionChange += (_) => m_Graph.owner.RegisterCompleteObjectUndo($"Change {property.displayName} Version");
                void UpdateField()
                {
                    field.typeText = property.GetPropertyTypeString();
                    field.InspectorUpdateTrigger();
                }

                property.onAfterVersionChange += UpdateField;
                row = new BlackboardRow(field, null);

                if (index < 0 || index > m_InputRows.Count)
                {
                    index = m_InputRows.Count;
                }

                if (index == m_InputRows.Count)
                {
                    m_PropertySection.Add(row);
                }
                else
                {
                    m_PropertySection.Insert(index, row);
                }

                break;
            }

            case ShaderKeyword keyword:
            {
                var icon = (m_Graph.isSubGraph || keyword.isExposed) ? exposedIcon : null;

                string typeText = keyword.keywordType.ToString() + " Keyword";
                typeText = keyword.isBuiltIn ? "Built-in " + typeText : typeText;

                field = new BlackboardFieldView(m_Graph, keyword, icon, keyword.displayName, typeText)
                {
                    userData = keyword
                };
                field.RegisterCallback <AttachToPanelEvent>(UpdateSelectionAfterUndoRedo);
                row = new BlackboardRow(field, null);

                if (index < 0 || index > m_InputRows.Count)
                {
                    index = m_InputRows.Count;
                }

                if (index == m_InputRows.Count)
                {
                    m_KeywordSection.Add(row);
                }
                else
                {
                    m_KeywordSection.Insert(index, row);
                }

                break;
            }

            default:

                throw new ArgumentOutOfRangeException();
            }

            field.RegisterCallback <MouseEnterEvent>(evt => OnMouseHover(evt, input));
            field.RegisterCallback <MouseLeaveEvent>(evt => OnMouseHover(evt, input));
            field.RegisterCallback <DragUpdatedEvent>(OnDragUpdatedEvent);
            // These callbacks are used for the property dragging scroll behavior
            field.RegisterCallback <DragEnterEvent>(evt => blackboard.ShowScrollBoundaryRegions());
            field.RegisterCallback <DragExitedEvent>(evt => blackboard.HideScrollBoundaryRegions());

            // Removing the expand button from the blackboard, its added by default
            var expandButton = row.Q <Button>("expandButton");

            expandButton.RemoveFromHierarchy();

            m_InputRows[input] = row;

            if (!addToGraph)
            {
                m_InputRows[input].expanded = SessionState.GetBool($"Unity.ShaderGraph.Input.{input.objectId}.isExpanded", false);
            }
            else
            {
                row.expanded = true;
                field.OpenTextEditor();
                if (input as ShaderKeyword != null)
                {
                    m_Graph.OnKeywordChangedNoValidate();
                }
            }
        }