public void Setup(SerializedProperty property)
    {
        m_property = property;

        modeProperty       = property.FindPropertyRelative("m_mode");
        colorArrayProperty = property.FindPropertyRelative("m_serializedColorKeys");
        alphaArrayProperty = property.FindPropertyRelative("m_serializedAlphaKeys");

        editMode     = EditMode.color;
        selectedItem = 0;

        selectedProperty = colorArrayProperty.GetArrayElementAtIndex(0);

        gradientTexture          = new Texture2D(400, 1);
        gradientTexture.wrapMode = TextureWrapMode.Clamp;

        currentGradient = GradientFieldDrawer.GenerateGradient(property);
        GradientFieldDrawer.SetGradientToTexture(currentGradient, gradientTexture);
        bgTexture = GradientFieldDrawer.GenerateInspectorBackground(30, 2);


        alphaHandle = LoadIconFromRelativePath("/Resources/GradientAlphaKey.png");
        colorHandle = LoadIconFromRelativePath("/Resources/GradientColorKey.png");

        alphaHandleHighlight = LoadIconFromRelativePath("/Resources/GradientAlphaKey.Highlight.png");
        colorHandleHighlight = LoadIconFromRelativePath("/Resources/GradientColorKey.Highlight.png");
    }
Example #2
0
        internal override void Apply(VisualElement container)
        {
            /// <sample>
            var initialValue = new Gradient();

            initialValue.colorKeys = new GradientColorKey[]
            {
                new GradientColorKey(Color.red, 0),
                new GradientColorKey(Color.blue, 10),
                new GradientColorKey(Color.green, 20)
            };

            // Get a reference to the field from UXML and assign it its value.
            var uxmlField = container.Q <GradientField>("the-uxml-field");

            uxmlField.value = initialValue;

            // Create a new field, disable it, and give it a style class.
            var csharpField = new GradientField("C# Field");

            csharpField.SetEnabled(false);
            csharpField.AddToClassList("some-styled-field");
            csharpField.value = uxmlField.value;
            container.Add(csharpField);

            // Mirror value of uxml field into the C# field.
            uxmlField.RegisterCallback <ChangeEvent <Gradient> >((evt) =>
            {
                csharpField.value = evt.newValue;
            });
            /// </sample>
        }
        internal VisualElement CreateGUI(
            ValueChangedCallback valueChangedCallback,
            Gradient fieldToDraw,
            string labelName,
            out VisualElement propertyGradientField,
            int indentLevel = 0)
        {
            var objectField = new GradientField {
                value = fieldToDraw
            };

            if (valueChangedCallback != null)
            {
                objectField.RegisterValueChangedCallback(evt => { valueChangedCallback((Gradient)evt.newValue); });
            }

            propertyGradientField = objectField;

            // Any core widgets used by the inspector over and over should come from some kind of factory
            var defaultRow = new PropertyRow(PropertyDrawerUtils.CreateLabel(labelName, indentLevel));

            defaultRow.Add(propertyGradientField);
            defaultRow.styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyRow"));
            return(defaultRow);
        }
        public BindableElement CreateGradientField(string name, bool hdr, ColorSpace colorSpace)
        {
            var field = new GradientField(name);

            field.colorSpace = colorSpace;
            field.hdr        = hdr;
            return(field);
        }
        public static void RenderGradientProperty(VisualElement container, string name, object value,
                                                  Action <object> setter)
        {
            var field = new GradientField(name);

            field.SetValueWithoutNotify((Gradient)value);
            field.MarkDirtyRepaint();
            field.RegisterValueChangedCallback(evt => setter(evt.newValue));
            container.Add(field);
        }
    void OpenWindow(SerializedProperty property)
    {
        GradientField gradient = (GradientField)fieldInfo.GetValue(property.serializedObject.targetObject);

        GradientFieldEditorWindow window = ScriptableObject.CreateInstance <GradientFieldEditorWindow>();

        window.Setup(property);
        window.minSize      = new Vector2(550, 240);
        window.titleContent = new GUIContent("Gradient Editor");

        window.ShowAuxWindow();
    }
Example #7
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            if (property.propertyType == SerializedPropertyType.Gradient)
            {
                var gradientUsage = (GradientUsageAttribute)attribute;
                var field         = new GradientField(property.displayName);
                field.hdr        = gradientUsage.hdr;
                field.colorSpace = gradientUsage.colorSpace;
                return(field);
            }

            return(new Label(s_InvalidTypeMessage));
        }
    public static void SetGradientToTexture(GradientField gradient, Texture2D targetTexture)
    {
        int width = targetTexture.width;

        Color[] colors = new Color[width];
        for (int i = 0; i < width; i++)
        {
            float lerp = (float)i / (width - 1);
            colors[i] = gradient.Evaluate(lerp);
        }

        targetTexture.SetPixels(colors);
        targetTexture.Apply();
    }
    public static GradientField GenerateGradient(SerializedProperty property, int excludeColor = -1, int excludeAlpha = -1)
    {
        var gradient = new GradientField();

        gradient.mode = (GradientMode)property.FindPropertyRelative("m_mode").intValue;

        var colorProps = property.FindPropertyRelative("m_serializedColorKeys");
        var alphaProps = property.FindPropertyRelative("m_serializedAlphaKeys");


        SerializedProperty prop;

        var colorKeys = new List <GradientColorKey>();
        var alphaKeys = new List <GradientAlphaKey>();

        for (int i = 0; i < colorProps.arraySize; i++)
        {
            if (i == excludeColor)
            {
                continue;
            }

            prop = colorProps.GetArrayElementAtIndex(i);

            colorKeys.Add(new GradientColorKey(
                              prop.FindPropertyRelative("color").colorValue,
                              prop.FindPropertyRelative("time").floatValue / 100f
                              ));
        }

        for (int i = 0; i < alphaProps.arraySize; i++)
        {
            if (i == excludeAlpha)
            {
                continue;
            }

            prop = alphaProps.GetArrayElementAtIndex(i);

            alphaKeys.Add(new GradientAlphaKey(
                              prop.FindPropertyRelative("alpha").floatValue,
                              prop.FindPropertyRelative("time").floatValue / 100f
                              ));
        }

        gradient.alphaKeys = alphaKeys.ToArray();
        gradient.colorKeys = colorKeys.ToArray();

        return(gradient);
    }
        void BuildGradientPropertyField(GradientShaderProperty property)
        {
            var field = new GradientField {
                value = property.value
            };

            field.RegisterValueChangedCallback(evt =>
            {
                graph.owner.RegisterCompleteObjectUndo("Change Property Value");
                property.value = evt.newValue;
                DirtyNodes();
            });
            AddRow("Default", field);
        }
    void GradientEditorSetter(string GradientName, string GradientLabel, LightColorSetter MaterialSetter)
    {
        VisualElement root = rootVisualElement;
        VisualElement gradientVisualElement = root.Q <VisualElement>(name: GradientName);

        if (gradientVisualElement != null)
        {
            GradientField    gradientField             = gradientVisualElement.Q <GradientField>();
            SerializedObject serialized_MaterialSetter = new SerializedObject(MaterialSetter);
            gradientField.bindingPath = "gradient";
            gradientField.Bind(serialized_MaterialSetter);
            gradientVisualElement.Q <Label>().text = GradientLabel;
        }
    }
Example #12
0
        void Init()
        {
            GradientField field = new GradientField()
            {
                value = config.value != null ? (Gradient)config.value : new Gradient(),
            };

            field.EnableInClassList("compositeField", false);

            field.RegisterValueChangedCallback((e) => {
                config.OnValueChanged(e.newValue);
                MarkDirtyRepaint();
            });
            Add(field);
        }
    void Save()
    {
        GradientFieldDrawer.ResetGradient();

        m_property.serializedObject.ApplyModifiedProperties();

        int excludeAlpha = -1;
        int excludeColor = -1;

        if (isDraggingToRemove)
        {
            excludeAlpha = editMode == EditMode.alpha ? selectedItem : -1;
            excludeColor = editMode == EditMode.color ? selectedItem : -1;
        }

        currentGradient = GradientFieldDrawer.GenerateGradient(m_property, excludeColor, excludeAlpha);
        GradientFieldDrawer.SetGradientToTexture(currentGradient, gradientTexture);

        Repaint();
    }
Example #14
0
        public override void Enable(bool fromInspector)
        {
            base.Enable(fromInspector);
            sampleGradientNode = nodeTarget as SampleGradientNode;

            var gradientField = new GradientField()
            {
                value = sampleGradientNode.gradient
            };

            gradientField.style.height = 32;

            gradientField.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Gradient");
                sampleGradientNode.gradient = (Gradient)e.newValue;
                NotifyNodeChanged();
            });

            controlsContainer.Add(gradientField);
        }
Example #15
0
        public GradientSlotControlView(GradientInputMaterialSlot slot)
        {
            m_Slot = slot;
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/Controls/GradientSlotControlView"));

            m_GradientObject          = ScriptableObject.CreateInstance <GradientObject>();
            m_GradientObject.gradient = new Gradient();
            m_SerializedObject        = new SerializedObject(m_GradientObject);

            m_GradientObject.gradient.SetKeys(m_Slot.value.colorKeys, m_Slot.value.alphaKeys);
            m_GradientObject.gradient.mode = m_Slot.value.mode;

            var gradientField = new GradientField()
            {
                value = m_GradientObject.gradient
            };

            gradientField.RegisterValueChangedCallback(OnValueChanged);
            Add(gradientField);
        }
        public GradientSlotControlView(GradientInputMaterialSlot slot)
        {
            m_Slot = slot;
            AddStyleSheetPath("Styles/Controls/GradientSlotControlView");

            m_GradientObject          = ScriptableObject.CreateInstance <GradientObject>();
            m_GradientObject.gradient = new Gradient();
            m_SerializedObject        = new SerializedObject(m_GradientObject);

            m_GradientObject.gradient.SetKeys(m_Slot.value.colorKeys, m_Slot.value.alphaKeys);
            m_GradientObject.gradient.mode = m_Slot.value.mode;

            var gradientField = new GradientField()
            {
                value = m_GradientObject.gradient
            };

            gradientField.OnValueChanged(OnValueChanged);
            Add(gradientField);
        }
Example #17
0
        public GradientControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
        {
            m_Node         = node;
            m_PropertyInfo = propertyInfo;
            AddStyleSheetPath("Styles/Controls/GradientControlView");

            if (propertyInfo.PropertyType != typeof(Gradient))
            {
                throw new ArgumentException("Property must be of type Gradient.", "propertyInfo");
            }
            new GUIContent(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name));

            m_GradientObject          = ScriptableObject.CreateInstance <GradientObject>();
            m_GradientObject.gradient = new Gradient();
            m_SerializedObject        = new SerializedObject(m_GradientObject);

            var gradient = (Gradient)m_PropertyInfo.GetValue(m_Node, null);

            m_GradientObject.gradient.SetKeys(gradient.colorKeys, gradient.alphaKeys);
            m_GradientObject.gradient.mode = gradient.mode;

            var gradientPanel = new VisualElement {
                name = "gradientPanel"
            };

            if (!string.IsNullOrEmpty(label))
            {
                gradientPanel.Add(new Label(label));
            }

            var gradientField = new GradientField()
            {
                value = m_GradientObject.gradient
            };

            gradientField.OnValueChanged(OnValueChanged);
            gradientPanel.Add(gradientField);

            Add(gradientPanel);
        }
Example #18
0
    void SetArtistTool()
    {
        VisualElement root = rootVisualElement;

        root.Clear();
        VisualTreeAsset ArtistToolVisualTree = Resources.Load <VisualTreeAsset>("ArtistTool");

        ArtistToolVisualTree.CloneTree(root);
        root.styleSheets.Add(Resources.Load <StyleSheet>("ArtistTool"));

        SerializedObject Tso        = new SerializedObject(TimeController);
        Slider           timeSlider = root.Q <Slider>(name: "Time");

        timeSlider.Bind(Tso);


        #region SkyColor
        VisualElement gradientVisualElement = root.Q <VisualElement>(name: "SkyGradient");

        if (gradientVisualElement != null)
        {
            GradientField gradientField = gradientVisualElement.Q <GradientField>();

            if (gradientField != null)
            {
                skyColorSetter = GameObject.Find("Light - Sky").GetComponent <MaterialColorSetter>();
                SerializedObject serialized_MaterialSetter = new SerializedObject(skyColorSetter);
                gradientField.bindingPath = "gradient";
                gradientField.Bind(serialized_MaterialSetter);
                gradientVisualElement.Q <Label>().text = "Sky Gradient";
            }
        }

        #endregion

        #region Ruins
        GradientEditorSetter("RuinsGradient", "Ruins Gradient", RuinsColorSetter);
        #endregion

        #region Trees
        GradientEditorSetter("TreesGradient", "Trees Gradient", TreesColorSetter);
        #endregion

        #region Rim
        GradientEditorSetter("RimColor", "Rim Gradient", RimColorSetter);
        #endregion



        #region Lights

        #region SunLights
        SerializedObject serialized_SunSpot = new SerializedObject(SunSpot_Group);

        VisualElement sunLightVisualElement = root.Q <VisualElement>(name: "Sunlight");
        if (sunLightVisualElement.Q <VisualElement>(name: "LightGradient") != null)
        {
            GradientField sunLightGradient  = sunLightVisualElement.Q <VisualElement>(name: "LightGradient").Q <GradientField>();
            FloatField    sunLightIntensity = root.Q <FloatField>(name: "Intensity");
            if (sunLightGradient != null)
            {
                sunLightGradient.bindingPath = "gradient";
                sunLightGradient.Bind(serialized_SunSpot);
                sunLightGradient.label = "Gradient";
            }

            sunLightIntensity.value = GetSpotLightIntensity();
            sunLightIntensity.RegisterCallback <ChangeEvent <float> >(ChangeIntensitySpotLightsEvent);
        }

        #endregion

        #region GrassLight
        SerializedObject serialized_GrassLight_Group = new SerializedObject(GrassLight_Group);

        VisualElement grassLightVisualElement = root.Q <VisualElement>(name: "GrassLight");
        if (grassLightVisualElement.Q <VisualElement>(name: "LightGradient") != null)
        {
            GradientField grassLightGradient  = grassLightVisualElement.Q <VisualElement>(name: "LightGradient").Q <GradientField>();
            FloatField    grassLightIntensity = grassLightVisualElement.Q <FloatField>(name: "Intensity");

            if (grassLightGradient != null)
            {
                grassLightGradient.bindingPath = "gradient";
                grassLightGradient.Bind(serialized_GrassLight_Group);
                grassLightGradient.label = "Gradient";
            }

            grassLightIntensity.value = GrassLight.intensity;

            SerializedObject serialized_GrassLight = new SerializedObject(GrassLight);
            grassLightIntensity.Bind(serialized_GrassLight);
        }
        #endregion

        #region cave Light
        SerializedObject serialized_CaveHoleLight = new SerializedObject(CaveHoleLight);

        VisualElement caveLightVisualElement = root.Q <VisualElement>(name: "CaveHoleLight");
        caveLightVisualElement.Q <FloatField>(name: "Falloff").Bind(serialized_CaveHoleLight);

        Slider     fallOffSlider = caveLightVisualElement.Q <Slider>(name: "FalloffIntencity");
        FloatField fallOffField  = fallOffSlider.Q <FloatField>(name: "CurrentValue");
        fallOffSlider.Bind(serialized_CaveHoleLight);

        fallOffField.SetValueWithoutNotify(CaveHoleLight.falloffIntensity);

        fallOffField.RegisterCallback <ChangeEvent <float> >((evt) => fallOffSlider.value = evt.newValue);

        fallOffSlider.RegisterCallback <ChangeEvent <float> >((evt) => fallOffField.SetValueWithoutNotify(evt.newValue));

        #endregion

        #region Visualisers
        var AllGradientElements = root.Query <GradientField>();
        AllGradientElements.ForEach((element) =>
        {
            //registerCallback for Gradient to apply changes on scene
            element.RegisterCallback <ChangeEvent <Gradient> >(ChangeGradientEvent);

            VisualElement visualiser = element.Q <VisualElement>(name: "VisualisationColor");

            //Init color of visualisation cube
            float currentTime = TimeController.timeValue;
            visualiser.style.backgroundColor = element.value.Evaluate(currentTime);

            //register Callback for each visualisation cube when gradient Changes
            element.RegisterCallback <ChangeEvent <Gradient> >((evt) =>
            {
                float timeOfChange = TimeController.timeValue;
                visualiser.style.backgroundColor = evt.newValue.Evaluate(currentTime);
            });

            //register Callback for each visualisation cube when Time Changes
            timeSlider.RegisterCallback <ChangeEvent <float> >((evt) =>
            {
                visualiser.style.backgroundColor = element.value.Evaluate(evt.newValue);
            });
        });
        #endregion

        #endregion

        #region Wind Shader
        // Set Initial Values
        VisualElement windComponent = root.Q <VisualElement>(name: "Wind");
        if (windComponent != null)
        {
            Vector4Field windDirectionQuaternion = windComponent.Q <Vector4Field>(name: "WindDirection");
            windDirectionQuaternion.value = GetWindDirection();

            FloatField windScaleFloat = windComponent.Q <FloatField>(name: "WindScale");
            windScaleFloat.value = GetWindScale();

            MinMaxValue minMaxStrength = GetWindStrength();

            VisualElement windStrengthHolder = windComponent.Q <VisualElement>(name: "WinStrengthHolder");

            MinMaxSlider windStrengthSlider = windStrengthHolder.Q <MinMaxSlider>(name: "WindStrength");
            windStrengthSlider.highLimit = minMaxStrength.HighLimit;
            windStrengthSlider.lowLimit  = minMaxStrength.LowLimit;
            windStrengthSlider.value     = new Vector2(minMaxStrength.minValue, minMaxStrength.maxValue);

            windStrengthHolder.Q <Label>(name: "MinValue").text = "Min Value :" + minMaxStrength.minValue;
            windStrengthHolder.Q <Label>(name: "MaxValue").text = "Max Value :" + minMaxStrength.maxValue;

            FloatField windSpeedFloat = windComponent.Q <FloatField>(name: "WindSpeed");
            windSpeedFloat.value = GetWindSpeed();

            //Set Callbacks values
            windDirectionQuaternion.RegisterCallback <ChangeEvent <Vector4> >(ChangeWindDirection);
            windScaleFloat.RegisterCallback <ChangeEvent <float> >(ChangeWindScale);
            windStrengthSlider.RegisterCallback <ChangeEvent <Vector2> >(ChangeWindStrength);
            windSpeedFloat.RegisterCallback <ChangeEvent <float> >(ChangeWindSpeed);
        }

        #endregion

        #region Postprocessing
        #region WhiteBalance
        //serialize White balance property
        SerializedObject serialized_whiteBalanceProperty = new SerializedObject(whiteBalanceProperty);
        //Get White balance Visual Element
        VisualElement whiteBalanceVisualElement = root.Q <VisualElement>(name: "WhiteBalance");

        #region Temperature
        //Get White Balance temperature Visual Element
        VisualElement whiteBalanceTemperatureVE = whiteBalanceVisualElement.Q <VisualElement>(name: "Temperature");

        //Get White Balance temperature Slider
        Slider whiteBalanceTemperatureSlider = whiteBalanceTemperatureVE.Q <Slider>(name: "SliderValue");

        //Bind Slider to value
        whiteBalanceTemperatureSlider.bindingPath = "temperature.m_Value";
        whiteBalanceTemperatureSlider.Bind(serialized_whiteBalanceProperty);

        //Get White Balance temperature Float Field
        FloatField whiteBalanceTemperatureFloat = whiteBalanceTemperatureVE.Q <FloatField>(name: "CurrentValue");
        //Set default Temperature
        whiteBalanceTemperatureFloat.SetValueWithoutNotify(whiteBalanceProperty.temperature.value);

        //Register change callback for the float field to change the slider value. Changing slider value will change the values bound with it.
        whiteBalanceTemperatureFloat.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTemperatureSlider.value = evt.newValue);

        //Register change Callback for the slider, to change the float fiel Without notification (to avoid triggering Float field callback)
        whiteBalanceTemperatureSlider.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTemperatureFloat.SetValueWithoutNotify(evt.newValue));
        #endregion

        #region Tint

        //Get White Balance Tint Visual Element
        VisualElement whiteBalanceTintVE = whiteBalanceVisualElement.Q <VisualElement>(name: "Tint");

        //Get White Balance Tint Slider
        Slider whiteBalanceTintSlider = whiteBalanceTintVE.Q <Slider>(name: "SliderValue");

        //Bind Slider to value
        whiteBalanceTintSlider.bindingPath = "tint.m_Value";
        whiteBalanceTintSlider.Bind(serialized_whiteBalanceProperty);

        //Get White Balance Tint Float Field
        FloatField whiteBalanceTintFloat = whiteBalanceTintVE.Q <FloatField>(name: "CurrentValue");
        //Set default Tint
        whiteBalanceTintFloat.SetValueWithoutNotify(whiteBalanceProperty.tint.value);

        //Register change callback for the float field to change the slider value. Changing slider value will change the values bound with it.
        whiteBalanceTintFloat.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTintSlider.value = evt.newValue);

        //Register change Callback for the slider, to change the float fiel Without notification (to avoid triggering Float field callback)
        whiteBalanceTintSlider.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTintFloat.SetValueWithoutNotify(evt.newValue));
        #endregion

        #endregion

        #region Bloom

        //serialize bloom property
        SerializedObject serialized_BloomProperty = new SerializedObject(BloomProperty);
        //Get Bloom Visual Element
        VisualElement bloomVisualElement = root.Q <VisualElement>(name: "Bloom");

        //Get Bloom Tint Color
        ColorField bloomTint = bloomVisualElement.Q <ColorField>(name: "Tint");

        //Bind color to value
        bloomTint.bindingPath = "tint.m_Value";
        bloomTint.Bind(serialized_BloomProperty);

        //Get Bloom Intensity
        FloatField bloomIntensity = bloomVisualElement.Q <FloatField>(name: "Intensity");

        //Bind Intensity to value
        bloomIntensity.Bind(serialized_BloomProperty);

        #endregion
        #endregion


        #region VFX

        SerializedObject serialized_GlowParticleSystem = new SerializedObject(GlowParticleSystem);

        VisualElement VFXVisualElement = root.Q <VisualElement>(name: "VFX");


        VFXVisualElement.Q <FloatField>(name: "Emission").bindingPath = "EmissionModule.rateOverTime.scalar";
        VFXVisualElement.Q <FloatField>(name: "Emission").Bind(serialized_GlowParticleSystem);

        VFXVisualElement.Q <EnumField>(name: "RenderMode").Init(GlowParticleSystem.GetComponent <ParticleSystemRenderer>().renderMode);
        VFXVisualElement.Q <EnumField>(name: "RenderMode").RegisterCallback <ChangeEvent <string> >(ChangeRenderMode);

        VFXVisualElement.Q <ObjectField>(name: "Material").objectType = typeof(Material);
        VFXVisualElement.Q <ObjectField>(name: "Material").RegisterCallback <ChangeEvent <string> >(ChangeRenderMaterial);
        #endregion

        root.Q <Button>(name: "SaveButton").clicked  += SaveButton;
        root.Q <Button>(name: "ResetButton").clicked += ResetToInitialSceneValues;
    }
Example #19
0
        void CreateUIElements()
        {
            var titleRow = new VisualElement()
            {
                style =
                {
                    flexDirection  = FlexDirection.Row,
                    flexShrink     =                0f,
                    justifyContent = Justify.SpaceBetween
                }
            };

            m_VisualElementContainer.Add(new Label("VisualElements Container"));


            var curveX           = AnimationCurve.Linear(0, 0, 1, 0);
            var popupFieldValues = new List <SomeClass>
            {
                new SomeClass("First Class Value"),
                new SomeClass("Second Value"),
                new SomeClass("Another Value"),
                new SomeClass("Another Value with a very lonnnnnnnnnnnnnnnnnnnnnnnnng text to make sure this is really overflowing the popup field.")
            };
            var maskFieldOptions = new List <string>(m_MaskFieldOptions);


            m_VisualElementContainer.Add(m_IntegerField  = new IntegerField());
            m_VisualElementContainer.Add(m_LongField     = new LongField());
            m_VisualElementContainer.Add(m_FloatField    = new FloatField());
            m_VisualElementContainer.Add(m_DoubleField   = new DoubleField());
            m_VisualElementContainer.Add(m_EnumField     = new EnumField(EnumValues.Two));
            m_VisualElementContainer.Add(m_TextField     = new TextField());
            m_VisualElementContainer.Add(m_PasswordField = new TextField()
            {
                isPasswordField = true, maskChar = '*'
            });
            m_VisualElementContainer.Add(m_Vector3Field      = new Vector3Field());
            m_VisualElementContainer.Add(m_Vector3IntField   = new Vector3IntField());
            m_VisualElementContainer.Add(m_Vector2Field      = new Vector2Field());
            m_VisualElementContainer.Add(m_ColorField        = new ColorField());
            m_VisualElementContainer.Add(m_ObjectFieldCamera = new ObjectField()
            {
                objectType = typeof(Camera)
            });
            m_VisualElementContainer.Add(m_ObjectFieldGameObject = new ObjectField()
            {
                objectType = typeof(GameObject)
            });
            m_VisualElementContainer.Add(m_CurveField = new CurveField()
            {
                value = curveX
            });
            m_VisualElementContainer.Add(m_CurveFieldMesh = new CurveField()
            {
                value = curveX, renderMode = CurveField.RenderMode.Mesh
            });
            m_VisualElementContainer.Add(m_PopupField        = new PopupField <SomeClass>(popupFieldValues, popupFieldValues[1]));
            m_VisualElementContainer.Add(m_RectField         = new RectField());
            m_VisualElementContainer.Add(m_BoundsField       = new BoundsField());
            m_VisualElementContainer.Add(m_ToggleField       = new Toggle());
            m_VisualElementContainer.Add(m_MaskField         = new MaskField(maskFieldOptions, 6));
            m_VisualElementContainer.Add(m_LayerField        = new LayerField());
            m_VisualElementContainer.Add(m_TagField          = new TagField());
            m_VisualElementContainer.Add(m_MinMaxSliderField = new MinMaxSlider(5, 10, 0, 125));
            m_VisualElementContainer.Add(m_Slider            = new Slider(2, 8));
            m_VisualElementContainer.Add(m_SliderInt         = new SliderInt(11, 23));

            var buttonRow = new VisualElement()
            {
                style =
                {
                    flexDirection = FlexDirection.Row,
                    flexShrink    =                0f,
                }
            };

            buttonRow.Add(new Button()
            {
                text = k_ButtonLeftTitle, style = { flexGrow = 1 }
            });
            buttonRow.Add(new Button()
            {
                text = k_ButtonRightTitle, style = { flexGrow = 1 }
            });
            m_VisualElementContainer.Add(buttonRow);

            m_VisualElementContainer.Add(new Button()
            {
                text = k_ButtonTopTitle
            });
            m_VisualElementContainer.Add(new Button()
            {
                text = k_ButtonBottomTitle
            });

            m_VisualElementContainer.Add(m_ColorField1        = new ColorField());
            m_VisualElementContainer.Add(m_LayerMaskField     = new LayerMaskField(0));
            m_VisualElementContainer.Add(m_MultiLineTextField = new TextField()
            {
                multiline = true
            });

            m_VisualElementContainer.Add(m_SliderProgressBar = new SliderInt());
            m_VisualElementContainer.Add(m_ProgressBar       = new ProgressBar());

            m_ProgressBar.title           = nameof(ProgressBar);
            m_SliderProgressBar.lowValue  = 0;
            m_SliderProgressBar.highValue = 100;

            m_SliderProgressBar.bindingPath = nameof(SliderProgressTestObject.exampleValue);
            m_ProgressBar.bindingPath       = nameof(SliderProgressTestObject.exampleValue);

            m_SliderProgressBar.Bind(SliderProgressTestSO);
            m_ProgressBar.Bind(SliderProgressTestSO);
            // The progress bar by itself does not contain any margin in IMGUI...
            // In this example, we are artifically adding the textfield margin to it. (see below, in the IMGUI section, ProgressBar())
            m_ProgressBar.style.marginBottom = 2f;

            m_VisualElementContainer.Add(m_GradientField = new GradientField());
            RefreshUIElements();
        }
        public void OnEnable()
        {
            if (input == null)
            {
                input = new Gradient();
                input.SetKeys(
                    new GradientColorKey[] { new GradientColorKey(Color.red, 0), new GradientColorKey(Color.blue, 1) }
                    , new GradientAlphaKey[] { new GradientAlphaKey(1, 1) });
            }
            if (approxOutput == null)
            {
                approxOutput = new Gradient();
            }
            if (gradientTexture == null)
            {
                gradientTexture = new Texture2D(256, 1);
                gradientColors  = gradientTexture.GetPixels();
            }

            var root = this.GetRootVisualContainer();

            var inputContainer = new VisualElement()
            {
                style =
                {
                    marginTop       =                 6,
                    marginBottom    =                 6,
                    flexDirection   = FlexDirection.Row,
                    backgroundColor = new Color(0.3f, 0.3f, 0.3f),
                }
            };

            inputContainer.Add(new Label()
            {
                text  = "Input Gradient",
                style =
                {
                    fontSize  =             12,
                    fontStyle = FontStyle.Bold,
                    width     = 140
                }
            });
            inputGradientField = new GradientField()
            {
                value = input,
                style =
                {
                    fontSize  =             20,
                    fontStyle = FontStyle.Bold,
                    flexGrow  = 1
                }
            };
            inputContainer.Add(inputGradientField);
            root.Add(inputContainer);

            root.Add(new Button(() => { ConvertToTexture(GradientMode.RGB); })
            {
                text  = "Convert (RGB)",
                style =
                {
                    fontSize  = 12,
                    fontStyle = FontStyle.Bold
                }
            });
            root.Add(new Button(() => { ConvertToTexture(GradientMode.LChuv); })
            {
                text  = "Convert (LChuv) + Approximate",
                style =
                {
                    fontSize  = 12,
                    fontStyle = FontStyle.Bold
                }
            });

            var outputTexContainer = new VisualElement()
            {
                style =
                {
                    marginTop       =                 6,
                    marginBottom    =                 6,
                    flexDirection   = FlexDirection.Row,
                    backgroundColor = new Color(0.3f, 0.3f, 0.3f),
                }
            };

            outputTexContainer.Add(new Label()
            {
                text  = "Output Texture",
                style =
                {
                    fontSize  =             12,
                    fontStyle = FontStyle.Bold,
                    width     = 140
                }
            });
            outputGradientTexture = new VisualElement()
            {
                style =
                {
                    marginLeft   =   6,
                    marginRight  =   6,
                    marginTop    =   2,
                    marginBottom =   2,
                    width        = 256,
                    height       = 30
                }
            };
            outputTexContainer.Add(outputGradientTexture);
            outputTexContainer.Add(new Button(() => { SaveTexture(outputGradientTexture.style.backgroundImage.value); })
            {
                text  = "Save",
                style =
                {
                    fontSize  = 12,
                    fontStyle = FontStyle.Bold
                }
            });
            root.Add(outputTexContainer);

            var outputApproxGradientContainer = new VisualElement()
            {
                style =
                {
                    marginTop       =                 6,
                    marginBottom    =                 6,
                    flexDirection   = FlexDirection.Row,
                    backgroundColor = new Color(0.3f, 0.3f, 0.3f),
                }
            };

            outputApproxGradientContainer.Add(new Label()
            {
                text  = "Output Approx. Gradient",
                style =
                {
                    fontSize  =             12,
                    fontStyle = FontStyle.Bold,
                    width     = 140
                }
            });
            outputGradientField = new GradientField()
            {
                value = approxOutput,
                style =
                {
                    fontSize  =             20,
                    fontStyle = FontStyle.Bold,
                    flexGrow  = 1
                }
            };
            outputApproxGradientContainer.Add(outputGradientField);
            root.Add(outputApproxGradientContainer);
        }
        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();
        }
Example #22
0
        public void OnEnable()
        {
            if (approxOutput == null)
            {
                approxOutput = new Gradient();
            }
            if (inputTexture == null)
            {
                inputTexture = Texture2D.whiteTexture;
            }
            var root = this.GetRootVisualContainer();

            var inputContainer = new VisualElement()
            {
                style =
                {
                    marginTop       =                 6,
                    marginBottom    =                 6,
                    flexDirection   = FlexDirection.Row,
                    backgroundColor = new Color(0.3f, 0.3f, 0.3f),
                }
            };

            // Display Texture selector
            root.Add(new IMGUIContainer(OnTextureSelectorGUI)
            {
                style =
                {
                    width       = 200,
                    height      =  50,
                    marginLeft  =  10,
                    marginRight =  10,
                    marginTop   = 10
                }
            });
            root.Add(inputContainer);

            var button = new Button(ApproximateGradient)
            {
                text  = "Approximate",
                style =
                {
                    fontSize  = 12,
                    fontStyle = FontStyle.Bold
                }
            };

            root.Add(button);

            var outputContainer = new VisualElement()
            {
                style =
                {
                    marginTop       =                 6,
                    marginBottom    =                 6,
                    flexDirection   = FlexDirection.Row,
                    backgroundColor = new Color(0.3f, 0.3f, 0.3f),
                }
            };

            // Label
            outputContainer.Add(new Label()
            {
                text  = "Output Gradient",
                style =
                {
                    fontSize  =             12,
                    fontStyle = FontStyle.Bold,
                    width     = 140
                }
            });
            // GradientField
            outputGradientField = new GradientField()
            {
                value = approxOutput,
                style =
                {
                    fontSize  =             20,
                    fontStyle = FontStyle.Bold,
                    flexGrow  = 1
                }
            };
            outputContainer.Add(outputGradientField);
            root.Add(outputContainer);
        }