void AddProperty(IShaderProperty property, bool create = false, int index = -1)
        {
            if (m_PropertyRows.ContainsKey(property.guid))
            {
                return;
            }
            var field = new BlackboardField(m_ExposedIcon, property.displayName, property.propertyType.ToString())
            {
                userData = property
            };
            var row = new BlackboardRow(field, new BlackboardFieldPropertyView(m_Graph, property));

            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;

            if (create)
            {
                field.OpenTextEditor();
                row.expanded = true;
                m_Graph.owner.RegisterCompleteObjectUndo("Create Property");
                m_Graph.AddShaderProperty(property);
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 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();
            }
        }
Esempio n. 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();
                }
            }
        }