Beispiel #1
0
        void AddProperty(AbstractShaderProperty property, bool create = false, int index = -1)
        {
            if (m_PropertyRows.ContainsKey(property.guid))
            {
                return;
            }

            if (create)
            {
                property.displayName = m_Graph.SanitizePropertyName(property.displayName);
            }

            var icon  = property.generatePropertyBlock ? exposedIcon : null;
            var field = new BlackboardField(icon, property.displayName, property.propertyType.ToString())
            {
                userData = property
            };

            var propertyView = new BlackboardFieldPropertyView(field, m_Graph, property);
            var row          = new BlackboardRow(field, propertyView);
            var pill         = row.Q <Pill>();

            pill.RegisterCallback <MouseEnterEvent>(evt => OnMouseHover(evt, property));
            pill.RegisterCallback <MouseLeaveEvent>(evt => OnMouseHover(evt, property));
            pill.RegisterCallback <DragUpdatedEvent>(OnDragUpdatedEvent);

            var expandButton = row.Q <Button>("expandButton");

            expandButton.RegisterCallback <MouseDownEvent>(evt => OnExpanded(evt, property), TrickleDown.TrickleDown);

            row.userData = property;
            if (index < 0)
            {
                index = m_PropertyRows.Count;
            }
            if (index == m_PropertyRows.Count)
            {
                m_Section.Add(row);
            }
            else
            {
                m_Section.Insert(index, row);
            }
            m_PropertyRows[property.guid] = row;

            m_PropertyRows[property.guid].expanded = SessionState.GetBool(property.guid.ToString(), true);

            if (create)
            {
                row.expanded = true;
                m_Graph.owner.RegisterCompleteObjectUndo("Create Property");
                m_Graph.AddShaderProperty(property);
                field.OpenTextEditor();
            }
        }
        void AddInputRow(ShaderInput input, bool create = false, int index = -1)
        {
            if (m_InputRows.ContainsKey(input))
            {
                return;
            }

            if (create)
            {
                m_Graph.SanitizeGraphInputName(input);
                input.generatePropertyBlock = input.isExposable;
            }

            BlackboardFieldView field = null;
            BlackboardRow       row   = null;

            switch (input)
            {
            case AbstractShaderProperty property:
            {
                var icon = (m_Graph.isSubGraph || (property.isExposable && property.generatePropertyBlock)) ? exposedIcon : null;
                field = new BlackboardFieldView(m_Graph, property, UpdateBlackboardView, 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.isExposable && keyword.generatePropertyBlock)) ? exposedIcon : null;

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

                field = new BlackboardFieldView(m_Graph, keyword, UpdateBlackboardView, 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);

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

            expandButton.RemoveFromHierarchy();

            m_InputRows[input] = row;

            if (!create)
            {
                m_InputRows[input].expanded = SessionState.GetBool($"Unity.ShaderGraph.Input.{input.objectId}.isExpanded", false);
            }
            else
            {
                row.expanded = true;
                m_Graph.owner.RegisterCompleteObjectUndo("Create Graph Input");
                m_Graph.AddGraphInput(input);
                field.OpenTextEditor();

                if (input as ShaderKeyword != null)
                {
                    m_Graph.OnKeywordChangedNoValidate();
                }
            }
        }
Beispiel #3
0
        void AddInputRow(ShaderInput input, bool create = false, int index = -1)
        {
            if (m_InputRows.ContainsKey(input.guid))
            {
                return;
            }

            if (create)
            {
                m_Graph.SanitizeGraphInputName(input);
            }

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

            BlackboardField field = null;
            BlackboardRow   row   = null;

            switch (input)
            {
            case AbstractShaderProperty property:
            {
                var icon = (m_Graph.isSubGraph || (property.isExposable && property.generatePropertyBlock)) ? exposedIcon : null;
                field = new BlackboardField(icon, property.displayName, property.propertyType.ToString())
                {
                    userData = property
                };
                var propertyView = new BlackboardFieldPropertyView(field, m_Graph, property);
                row = new BlackboardRow(field, propertyView)
                {
                    userData = input
                };
                if (index == m_PropertySection.childCount)
                {
                    m_PropertySection.Add(row);
                }
                else
                {
                    m_PropertySection.Insert(index, row);
                }
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (field == null || row == null)
            {
                return;
            }

            var pill = row.Q <Pill>();

            pill.RegisterCallback <MouseEnterEvent>(evt => OnMouseHover(evt, input));
            pill.RegisterCallback <MouseLeaveEvent>(evt => OnMouseHover(evt, input));
            pill.RegisterCallback <DragUpdatedEvent>(OnDragUpdatedEvent);

            var expandButton = row.Q <Button>("expandButton");

            expandButton.RegisterCallback <MouseDownEvent>(evt => OnExpanded(evt, input), TrickleDown.TrickleDown);

            m_InputRows[input.guid]          = row;
            m_InputRows[input.guid].expanded = SessionState.GetBool(input.guid.ToString(), true);

            if (create)
            {
                row.expanded = true;
                m_Graph.owner.RegisterCompleteObjectUndo("Create Graph Input");
                m_Graph.AddGraphInput(input);
                field.OpenTextEditor();
            }
        }
Beispiel #4
0
        void AddInputRow(ShaderInput input, bool create = false, int index = -1)
        {
            if (m_InputRows.ContainsKey(input.guid))
            {
                return;
            }

            if (create)
            {
                m_Graph.SanitizeGraphInputName(input);
                input.generatePropertyBlock = input.isExposable;
            }

            BlackboardField field = null;
            BlackboardRow   row   = null;

            switch (input)
            {
            case AbstractShaderProperty property:
            {
                var icon = (m_Graph.isSubGraph || (property.isExposable && property.generatePropertyBlock)) ? exposedIcon : null;
                field = new BlackboardField(icon, property.displayName, property.propertyType.ToString())
                {
                    userData = property
                };
                var propertyView = new BlackboardFieldPropertyView(field, m_Graph, property);
                row = new BlackboardRow(field, propertyView)
                {
                    userData = input
                };

                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.isExposable && keyword.generatePropertyBlock)) ? exposedIcon : null;

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

                field = new BlackboardField(icon, keyword.displayName, typeText)
                {
                    userData = keyword
                };
                var keywordView = new BlackboardFieldKeywordView(field, m_Graph, keyword);
                row = new BlackboardRow(field, keywordView);

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

            if (field == null || row == null)
            {
                return;
            }

            var pill = row.Q <Pill>();

            pill.RegisterCallback <MouseEnterEvent>(evt => OnMouseHover(evt, input));
            pill.RegisterCallback <MouseLeaveEvent>(evt => OnMouseHover(evt, input));
            pill.RegisterCallback <DragUpdatedEvent>(OnDragUpdatedEvent);

            var expandButton = row.Q <Button>("expandButton");

            expandButton.RegisterCallback <MouseDownEvent>(evt => OnExpanded(evt, input), TrickleDown.TrickleDown);

            m_InputRows[input.guid] = row;

            if (!create)
            {
                m_InputRows[input.guid].expanded = SessionState.GetBool($"Unity.ShaderGraph.Input.{input.guid.ToString()}.isExpanded", false);
            }
            else
            {
                row.expanded = true;
                m_ExpandedInputs[input.guid] = true;
                m_Graph.owner.RegisterCompleteObjectUndo("Create Graph Input");
                m_Graph.AddGraphInput(input);
                field.OpenTextEditor();

                if (input as ShaderKeyword != null)
                {
                    m_Graph.OnKeywordChangedNoValidate();
                }
            }
        }