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.RenameGo();
                row.expanded = true;
                m_Graph.owner.RegisterCompleteObjectUndo("Create Property");
                m_Graph.AddShaderProperty(property);
            }
        }
示例#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();
            }
        }
 public BlackboardFieldKeywordView(BlackboardField blackboardField, GraphData graph, ShaderInput input)
     : base(blackboardField, graph, input)
 {
     greyLabel        = new GUIStyle(EditorStyles.label);
     greyLabel.normal = new GUIStyleState {
         textColor = Color.grey
     };
     greyLabel.focused = new GUIStyleState {
         textColor = Color.grey
     };
     greyLabel.hover = new GUIStyleState {
         textColor = Color.grey
     };
 }
示例#4
0
        public BlackboardFieldView(BlackboardField blackboardField, GraphData graph, ShaderInput input)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/ShaderGraphBlackboard"));
            m_BlackboardField = blackboardField;
            m_Graph           = graph;
            m_Input           = input;
            m_Rows            = new List <VisualElement>();

            m_KeyDownCallback = new EventCallback <KeyDownEvent>(evt =>
            {
                // Record Undo for input field edit
                if (m_UndoGroup == -1)
                {
                    m_UndoGroup = Undo.GetCurrentGroup();
                    graph.owner.RegisterCompleteObjectUndo("Change property value");
                }
                // Handle scaping input field edit
                if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
                {
                    Undo.RevertAllDownToGroup(m_UndoGroup);
                    m_UndoGroup = -1;
                    evt.StopPropagation();
                }
                // Dont record Undo again until input field is unfocused
                m_UndoGroup++;
                this.MarkDirtyRepaint();
            });

            m_FocusOutCallback = new EventCallback <FocusOutEvent>(evt =>
            {
                // Reset UndoGroup when done editing input field
                m_UndoGroup = -1;
            });

            BuildDefaultFields(input);
            BuildCustomFields(input);

            AddToClassList("sgblackboardFieldView");
        }
示例#5
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();
            }
        }
示例#6
0
 public BlackboardFieldKeywordView(BlackboardField blackboardField, GraphData graph, ShaderInput input)
     : base(blackboardField, graph, input)
 {
 }
        public BlackboardFieldPropertyView(BlackboardField blackboardField, GraphData graph, AbstractShaderProperty property)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/ShaderGraphBlackboard"));
            m_BlackboardField = blackboardField;
            m_Graph           = graph;
            m_Property        = property;

            if (!m_Graph.isSubGraph)
            {
                if (property.isExposable)
                {
                    m_ExposedToogle = new Toggle();
                    m_ExposedToogle.OnToggleChanged(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Exposed Toggle");
                        if (m_OnExposedToggle != null)
                        {
                            m_OnExposedToggle();
                        }
                        property.generatePropertyBlock = evt.newValue;
                        if (property.generatePropertyBlock)
                        {
                            m_BlackboardField.icon = BlackboardProvider.exposedIcon;
                        }
                        else
                        {
                            m_BlackboardField.icon = null;
                        }
                        DirtyNodes(ModificationScope.Graph);
                    });
                    m_ExposedToogle.value = property.generatePropertyBlock;
                    AddRow("Exposed", m_ExposedToogle);
                }

                if (property.isExposable)
                {
                    m_ReferenceNameField = new TextField(512, false, false, ' ');
                    m_ReferenceNameField.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNameReferenceField"));
                    AddRow("Reference", m_ReferenceNameField);
                    m_ReferenceNameField.value     = property.referenceName;
                    m_ReferenceNameField.isDelayed = true;
                    m_ReferenceNameField.RegisterValueChangedCallback(newName =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Reference Name");
                        if (m_ReferenceNameField.value != m_Property.referenceName)
                        {
                            string newReferenceName        = m_Graph.SanitizePropertyReferenceName(newName.newValue, property.guid);
                            property.overrideReferenceName = newReferenceName;
                        }
                        m_ReferenceNameField.value = property.referenceName;

                        if (string.IsNullOrEmpty(property.overrideReferenceName))
                        {
                            m_ReferenceNameField.RemoveFromClassList("modified");
                        }
                        else
                        {
                            m_ReferenceNameField.AddToClassList("modified");
                        }

                        DirtyNodes(ModificationScope.Graph);
                        UpdateReferenceNameResetMenu();
                    });

                    if (!string.IsNullOrEmpty(property.overrideReferenceName))
                    {
                        m_ReferenceNameField.AddToClassList("modified");
                    }
                }
            }

            // Key Undo callbacks for input fields
            EventCallback <KeyDownEvent> keyDownCallback = new EventCallback <KeyDownEvent>(evt =>
            {
                // Record Undo for input field edit
                if (m_UndoGroup == -1)
                {
                    m_UndoGroup = Undo.GetCurrentGroup();
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                }
                // Handle scaping input field edit
                if (evt.keyCode == KeyCode.Escape && m_UndoGroup > -1)
                {
                    Undo.RevertAllDownToGroup(m_UndoGroup);
                    m_UndoGroup = -1;
                    evt.StopPropagation();
                }
                // Dont record Undo again until input field is unfocused
                m_UndoGroup++;
                this.MarkDirtyRepaint();
            });
            EventCallback <FocusOutEvent> focusOutCallback = new EventCallback <FocusOutEvent>(evt =>
            {
                // Reset UndoGroup when done editing input field
                m_UndoGroup = -1;
            });

            if (property is Vector1ShaderProperty)
            {
                var floatProperty = (Vector1ShaderProperty)property;
                BuildVector1PropertyView(floatProperty);
            }
            else if (property is Vector2ShaderProperty)
            {
                var vectorProperty = (Vector2ShaderProperty)property;
                var field          = new Vector2Field {
                    value = vectorProperty.value
                };

                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);

                // Called after KeyDownEvent
                field.RegisterValueChangedCallback(evt =>
                {
                    // Only true when setting value via FieldMouseDragger
                    // Undo recorded once per dragger release
                    if (m_UndoGroup == -1)
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    }
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector3ShaderProperty)
            {
                var vectorProperty = (Vector3ShaderProperty)property;
                var field          = new Vector3Field {
                    value = vectorProperty.value
                };

                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-z-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-z-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);

                // Called after KeyDownEvent
                field.RegisterValueChangedCallback(evt =>
                {
                    // Only true when setting value via FieldMouseDragger
                    // Undo recorded once per dragger release
                    if (m_UndoGroup == -1)
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    }
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector4ShaderProperty)
            {
                var vectorProperty = (Vector4ShaderProperty)property;
                var field          = new Vector4Field {
                    value = vectorProperty.value
                };

                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-x-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-y-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-z-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-z-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);
                field.Q("unity-w-input").Q("unity-text-input").RegisterCallback <KeyDownEvent>(keyDownCallback);
                field.Q("unity-w-input").Q("unity-text-input").RegisterCallback <FocusOutEvent>(focusOutCallback);

                // Called after KeyDownEvent
                field.RegisterValueChangedCallback(evt =>
                {
                    // Only true when setting value via FieldMouseDragger
                    // Undo recorded once per dragger release
                    if (m_UndoGroup == -1)
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    }
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ColorShaderProperty)
            {
                var colorProperty = (ColorShaderProperty)property;
                var colorField    = new ColorField {
                    value = property.defaultValue, showEyeDropper = false, hdr = colorProperty.colorMode == ColorMode.HDR
                };
                colorField.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    colorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", colorField);
                if (!m_Graph.isSubGraph)
                {
                    var colorModeField = new EnumField((Enum)colorProperty.colorMode);
                    colorModeField.RegisterValueChangedCallback(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Color Mode");
                        if (colorProperty.colorMode == (ColorMode)evt.newValue)
                        {
                            return;
                        }
                        colorProperty.colorMode = (ColorMode)evt.newValue;
                        colorField.hdr          = colorProperty.colorMode == ColorMode.HDR;
                        colorField.MarkDirtyRepaint();
                        DirtyNodes();
                    });
                    AddRow("Mode", colorModeField);
                }
            }
            else if (property is TextureShaderProperty)
            {
                var textureProperty = (TextureShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    textureProperty.value.texture = (Texture)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
                if (!m_Graph.isSubGraph)
                {
                    var defaultModeField = new EnumField((Enum)textureProperty.defaultType);
                    defaultModeField.RegisterValueChangedCallback(evt =>
                    {
                        m_Graph.owner.RegisterCompleteObjectUndo("Change Texture Mode");
                        if (textureProperty.defaultType == (TextureShaderProperty.DefaultType)evt.newValue)
                        {
                            return;
                        }
                        textureProperty.defaultType = (TextureShaderProperty.DefaultType)evt.newValue;
                        DirtyNodes(ModificationScope.Graph);
                    });
                    void ToggleDefaultModeFieldEnabled()
                    {
                        defaultModeField.SetEnabled(!defaultModeField.enabledSelf);
                    }

                    m_OnExposedToggle += ToggleDefaultModeFieldEnabled;
                    AddRow("Mode", defaultModeField);
                }
            }
            else if (property is Texture2DArrayShaderProperty)
            {
                var textureProperty = (Texture2DArrayShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.textureArray, objectType = typeof(Texture2DArray)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    textureProperty.value.textureArray = (Texture2DArray)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Texture3DShaderProperty)
            {
                var textureProperty = (Texture3DShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture3D)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    textureProperty.value.texture = (Texture3D)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is CubemapShaderProperty)
            {
                var cubemapProperty = (CubemapShaderProperty)property;
                var field           = new ObjectField {
                    value = cubemapProperty.value.cubemap, objectType = typeof(Cubemap)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    cubemapProperty.value.cubemap = (Cubemap)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is BooleanShaderProperty)
            {
                var booleanProperty = (BooleanShaderProperty)property;
                EventCallback <ChangeEvent <bool> > onBooleanChanged = evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    booleanProperty.value = evt.newValue;
                    DirtyNodes();
                };
                var field = new Toggle();
                field.OnToggleChanged(onBooleanChanged);
                field.value = booleanProperty.value;
                AddRow("Default", field);
            }
            else if (property is Matrix2ShaderProperty)
            {
                var matrix2Property = (Matrix2ShaderProperty)property;
                var row0Field       = new Vector2Field {
                    value = matrix2Property.value.GetRow(0)
                };
                row0Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector2 row1          = matrix2Property.value.GetRow(1);
                    matrix2Property.value = new Matrix4x4()
                    {
                        m00 = evt.newValue.x,
                        m01 = evt.newValue.y,
                        m02 = 0,
                        m03 = 0,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = 0,
                        m13 = 0,
                        m20 = 0,
                        m21 = 0,
                        m22 = 0,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("Default", row0Field);
                var row1Field = new Vector2Field {
                    value = matrix2Property.value.GetRow(1)
                };
                row1Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector2 row0          = matrix2Property.value.GetRow(0);
                    matrix2Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = 0,
                        m03 = 0,
                        m10 = evt.newValue.x,
                        m11 = evt.newValue.y,
                        m12 = 0,
                        m13 = 0,
                        m20 = 0,
                        m21 = 0,
                        m22 = 0,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("", row1Field);
            }
            else if (property is Matrix3ShaderProperty)
            {
                var matrix3Property = (Matrix3ShaderProperty)property;
                var row0Field       = new Vector3Field {
                    value = matrix3Property.value.GetRow(0)
                };
                row0Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector3 row1          = matrix3Property.value.GetRow(1);
                    Vector3 row2          = matrix3Property.value.GetRow(2);
                    matrix3Property.value = new Matrix4x4()
                    {
                        m00 = evt.newValue.x,
                        m01 = evt.newValue.y,
                        m02 = evt.newValue.z,
                        m03 = 0,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = 0,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("Default", row0Field);
                var row1Field = new Vector3Field {
                    value = matrix3Property.value.GetRow(1)
                };
                row1Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector3 row0          = matrix3Property.value.GetRow(0);
                    Vector3 row2          = matrix3Property.value.GetRow(2);
                    matrix3Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = 0,
                        m10 = evt.newValue.x,
                        m11 = evt.newValue.y,
                        m12 = evt.newValue.z,
                        m13 = 0,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("", row1Field);
                var row2Field = new Vector3Field {
                    value = matrix3Property.value.GetRow(2)
                };
                row2Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector3 row0          = matrix3Property.value.GetRow(0);
                    Vector3 row1          = matrix3Property.value.GetRow(1);
                    matrix3Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = 0,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = 0,
                        m20 = evt.newValue.x,
                        m21 = evt.newValue.y,
                        m22 = evt.newValue.z,
                        m23 = 0,
                        m30 = 0,
                        m31 = 0,
                        m32 = 0,
                        m33 = 0,
                    };
                    DirtyNodes();
                });
                AddRow("", row2Field);
            }
            else if (property is Matrix4ShaderProperty)
            {
                var matrix4Property = (Matrix4ShaderProperty)property;
                var row0Field       = new Vector4Field {
                    value = matrix4Property.value.GetRow(0)
                };
                row0Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector4 row1          = matrix4Property.value.GetRow(1);
                    Vector4 row2          = matrix4Property.value.GetRow(2);
                    Vector4 row3          = matrix4Property.value.GetRow(3);
                    matrix4Property.value = new Matrix4x4()
                    {
                        m00 = evt.newValue.x,
                        m01 = evt.newValue.y,
                        m02 = evt.newValue.z,
                        m03 = evt.newValue.w,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = row1.w,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = row2.w,
                        m30 = row3.x,
                        m31 = row3.y,
                        m32 = row3.z,
                        m33 = row3.w,
                    };
                    DirtyNodes();
                });
                AddRow("Default", row0Field);
                var row1Field = new Vector4Field {
                    value = matrix4Property.value.GetRow(1)
                };
                row1Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector4 row0          = matrix4Property.value.GetRow(0);
                    Vector4 row2          = matrix4Property.value.GetRow(2);
                    Vector4 row3          = matrix4Property.value.GetRow(3);
                    matrix4Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = row0.w,
                        m10 = evt.newValue.x,
                        m11 = evt.newValue.y,
                        m12 = evt.newValue.z,
                        m13 = evt.newValue.w,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = row2.w,
                        m30 = row3.x,
                        m31 = row3.y,
                        m32 = row3.z,
                        m33 = row3.w,
                    };
                    DirtyNodes();
                });
                AddRow("", row1Field);
                var row2Field = new Vector4Field {
                    value = matrix4Property.value.GetRow(2)
                };
                row2Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector4 row0          = matrix4Property.value.GetRow(0);
                    Vector4 row1          = matrix4Property.value.GetRow(1);
                    Vector4 row3          = matrix4Property.value.GetRow(3);
                    matrix4Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = row0.w,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = row1.w,
                        m20 = evt.newValue.x,
                        m21 = evt.newValue.y,
                        m22 = evt.newValue.z,
                        m23 = evt.newValue.w,
                        m30 = row3.x,
                        m31 = row3.y,
                        m32 = row3.z,
                        m33 = row3.w,
                    };
                    DirtyNodes();
                });
                AddRow("", row2Field);
                var row3Field = new Vector4Field {
                    value = matrix4Property.value.GetRow(3)
                };
                row3Field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    Vector4 row0          = matrix4Property.value.GetRow(0);
                    Vector4 row1          = matrix4Property.value.GetRow(1);
                    Vector4 row2          = matrix4Property.value.GetRow(2);
                    matrix4Property.value = new Matrix4x4()
                    {
                        m00 = row0.x,
                        m01 = row0.y,
                        m02 = row0.z,
                        m03 = row0.w,
                        m10 = row1.x,
                        m11 = row1.y,
                        m12 = row1.z,
                        m13 = row1.w,
                        m20 = row2.x,
                        m21 = row2.y,
                        m22 = row2.z,
                        m23 = row2.w,
                        m30 = evt.newValue.x,
                        m31 = evt.newValue.y,
                        m32 = evt.newValue.z,
                        m33 = evt.newValue.w,
                    };
                    DirtyNodes();
                });
                AddRow("", row3Field);
            }
            else if (property is SamplerStateShaderProperty)
            {
                var samplerStateProperty = (SamplerStateShaderProperty)property;
                var filterField          = new EnumField(samplerStateProperty.value.filter);
                filterField.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    TextureSamplerState state = samplerStateProperty.value;
                    state.filter = (TextureSamplerState.FilterMode)evt.newValue;
                    samplerStateProperty.value = state;
                    DirtyNodes(ModificationScope.Graph);
                });
                AddRow("Filter", filterField);
                var wrapField = new EnumField(samplerStateProperty.value.wrap);
                wrapField.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    TextureSamplerState state = samplerStateProperty.value;
                    state.wrap = (TextureSamplerState.WrapMode)evt.newValue;
                    samplerStateProperty.value = state;
                    DirtyNodes(ModificationScope.Graph);
                });
                AddRow("Wrap", wrapField);
            }
            else if (property is GradientShaderProperty)
            {
                var gradientProperty = (GradientShaderProperty)property;
                var field            = new GradientField {
                    value = gradientProperty.value
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                    gradientProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }

            var precisionField = new EnumField((Enum)property.precision);

            precisionField.RegisterValueChangedCallback(evt =>
            {
                m_Graph.owner.RegisterCompleteObjectUndo("Change Precision");
                if (property.precision == (Precision)evt.newValue)
                {
                    return;
                }
                property.precision = (Precision)evt.newValue;
                m_Graph.ValidateGraph();
                precisionField.MarkDirtyRepaint();
                DirtyNodes();
            });
            AddRow("Precision", precisionField);

            AddToClassList("sgblackboardFieldPropertyView");

            UpdateReferenceNameResetMenu();
        }
 public BlackboardFieldPropertyView(BlackboardField blackboardField, GraphData graph, ShaderInput input)
     : base(blackboardField, graph, input)
 {
 }
示例#9
0
 public static void OpenTextEditor(this BlackboardField field)
 {
     field.RenameGo();
 }
示例#10
0
        public BlackboardFieldPropertyView(BlackboardField blackboardField, AbstractMaterialGraph graph, IShaderProperty property)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/ShaderGraphBlackboard"));
            m_BlackboardField = blackboardField;
            m_Graph           = graph;
            m_Property        = property;

            m_ExposedToogle = new Toggle();
            m_ExposedToogle.OnToggleChanged(evt =>
            {
                property.generatePropertyBlock = evt.newValue;
                if (property.generatePropertyBlock)
                {
                    m_BlackboardField.icon = BlackboardProvider.exposedIcon;
                }
                else
                {
                    m_BlackboardField.icon = null;
                }
                DirtyNodes(ModificationScope.Graph);
            });
            m_ExposedToogle.value = property.generatePropertyBlock;
            AddRow("Exposed", m_ExposedToogle);

            m_ReferenceNameField = new TextField(512, false, false, ' ');
            m_ReferenceNameField.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNameReferenceField"));
            AddRow("Reference", m_ReferenceNameField);
            m_ReferenceNameField.value     = property.referenceName;
            m_ReferenceNameField.isDelayed = true;
            m_ReferenceNameField.RegisterValueChangedCallback(newName =>
            {
                if (m_ReferenceNameField.value != m_Property.referenceName)
                {
                    string newReferenceName        = m_Graph.SanitizePropertyReferenceName(newName.newValue, property.guid);
                    property.overrideReferenceName = newReferenceName;
                }
                m_ReferenceNameField.value = property.referenceName;

                if (string.IsNullOrEmpty(property.overrideReferenceName))
                {
                    m_ReferenceNameField.RemoveFromClassList("modified");
                }
                else
                {
                    m_ReferenceNameField.AddToClassList("modified");
                }

                DirtyNodes(ModificationScope.Graph);
                UpdateReferenceNameResetMenu();
            });

            if (!string.IsNullOrEmpty(property.overrideReferenceName))
            {
                m_ReferenceNameField.AddToClassList("modified");
            }

            if (property is Vector1ShaderProperty)
            {
                VisualElement floatRow   = new VisualElement();
                VisualElement intRow     = new VisualElement();
                VisualElement modeRow    = new VisualElement();
                VisualElement minRow     = new VisualElement();
                VisualElement maxRow     = new VisualElement();
                FloatField    floatField = null;

                var floatProperty = (Vector1ShaderProperty)property;

                if (floatProperty.floatType == FloatType.Integer)
                {
                    var field = new IntegerField {
                        value = (int)floatProperty.value
                    };
                    field.RegisterValueChangedCallback(intEvt =>
                    {
                        floatProperty.value = (float)intEvt.newValue;
                        DirtyNodes();
                    });
                    intRow = AddRow("Default", field);
                }
                else
                {
                    floatField = new FloatField {
                        value = floatProperty.value
                    };
                    floatField.RegisterValueChangedCallback(evt =>
                    {
                        floatProperty.value = (float)evt.newValue;
                        DirtyNodes();
                    });
                    floatRow = AddRow("Default", floatField);
                }

                var floatModeField = new EnumField((Enum)floatProperty.floatType);
                floatModeField.value = floatProperty.floatType;
                floatModeField.RegisterValueChangedCallback(evt =>
                {
                    if (floatProperty.floatType == (FloatType)evt.newValue)
                    {
                        return;
                    }
                    floatProperty           = (Vector1ShaderProperty)property;
                    floatProperty.floatType = (FloatType)evt.newValue;
                    switch (floatProperty.floatType)
                    {
                    case FloatType.Slider:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        var field = new FloatField {
                            value = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x)
                        };
                        floatProperty.value = (float)field.value;
                        field.RegisterValueChangedCallback(defaultEvt =>
                        {
                            floatProperty.value = Mathf.Max(Mathf.Min((float)defaultEvt.newValue, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                            field.value         = floatProperty.value;
                            DirtyNodes();
                        });
                        floatRow     = AddRow("Default", field);
                        field.value  = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        modeRow      = AddRow("Mode", floatModeField);
                        var minField = new FloatField {
                            value = floatProperty.rangeValues.x
                        };
                        minField.RegisterValueChangedCallback(minEvt =>
                        {
                            floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y);
                            floatProperty.value       = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                            field.value = floatProperty.value;
                            DirtyNodes();
                        });
                        minRow       = AddRow("Min", minField);
                        var maxField = new FloatField {
                            value = floatProperty.rangeValues.y
                        };
                        maxField.RegisterValueChangedCallback(maxEvt =>
                        {
                            floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue);
                            floatProperty.value       = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                            field.value = floatProperty.value;
                            DirtyNodes();
                        });
                        maxRow = AddRow("Max", maxField);
                        break;

                    case FloatType.Integer:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        var intField = new IntegerField {
                            value = (int)floatProperty.value
                        };
                        intField.RegisterValueChangedCallback(intEvt =>
                        {
                            floatProperty.value = (float)intEvt.newValue;
                            DirtyNodes();
                        });
                        intRow  = AddRow("Default", intField);
                        modeRow = AddRow("Mode", floatModeField);
                        break;

                    default:
                        RemoveElements(new VisualElement[] { floatRow, intRow, modeRow, minRow, maxRow });
                        field = new FloatField {
                            value = floatProperty.value
                        };
                        field.RegisterValueChangedCallback(defaultEvt =>
                        {
                            floatProperty.value = (float)defaultEvt.newValue;
                            DirtyNodes();
                        });
                        floatRow = AddRow("Default", field);
                        modeRow  = AddRow("Mode", floatModeField);
                        break;
                    }
                    DirtyNodes();
                });
                modeRow = AddRow("Mode", floatModeField);

                if (floatProperty.floatType == FloatType.Slider)
                {
                    var minField = new FloatField {
                        value = floatProperty.rangeValues.x
                    };
                    minField.RegisterValueChangedCallback(minEvt =>
                    {
                        floatProperty.rangeValues = new Vector2((float)minEvt.newValue, floatProperty.rangeValues.y);
                        floatProperty.value       = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        floatField.value          = floatProperty.value;
                        DirtyNodes();
                    });
                    minRow = AddRow("Min", minField);
                    var maxField = new FloatField {
                        value = floatProperty.rangeValues.y
                    };
                    maxField.RegisterValueChangedCallback(maxEvt =>
                    {
                        floatProperty.rangeValues = new Vector2(floatProperty.rangeValues.x, (float)maxEvt.newValue);
                        floatProperty.value       = Mathf.Max(Mathf.Min(floatProperty.value, floatProperty.rangeValues.y), floatProperty.rangeValues.x);
                        floatField.value          = floatProperty.value;
                        DirtyNodes();
                    });
                    maxRow = AddRow("Max", maxField);
                }
            }
            else if (property is Vector2ShaderProperty)
            {
                var vectorProperty = (Vector2ShaderProperty)property;
                var field          = new Vector2Field {
                    value = vectorProperty.value
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector3ShaderProperty)
            {
                var vectorProperty = (Vector3ShaderProperty)property;
                var field          = new Vector3Field {
                    value = vectorProperty.value
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector4ShaderProperty)
            {
                var vectorProperty = (Vector4ShaderProperty)property;
                var field          = new Vector4Field {
                    value = vectorProperty.value
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ColorShaderProperty)
            {
                var colorProperty = (ColorShaderProperty)property;
                var colorField    = new ColorField {
                    value = property.defaultValue, showEyeDropper = false, hdr = colorProperty.colorMode == ColorMode.HDR
                };
                colorField.RegisterValueChangedCallback(evt =>
                {
                    colorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", colorField);
                var colorModeField = new EnumField((Enum)colorProperty.colorMode);
                colorModeField.RegisterValueChangedCallback(evt =>
                {
                    if (colorProperty.colorMode == (ColorMode)evt.newValue)
                    {
                        return;
                    }
                    colorProperty.colorMode = (ColorMode)evt.newValue;
                    colorField.hdr          = colorProperty.colorMode == ColorMode.HDR;
                    colorField.MarkDirtyRepaint();
                    DirtyNodes();
                });
                AddRow("Mode", colorModeField);
            }
            else if (property is TextureShaderProperty)
            {
                var textureProperty = (TextureShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    textureProperty.value.texture = (Texture)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
                var defaultModeField = new EnumField((Enum)textureProperty.defaultType);
                defaultModeField.RegisterValueChangedCallback(evt =>
                {
                    if (textureProperty.defaultType == (TextureShaderProperty.DefaultType)evt.newValue)
                    {
                        return;
                    }
                    textureProperty.defaultType = (TextureShaderProperty.DefaultType)evt.newValue;
                    DirtyNodes(ModificationScope.Graph);
                });
                AddRow("Mode", defaultModeField);
            }
            else if (property is Texture2DArrayShaderProperty)
            {
                var textureProperty = (Texture2DArrayShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.textureArray, objectType = typeof(Texture2DArray)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    textureProperty.value.textureArray = (Texture2DArray)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Texture3DShaderProperty)
            {
                var textureProperty = (Texture3DShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture3D)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    textureProperty.value.texture = (Texture3D)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is CubemapShaderProperty)
            {
                var cubemapProperty = (CubemapShaderProperty)property;
                var field           = new ObjectField {
                    value = cubemapProperty.value.cubemap, objectType = typeof(Cubemap)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    cubemapProperty.value.cubemap = (Cubemap)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is BooleanShaderProperty)
            {
                var booleanProperty = (BooleanShaderProperty)property;
                EventCallback <ChangeEvent <bool> > onBooleanChanged = evt =>
                {
                    booleanProperty.value = evt.newValue;
                    DirtyNodes();
                };
                var field = new Toggle();
                field.OnToggleChanged(onBooleanChanged);
                field.value = booleanProperty.value;
                AddRow("Default", field);
            }
//            AddRow("Type", new TextField());
//            AddRow("Exposed", new Toggle(null));
//            AddRow("Range", new Toggle(null));
//            AddRow("Default", new TextField());
//            AddRow("Tooltip", new TextField());


            AddToClassList("sgblackboardFieldPropertyView");

            UpdateReferenceNameResetMenu();
        }
示例#11
0
        public BlackboardFieldPropertyView(BlackboardField blackboardField, GraphData graph, AbstractShaderProperty property)
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/ShaderGraphBlackboard"));
            m_BlackboardField = blackboardField;
            m_Graph           = graph;
            m_Property        = property;

            m_ExposedToogle = new Toggle();
            m_ExposedToogle.OnToggleChanged(evt =>
            {
                m_Graph.owner.RegisterCompleteObjectUndo("Change Exposed Toggle");
                if (m_OnExposedToggle != null)
                {
                    m_OnExposedToggle();
                }
                property.generatePropertyBlock = evt.newValue;
                if (property.generatePropertyBlock)
                {
                    m_BlackboardField.icon = BlackboardProvider.exposedIcon;
                }
                else
                {
                    m_BlackboardField.icon = null;
                }
                DirtyNodes(ModificationScope.Graph);
            });
            m_ExposedToogle.value = property.generatePropertyBlock;
            AddRow("Exposed", m_ExposedToogle);

            m_ReferenceNameField = new TextField(512, false, false, ' ');
            m_ReferenceNameField.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNameReferenceField"));
            AddRow("Reference", m_ReferenceNameField);
            m_ReferenceNameField.value     = property.referenceName;
            m_ReferenceNameField.isDelayed = true;
            m_ReferenceNameField.RegisterValueChangedCallback(newName =>
            {
                m_Graph.owner.RegisterCompleteObjectUndo("Change reference name");
                if (m_ReferenceNameField.value != m_Property.referenceName)
                {
                    string newReferenceName        = m_Graph.SanitizePropertyReferenceName(newName.newValue, property.guid);
                    property.overrideReferenceName = newReferenceName;
                }
                m_ReferenceNameField.value = property.referenceName;

                if (string.IsNullOrEmpty(property.overrideReferenceName))
                {
                    m_ReferenceNameField.RemoveFromClassList("modified");
                }
                else
                {
                    m_ReferenceNameField.AddToClassList("modified");
                }

                DirtyNodes(ModificationScope.Graph);
                UpdateReferenceNameResetMenu();
            });

            if (!string.IsNullOrEmpty(property.overrideReferenceName))
            {
                m_ReferenceNameField.AddToClassList("modified");
            }

            if (property is Vector1ShaderProperty)
            {
                var floatProperty = (Vector1ShaderProperty)property;
                BuildVector1PropertyView(floatProperty);
            }
            else if (property is Vector2ShaderProperty)
            {
                var vectorProperty = (Vector2ShaderProperty)property;
                var field          = new Vector2Field {
                    value = vectorProperty.value
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector3ShaderProperty)
            {
                var vectorProperty = (Vector3ShaderProperty)property;
                var field          = new Vector3Field {
                    value = vectorProperty.value
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Vector4ShaderProperty)
            {
                var vectorProperty = (Vector4ShaderProperty)property;
                var field          = new Vector4Field {
                    value = vectorProperty.value
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    vectorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is ColorShaderProperty)
            {
                var colorProperty = (ColorShaderProperty)property;
                var colorField    = new ColorField {
                    value = property.defaultValue, showEyeDropper = false, hdr = colorProperty.colorMode == ColorMode.HDR
                };
                colorField.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    colorProperty.value = evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", colorField);
                var colorModeField = new EnumField((Enum)colorProperty.colorMode);
                colorModeField.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Color Mode");
                    if (colorProperty.colorMode == (ColorMode)evt.newValue)
                    {
                        return;
                    }
                    colorProperty.colorMode = (ColorMode)evt.newValue;
                    colorField.hdr          = colorProperty.colorMode == ColorMode.HDR;
                    colorField.MarkDirtyRepaint();
                    DirtyNodes();
                });
                AddRow("Mode", colorModeField);
            }
            else if (property is TextureShaderProperty)
            {
                var textureProperty = (TextureShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    textureProperty.value.texture = (Texture)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
                var defaultModeField = new EnumField((Enum)textureProperty.defaultType);
                defaultModeField.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change Texture Mode");
                    if (textureProperty.defaultType == (TextureShaderProperty.DefaultType)evt.newValue)
                    {
                        return;
                    }
                    textureProperty.defaultType = (TextureShaderProperty.DefaultType)evt.newValue;
                    DirtyNodes(ModificationScope.Graph);
                });
                void ToggleDefaultModeFieldEnabled()
                {
                    defaultModeField.SetEnabled(!defaultModeField.enabledSelf);
                }

                m_OnExposedToggle += ToggleDefaultModeFieldEnabled;
                AddRow("Mode", defaultModeField);
            }
            else if (property is Texture2DArrayShaderProperty)
            {
                var textureProperty = (Texture2DArrayShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.textureArray, objectType = typeof(Texture2DArray)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    textureProperty.value.textureArray = (Texture2DArray)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is Texture3DShaderProperty)
            {
                var textureProperty = (Texture3DShaderProperty)property;
                var field           = new ObjectField {
                    value = textureProperty.value.texture, objectType = typeof(Texture3D)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    textureProperty.value.texture = (Texture3D)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is CubemapShaderProperty)
            {
                var cubemapProperty = (CubemapShaderProperty)property;
                var field           = new ObjectField {
                    value = cubemapProperty.value.cubemap, objectType = typeof(Cubemap)
                };
                field.RegisterValueChangedCallback(evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    cubemapProperty.value.cubemap = (Cubemap)evt.newValue;
                    DirtyNodes();
                });
                AddRow("Default", field);
            }
            else if (property is BooleanShaderProperty)
            {
                var booleanProperty = (BooleanShaderProperty)property;
                EventCallback <ChangeEvent <bool> > onBooleanChanged = evt =>
                {
                    m_Graph.owner.RegisterCompleteObjectUndo("Change property value");
                    booleanProperty.value = evt.newValue;
                    DirtyNodes();
                };
                var field = new Toggle();
                field.OnToggleChanged(onBooleanChanged);
                field.value = booleanProperty.value;
                AddRow("Default", field);
            }
//            AddRow("Type", new TextField());
//            AddRow("Exposed", new Toggle(null));
//            AddRow("Range", new Toggle(null));
//            AddRow("Default", new TextField());
//            AddRow("Tooltip", new TextField());


            AddToClassList("sgblackboardFieldPropertyView");

            UpdateReferenceNameResetMenu();
        }
示例#12
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();
                }
            }
        }