public void VoxelFieldUi(VisualElement view, Settings settings)
    {
        var voxSize      = view.Q <FloatField>(className: "voxel-size");
        var NbMaxOfVoxel = view.Q <IntegerField>(className: "max-number-of-type");

        voxSize.value      = settings.SizeShared;
        NbMaxOfVoxel.value = (int)settings.MaxTypeOfVoxel;

        NbMaxOfVoxel.RegisterCallback <ChangeEvent <int> >(evt =>
        {
            MinMaxSlider slider = null;

            if (settings.RenderRules.Length > 0)
            {
                slider = view.Q(className: "rule", name: (settings.RenderRules.Length - 1).ToString()).Q <MinMaxSlider>(className: "MinMax");
            }

            if (evt.newValue < 0 || evt.newValue > 255 || (slider != null && evt.newValue < slider.maxValue))
            {
                return;
            }

            if (slider != null)
            {
                slider.highLimit = evt.newValue;
            }

            settings.MaxTypeOfVoxel = (uint)evt.newValue;
            AssetDatabase.ForceReserializeAssets(new List <string> {
                modulePath
            });
        });
    }
Ejemplo n.º 2
0
        public override void Enable(bool fromInspector)
        {
            base.Enable(fromInspector);

            var node = nodeTarget as RandomColorNode;

            var h = new MinMaxSlider("H", node.minHue, node.maxHue, 0.0f, 1.0f);
            var s = new MinMaxSlider("S", node.minSat, node.maxSat, 0.0f, 1.0f);
            var v = new MinMaxSlider("V", node.minValue, node.maxValue, 0.0f, 1.0f);

            h.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Hue " + e.newValue);
                node.minHue = e.newValue.x;
                node.maxHue = e.newValue.y;
                NotifyNodeChanged();
            });

            s.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Saturation " + e.newValue);
                node.minSat = e.newValue.x;
                node.maxSat = e.newValue.y;
                NotifyNodeChanged();
            });

            v.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Updated Value " + e.newValue);
                node.minValue = e.newValue.x;
                node.maxValue = e.newValue.y;
                NotifyNodeChanged();
            });

            controlsContainer.Add(h);
            controlsContainer.Add(s);
            controlsContainer.Add(v);
        }
Ejemplo n.º 3
0
        protected virtual void OnEnable()
        {
            // Reference to the root of the window.
            rootElement = rootVisualElement;

            controlParent = new VisualElement();
            controlParent.Add(toggleRecording = new Button(ToggleRecording)
            {
                text = "--"
            });
            buttonParent = new VisualElement();
            buttonParent.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
            buttonParent.Add(togglePlayback  = new Button(TogglePlayback)
            {
                text = "--"
            });
            buttonParent.Add(playbackPauseGame = new Toggle("Pause game on playback ?")
            {
                viewDataKey = "playbackPauseGame"
            });
            controlParent.Add(new Label(" "));
            controlParent.Add(buttonParent);
            controlParent.Add(playbackPauseGame);
            controlParent.Add(new Label(" "));
            rootElement.Add(controlParent);

            framesParent = new VisualElement();
            var textParent = new VisualElement();

            textParent.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
            textParent.style.alignContent  = new StyleEnum <Align>(Align.Center);
            textParent.Add(recordedFrames  = new Label("Recordered --/--"));
            textParent.Add(previewedFrames = new Label("Previewing --/--"));
            framesParent.Add(textParent);
            var recordParent = new VisualElement();

            recordParent.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row);
            recordParent.style.alignContent  = new StyleEnum <Align>(Align.Center);
            recordParent.Add(frameCapacity   = new IntegerField("Frame capacity: ")
            {
                value = 50, viewDataKey = "frameCapacity"
            });
            recordParent.Add(showMultipleFrames = new Toggle("Show multiple frames ?")
            {
                viewDataKey = "showMultipleFrames"
            });
            framesParent.Add(recordParent);
            rootElement.Add(framesParent);

            playbackParent = new VisualElement();
            playbackParent.Add(playbackSingle = new SliderInt(0, 100)
            {
                viewDataKey = "playbackSingle"
            });
            playbackParent.Add(playbackMultiple = new MinMaxSlider(0, 100, 0, 100)
            {
                viewDataKey = "playbackMultiple"
            });
            rootElement.Add(playbackParent);
        }
Ejemplo n.º 4
0
        private void OnEnable()
        {
#if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER
            string windowLayoutPath = "Packages/com.utj.profilerlogsplit/Editor/UI/UXML/ProfilerLogSplit.uxml";
#else
            string windowLayoutPath = "Packages/com.utj.profilerlogsplit/Editor/UI/UXML2018/ProfilerLogSplit.uxml";
#endif
            var tree          = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(windowLayoutPath);
            var visualElement = CloneTree(tree);
            this.rootVisualElement.Add(visualElement);

            this.FileNameLabel = this.rootVisualElement.Q <Label>("FileName");
            this.rootVisualElement.Q <Button>("SelFileBtn").clickable.clicked += OnClickFileSelectBtn;
            afterPrepareElement         = this.rootVisualElement.Q <VisualElement>("AfterAnalyze");
            afterPrepareElement.visible = false;
            afterPrepareElement.Q <Button>("SendProfilerBtn").clickable.clicked += OnClickSendToProfiler;

            afterPrepareElement.Q <Button>("NextBlockBtn").clickable.clicked += OnClickNextBtn;

            this.frameSlider   = afterPrepareElement.Q <MinMaxSlider>("ProfilerFrame");
            this.minFrame      = afterPrepareElement.Q <IntegerField>("ProfilerMinFrame");
            this.maxFrame      = afterPrepareElement.Q <IntegerField>("ProfilerMaxFrame");
            this.FileInfoLabel = afterPrepareElement.Q <Label>("Result");

            this.frameSlider.RegisterCallback <ChangeEvent <Vector2> >(OnChangeSlider);
            this.minFrame.RegisterCallback <ChangeEvent <int> >(OnChangeMinValue);
            this.maxFrame.RegisterCallback <ChangeEvent <int> >(OnChangeMaxValue);

            this.progressUI = new PrepareProgressUI();
        }
Ejemplo n.º 5
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        serializedObject.Update();

        float minLimitOld = _minLimit.floatValue;
        float maxLimitOld = _maxLimit.floatValue;
        float minValueOld = _minValue.floatValue;
        float maxValueOld = _maxValue.floatValue;

        EditorGUILayout.PropertyField(_customCamera);
        EditorGUILayout.PropertyField(_sliderBounds);
        EditorGUILayout.PropertyField(_minHandle);
        EditorGUILayout.PropertyField(_maxHandle);
        EditorGUILayout.PropertyField(_middleGraphic);

        EditorGUILayout.PropertyField(_minText);
        EditorGUILayout.PropertyField(_maxText);
        EditorGUILayout.PropertyField(_textFormat);

        EditorGUILayout.PropertyField(_minLimit);
        EditorGUILayout.PropertyField(_maxLimit);

        EditorGUILayout.PropertyField(_wholeNumbers);
        EditorGUILayout.PropertyField(_minValue);
        EditorGUILayout.PropertyField(_maxValue);

        float minValue = Mathf.Clamp(_minValue.floatValue, _minLimit.floatValue, _maxLimit.floatValue);
        float maxValue = Mathf.Clamp(_maxValue.floatValue, _minLimit.floatValue, _maxLimit.floatValue);

        EditorGUILayout.MinMaxSlider(label, ref minValue, ref maxValue, _minLimit.floatValue, _maxLimit.floatValue);

        bool anyValueChanged = !IsEqualFloat(minValueOld, minValue) ||
                               !IsEqualFloat(maxValueOld, maxValue) ||
                               !IsEqualFloat(minLimitOld, _minLimit.floatValue) ||
                               !IsEqualFloat(maxLimitOld, _maxLimit.floatValue);

        if (anyValueChanged)
        {
            MinMaxSlider slider = (MinMaxSlider)target;

            // force limits to ints if whole numbers.
            // needed to do this here because it wouldn't set in component script for some reason
            if (slider.wholeNumbers)
            {
                _minLimit.floatValue = Mathf.RoundToInt(_minLimit.floatValue);
                _maxLimit.floatValue = Mathf.RoundToInt(_maxLimit.floatValue);
            }

            // set slider values
            slider.SetValues(minValue, maxValue, _minLimit.floatValue, _maxLimit.floatValue);
        }

        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(_onValueChanged);

        serializedObject.ApplyModifiedProperties();
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        float minLimitOld = _minLimit.floatValue;
        float maxLimitOld = _maxLimit.floatValue;
        float minValueOld = _minValue.floatValue;
        float maxValueOld = _maxValue.floatValue;

        Label("UI Controls");
        EditorGUILayout.PropertyField(_sliderBounds);
        EditorGUILayout.PropertyField(_minHandle);
        EditorGUILayout.PropertyField(_maxHandle);
        EditorGUILayout.PropertyField(_middleGraphic);

        Label("Display Text (Optional)");
        EditorGUILayout.PropertyField(_minText);
        EditorGUILayout.PropertyField(_maxText);

        Label("Limits");
        EditorGUILayout.PropertyField(_minLimit);
        EditorGUILayout.PropertyField(_maxLimit);

        Label("Values");
        EditorGUILayout.PropertyField(_wholeNumbers);
        EditorGUILayout.PropertyField(_minValue);
        EditorGUILayout.PropertyField(_maxValue);

        float minValue = Mathf.Clamp(_minValue.floatValue, _minLimit.floatValue, _maxLimit.floatValue);
        float maxValue = Mathf.Clamp(_maxValue.floatValue, _minLimit.floatValue, _maxLimit.floatValue);

        EditorGUILayout.MinMaxSlider(label, ref minValue, ref maxValue, _minLimit.floatValue, _maxLimit.floatValue);

        bool anyValueChanged = minValueOld != minValue ||
                               maxValueOld != maxValue ||
                               minLimitOld != _minLimit.floatValue ||
                               maxLimitOld != _maxLimit.floatValue;

        if (anyValueChanged)
        {
            MinMaxSlider slider = target as MinMaxSlider;
            // force limits to ints if whole numbers.
            // needed to do this here because it wouldn't set in component script for some reason
            if (slider.wholeNumbers)
            {
                _minLimit.floatValue = Mathf.RoundToInt(_minLimit.floatValue);
                _maxLimit.floatValue = Mathf.RoundToInt(_maxLimit.floatValue);
            }

            // set slider values
            slider.SetValues(minValue, maxValue, _minLimit.floatValue, _maxLimit.floatValue);
        }

        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(_onValueChanged);

        serializedObject.ApplyModifiedProperties();
    }
Ejemplo n.º 7
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        const float ComponentHeight   = 16.0f;
        const float VerticalPadding   = 2.0f;
        const float HorizontalPadding = 5.0f;
        const float FieldWidth        = 45;

        if (property.propertyType != SerializedPropertyType.Vector2)
        {
            EditorGUI.LabelField(position, label, "Type needs to be a Vector2");
            return;
        }

        Vector2      range = property.vector2Value;
        float        min   = range.x;
        float        max   = range.y;
        MinMaxSlider attr  = attribute as MinMaxSlider;

        label = EditorGUI.BeginProperty(position, label, property);

        float verticalPos = position.y + ComponentHeight + VerticalPadding;
        float sliderWidth = position.width - 5 * HorizontalPadding - 2 * FieldWidth;
        Rect  sliderRect  = new Rect(position.x + FieldWidth + 2 * HorizontalPadding, verticalPos, sliderWidth, ComponentHeight);
        Rect  leftRect    = new Rect(position.x + HorizontalPadding, verticalPos, FieldWidth, ComponentHeight);
        Rect  rightRect   = new Rect(position.width - FieldWidth + HorizontalPadding, verticalPos, FieldWidth, ComponentHeight);

        EditorGUI.LabelField(position, label);

        EditorGUI.BeginChangeCheck();

        EditorGUI.MinMaxSlider(sliderRect, ref min, ref max, attr.min, attr.max);

        min = EditorGUI.FloatField(leftRect, min);
        max = EditorGUI.FloatField(rightRect, max);

        if (EditorGUI.EndChangeCheck())
        {
            if (!(min > max || max < min))
            {
                if (min < attr.min)
                {
                    min = attr.min;
                }

                if (max > attr.max)
                {
                    max = attr.max;
                }

                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
        }

        EditorGUI.EndProperty();
    }
Ejemplo n.º 8
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType == SerializedPropertyType.Vector2)
            {
                Vector2 range = property.vector2Value;
                float   min   = range.x;
                float   max   = range.y;

                float space      = 5;
                float labelWidth = position.width * 0.3f;
                float valueWidth = 50;

                float labelPos = position.x;
                float minPos   = labelPos + labelWidth + space;
                float maxPos   = position.x + position.width - valueWidth;

                float sliderPos   = minPos + valueWidth + space;
                float sliderWidth = maxPos - sliderPos - space;

                Rect labelRect  = new Rect(labelPos, position.y, labelWidth, position.height);
                Rect minRect    = new Rect(minPos, position.y, valueWidth, position.height);
                Rect sliderRect = new Rect(sliderPos, position.y, sliderWidth, position.height);
                Rect maxRect    = new Rect(maxPos, position.y, valueWidth, position.height);

                MinMaxSlider attr = attribute as MinMaxSlider;

                EditorGUI.BeginChangeCheck();
                EditorGUI.LabelField(labelRect, label);
                min = EditorGUI.FloatField(minRect, range.x);
                max = EditorGUI.FloatField(maxRect, range.y);
                EditorGUI.MinMaxSlider(sliderRect, ref min, ref max, attr.min, attr.max);
                if (EditorGUI.EndChangeCheck())
                {
                    if (min > max && max == m_Max)
                    {
                        min = max;
                    }
                    if (max < min && min == m_Min)
                    {
                        max = min;
                    }
                    min = min < attr.min? attr.min: min;
                    max = max > attr.max? attr.max: max;

                    range.x = min;
                    range.y = max;
                    property.vector2Value = range;
                    m_Max = max;
                    m_Min = min;
                }
            }
            else
            {
                EditorGUI.LabelField(position, label, "Only useable with Vector2");
            }
        }
    void SetWindSetArtistTool()
    {
        VisualElement root = rootVisualElement;

        root.Clear();
        //Loads and clones our VisualTree inside the root.
        VisualTreeAsset quickToolVisualTree = Resources.Load <VisualTreeAsset>("WindArtistTool");

        quickToolVisualTree.CloneTree(root);
        root.styleSheets.Add(Resources.Load <StyleSheet>("WindArtistTool"));



        #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

        root.Q <Button>(name: "SaveButton").clicked  += SaveButton;
        root.Q <Button>(name: "ResetButton").clicked += ResetToInitialSceneValues;
    }
Ejemplo n.º 10
0
    void ChangeWindStrength(ChangeEvent <Vector2> evt)
    {
        VisualElement root           = rootVisualElement;
        MinMaxSlider  minMaxStrength = root.Q <MinMaxSlider>(name: "WindStrength");

        float minValue;
        float maxValue;

        minValue = minMaxStrength.minValue;
        maxValue = minMaxStrength.maxValue;
        SetWindStrength(minValue, maxValue);
        root.Q <VisualElement>(name: "WinStrengthHolder").Q <Label>(name: "MinValue").text = "Min Value :" + minMaxStrength.minValue;
        root.Q <VisualElement>(name: "WinStrengthHolder").Q <Label>(name: "MaxValue").text = "Max Value :" + minMaxStrength.maxValue;
    }
        void DrawVector2Int(Rect position, SerializedProperty property, GUIContent label)
        {
            Vector2Int range = property.vector2IntValue;
            float      min   = range.x;
            float      max   = range.y;

            float space      = 5;
            float labelWidth = position.width * 0.38f;
            float valueWidth = 50;

            float labelPos = position.x;
            float minPos   = labelPos + labelWidth + space;
            float maxPos   = position.x + position.width - valueWidth;

            float sliderPos   = minPos + valueWidth + space;
            float sliderWidth = maxPos - sliderPos - space;

            Rect labelRect  = new Rect(labelPos, position.y, labelWidth, position.height);
            Rect minRect    = new Rect(minPos, position.y, valueWidth, position.height);
            Rect sliderRect = new Rect(sliderPos, position.y, sliderWidth, position.height);
            Rect maxRect    = new Rect(maxPos, position.y, valueWidth, position.height);

            MinMaxSlider attr = attribute as MinMaxSlider;

            EditorGUI.BeginChangeCheck();
            EditorGUI.LabelField(labelRect, label);
            EditorGUI.indentLevel = 0;
            min = EditorGUI.IntField(minRect, range.x);
            max = EditorGUI.IntField(maxRect, range.y);
            EditorGUI.MinMaxSlider(sliderRect, ref min, ref max, attr.min, attr.max);
            if (EditorGUI.EndChangeCheck())
            {
                if (min > max && max == m_Max)
                {
                    min = max;
                }
                if (max < min && min == m_Min)
                {
                    max = min;
                }
                min = min < attr.min ? attr.min : min;
                max = max > attr.max ? attr.max : max;

                range.x = (int)min;
                range.y = (int)max;
                property.vector2IntValue = range;
                m_Max = max;
                m_Min = min;
            }
        }
Ejemplo n.º 12
0
        public MinMaxSliderControl(Vector2 value, float min, float max)
        {
            _slider = new MinMaxSlider(value.x, value.y, min, max);

            _minText = new FloatField();
            _minText.RegisterValueChangedCallback(evt => this.SendChangeEvent(evt.previousValue, evt.newValue));
            _minText.AddToClassList(TextUssClassName);

            _maxText = new FloatField();
            _maxText.RegisterValueChangedCallback(evt => this.SendChangeEvent(evt.previousValue, evt.newValue));
            _maxText.AddToClassList(TextUssClassName);

            Add(_minText);
            Setup(value);
            Add(_maxText);
        }
 public virtual void Set(int value, Color color, Color onDragColor, Vector3 scale, bool twoSliders, bool leftSlider, GameObject otherSliderObject = null)
 {
     _minMaxMargin        = 2.0f;
     _image               = transform.Find("Image").GetComponent <Image>();
     _index               = value;
     _image.color         = color;
     _initialColor        = color;
     _changedColor        = onDragColor;
     _rectTransform       = GetComponent <RectTransform>();
     transform.localScale = scale;
     _text                = transform.Find("Value").GetComponent <TextMeshProUGUI>();
     _twoSliders          = twoSliders;
     _leftSlider          = leftSlider;
     _otherSliderObject   = otherSliderObject;
     _parentSlider        = GetComponentInParent <MinMaxSlider>();
     _parentRectTransform = GetComponentInParent <RectTransform>();
 }
Ejemplo n.º 14
0
        public VFXMinMaxSliderField()
        {
            AddToClassList("sliderMinMaxField");
            m_Slider = new MinMaxSlider(1, 10, 0, 100);

            m_Slider.RegisterValueChangedCallback(evt => ValueChanged(evt.newValue));
            m_IndeterminateLabel = new Label()
            {
                name = "indeterminate",
                text = VFXControlConstants.indeterminateText
            };
            m_IndeterminateLabel.SetEnabled(false);
            m_Slider.RegisterValueChangedCallback(ValueChanged);

            Add(m_Slider);
            RegisterCallBack();
        }
Ejemplo n.º 15
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (property.propertyType == SerializedPropertyType.Vector2)
        {
            Vector2      range = property.vector2Value;
            float        min   = range.x;
            float        max   = range.y;
            MinMaxSlider attr  = attribute as MinMaxSlider;
            label.tooltip = string.Format("{0}, {1}", min, max);
            EditorGUI.BeginChangeCheck();
            EditorGUI.MinMaxSlider(label, position, ref min, ref max, attr.min, attr.max);

            position.xMin += EditorGUIUtility.labelWidth;
            position.yMin += EditorGUIUtility.singleLineHeight - EditorGUIUtility.standardVerticalSpacing;

            var fullWidth = position.width;
            var span      = attr.max - attr.min;
            var minPos    = fullWidth * (min - attr.min) / span;
            var maxPos    = fullWidth * (max - attr.min) / span;

            position.xMin += minPos;
            position.width = maxPos - minPos;

            var style = new GUIStyle(EditorStyles.miniLabel);
            style.alignment = TextAnchor.UpperLeft;
            EditorGUI.LabelField(position, min.ToString("0.00"), style);
            style.alignment = TextAnchor.UpperRight;
            EditorGUI.LabelField(position, max.ToString("0.00"), style);

            if (EditorGUI.EndChangeCheck())
            {
                range.x = min;
                range.y = max;
                property.vector2Value = range;
            }
        }
        else
        {
            EditorGUI.HelpBox(position, "Use MinMaxSlider only with type Vector2.", MessageType.Warning);
        }
    }
Ejemplo n.º 16
0
        internal override void Apply(VisualElement container)
        {
            /// <sample>
            // Get a reference to the field from UXML and assign it its value.
            var uxmlField = container.Q <MinMaxSlider>("the-uxml-field");

            uxmlField.value = new Vector2(10, 12);

            // Create a new field, disable it, and give it a style class.
            var csharpField = new MinMaxSlider("C# Field", 0, 20, -10, 40);

            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 <Vector2> >((evt) =>
            {
                csharpField.value = evt.newValue;
            });
            /// </sample>
        }
Ejemplo n.º 17
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;
    }
Ejemplo n.º 18
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 SliderChanged(MinMaxSlider slider)
 {
 }
    void ResetToInitialSceneValues()
    {
        VisualElement root = rootVisualElement;

        VisualElement SkyGradientVE = root.Q <VisualElement>(name: "SkyGradient");

        if (SkyGradientVE != null)
        {
            SkyGradientVE.Q <GradientField>().value = initialSceneValues.SkyGradient;
        }

        VisualElement RuinsGradientVE = root.Q <VisualElement>(name: "RuinsGradient");

        if (RuinsGradientVE != null)
        {
            RuinsGradientVE.Q <GradientField>().value = initialSceneValues.RuinsGradient;
        }

        VisualElement TreesGradientVE = root.Q <VisualElement>(name: "TreesGradient");

        if (TreesGradientVE != null)
        {
            TreesGradientVE.Q <GradientField>().value = initialSceneValues.TreesGradient;
        }

        VisualElement RimColorVE = root.Q <VisualElement>(name: "RimColor");

        if (RimColorVE != null)
        {
            RimColorVE.Q <GradientField>().value = initialSceneValues.RimGradient;
        }

        VisualElement SunlightVE = root.Q <VisualElement>(name: "Sunlight");

        if (SunlightVE != null)
        {
            if (SunlightVE.Q <VisualElement>(name: "LightGradient") != null)
            {
                SunlightVE.Q <VisualElement>(name: "LightGradient").Q <GradientField>().value = initialSceneValues.SunlightGradient;
            }
            SunlightVE.Q <FloatField>(name: "Intensity").value = initialSceneValues.SunlightIntencity;
        }

        VisualElement GrassLightVE = root.Q <VisualElement>(name: "GrassLight");

        if (GrassLightVE != null)
        {
            if (GrassLightVE.Q <VisualElement>(name: "LightGradient") != null)
            {
                GrassLightVE.Q <VisualElement>(name: "LightGradient").Q <GradientField>().value = initialSceneValues.GrassLightGradient;
            }
            GrassLightVE.Q <FloatField>(name: "Intensity").value = initialSceneValues.GrassLightIntensity;
        }

        VisualElement CaveHoleLightVE = root.Q <VisualElement>(name: "CaveHoleLight");

        if (CaveHoleLightVE != null)
        {
            CaveHoleLightVE.Q <FloatField>(name: "Falloff").value      = initialSceneValues.FalloffCaveHole;
            CaveHoleLightVE.Q <Slider>(name: "FalloffIntencity").value = initialSceneValues.FalloffIntensityCaveHole;
            CaveHoleLightVE.Q <VisualElement>(name: "FalloffIntencity").Q <FloatField>(name: "CurrentValue").value = initialSceneValues.FalloffIntensityCaveHole;
        }

        VisualElement WindVE = root.Q <VisualElement>(name: "Wind");

        if (WindVE != null)
        {
            Vector4Field WindDirection = WindVE.Q <Vector4Field>(name: "WindDirection");
            if (WindDirection != null)
            {
                WindDirection.value = initialSceneValues.WindDirection;
            }

            FloatField WindScale = WindVE.Q <FloatField>(name: "WindScale");
            if (WindScale != null)
            {
                WindScale.value = initialSceneValues.WindScale;
            }

            MinMaxSlider WindStrength = WindVE.Q <MinMaxSlider>(name: "WindStrength");
            if (WindStrength != null)
            {
                WindStrength.minValue = initialSceneValues.WindStrength.minValue;
                WindStrength.maxValue = initialSceneValues.WindStrength.maxValue;
            }
            VisualElement WinStrengthHolder = WindVE.Q <VisualElement>(name: "WinStrengthHolder");
            if (WinStrengthHolder != null)
            {
                WinStrengthHolder.Q <Label>(name: "MinValue").text = "Min Value :" + initialSceneValues.WindStrength.minValue;
                WinStrengthHolder.Q <Label>(name: "MaxValue").text = "Max Value :" + initialSceneValues.WindStrength.maxValue;
            }
            FloatField WindSpeed = WindVE.Q <FloatField>(name: "WindSpeed");
            if (WindSpeed != null)
            {
                WindSpeed.value = initialSceneValues.WindSpeed;
            }
        }

        VisualElement WhiteBalanceVE = root.Q <VisualElement>(name: "WhiteBalance");

        if (WhiteBalanceVE != null)
        {
            VisualElement whiteBalanceTemperature = WhiteBalanceVE.Q <VisualElement>(name: "Temperature");
            whiteBalanceTemperature.Q <Slider>(name: "SliderValue").value      = initialSceneValues.WhiteBalanceTemperature;
            whiteBalanceTemperature.Q <FloatField>(name: "CurrentValue").value = initialSceneValues.WhiteBalanceTemperature;

            VisualElement whiteBalanceTint = WhiteBalanceVE.Q <VisualElement>(name: "Tint");
            whiteBalanceTint.Q <Slider>(name: "SliderValue").value      = initialSceneValues.WhiteBalanceTint;
            whiteBalanceTint.Q <FloatField>(name: "CurrentValue").value = initialSceneValues.WhiteBalanceTint;
        }

        VisualElement BloomVE = root.Q <VisualElement>(name: "Bloom");

        if (BloomVE != null)
        {
            BloomVE.Q <ColorField>(name: "Tint").value      = initialSceneValues.BloomTint;
            BloomVE.Q <FloatField>(name: "Intensity").value = initialSceneValues.BloomIntensity;
        }
        VisualElement VFXVisualElement = root.Q <VisualElement>(name: "VFX");

        if (VFXVisualElement != null)
        {
            VFXVisualElement.Q <FloatField>(name: "Emission").value = initialSceneValues.GlowParticleEmission;
            VFXVisualElement.Q <EnumField>(name: "RenderMode").Init(initialSceneValues.GlowParticlesRenderMode);
            SetRenderMaterial(initialSceneValues.GlowParticleRenderMaterial);
        }
    }
Ejemplo n.º 21
0
    public override void DrawEditor()
    {
        #region VisualElement
        VisualElement visualElement = new VisualElement();
        visualElement.name                  = "inline-csharp-visual-element";
        visualElement.style.marginTop       = 6;
        visualElement.style.marginBottom    = 3;
        visualElement.style.marginLeft      = 6;
        visualElement.style.marginRight     = 6;
        visualElement.style.flexDirection   = FlexDirection.Row;
        visualElement.style.backgroundColor = Color.white;
        visualElement.style.color           = Color.gray;
        #endregion

        #region Label
        Label label = new Label();
        label.text           = "Inline C# label";
        label.style.fontSize = 16;
        label.style.unityFontStyleAndWeight = FontStyle.Bold;
        label.style.backgroundColor         = Color.yellow;
        label.style.borderBottomLeftRadius  = 15;
        label.style.borderBottomRightRadius = 15;
        label.style.borderTopLeftRadius     = 15;
        label.style.borderTopRightRadius    = 15;
        label.style.paddingLeft             = 10;
        label.style.width        = 160;
        label.style.height       = 20;
        label.style.marginLeft   = 6;
        label.style.marginTop    = 6;
        label.style.marginBottom = 5;
        visualElement.Add(label);
        #endregion

        #region TextField
        TextField textField = new TextField();
        textField.value = "Textfield value";
        textField.style.backgroundColor = Color.cyan;
        textField.style.fontSize        = 15;
        textField.style.marginLeft      = 3;
        textField.style.marginTop       = 3;
        textField.style.marginBottom    = 3;
        textField.style.marginRight     = 3;
        textField.style.height          = 25;
        textField.style.flexGrow        = 1;
        visualElement.Add(textField);
        #endregion

        #region IntegerField
        IntegerField integerField = new IntegerField();
        integerField.value                   = 1144;
        integerField.style.fontSize          = 14;
        integerField.style.height            = 25;
        integerField.style.backgroundColor   = Color.blue;
        integerField.style.marginTop         = 3;
        integerField.style.marginRight       = 3;
        integerField.style.borderLeftWidth   = 3;
        integerField.style.borderRightWidth  = 3;
        integerField.style.borderTopWidth    = 3;
        integerField.style.borderBottomWidth = 3;
        integerField.style.minWidth          = 100;
        visualElement.Add(integerField);
        #endregion

        #region VisualElement2
        VisualElement visualElement2 = new VisualElement();
        visualElement2.style.marginTop       = 0;
        visualElement2.style.marginBottom    = 6;
        visualElement2.style.marginLeft      = 6;
        visualElement2.style.marginRight     = 6;
        visualElement2.style.flexDirection   = FlexDirection.Row;
        visualElement2.style.backgroundColor = Color.white;
        visualElement2.style.color           = Color.gray;
        #endregion

        #region Buttons

        Button button = new Button();
        button.text               = "Click me!";
        button.style.marginLeft   = 5;
        button.style.marginBottom = 3;
        button.style.marginTop    = 3;
        button.style.height       = 25;
        button.style.width        = 100;
        visualElement2.Add(button);

        Button button2 = new Button();
        button2.text               = "Font size: 14";
        button2.style.marginLeft   = 5;
        button2.style.marginBottom = 3;
        button2.style.marginTop    = 3;
        button2.style.height       = 25;
        button2.style.width        = 140;
        button2.style.fontSize     = 14;
        visualElement2.Add(button2);

        #endregion

        #region VisualElement3
        VisualElement visualElement3 = new VisualElement();
        visualElement3.style.marginTop       = 0;
        visualElement3.style.marginBottom    = 6;
        visualElement3.style.marginLeft      = 6;
        visualElement3.style.marginRight     = 6;
        visualElement3.style.flexDirection   = FlexDirection.Row;
        visualElement3.style.backgroundColor = Color.green;
        visualElement3.style.color           = Color.gray;
        #endregion

        //Foldout foldout = new Foldout();
        //foldout.text = "Foldout";
        //visualElement3.Add(foldout);

        MinMaxSlider minMaxSlider = new MinMaxSlider();
        minMaxSlider.label       = "MinMaxSlider example";
        minMaxSlider.lowLimit    = 0;
        minMaxSlider.highLimit   = 100;
        minMaxSlider.minValue    = 20;
        minMaxSlider.maxValue    = 45;
        minMaxSlider.style.width = 300;
        visualElement3.Add(minMaxSlider);

        #region VisualElement4
        VisualElement visualElement4 = new VisualElement();
        visualElement4.style.marginTop       = 0;
        visualElement4.style.marginBottom    = 6;
        visualElement4.style.marginLeft      = 6;
        visualElement4.style.marginRight     = 6;
        visualElement4.style.flexDirection   = FlexDirection.Row;
        visualElement4.style.backgroundColor = Color.magenta;
        visualElement4.style.color           = Color.gray;
        #endregion



        root.Add(visualElement);
        root.Add(visualElement2);
        root.Add(visualElement3);
        root.Add(visualElement4);
    }
Ejemplo n.º 22
0
        public override void Enable(bool fromInspector)
        {
            levelsNode = nodeTarget as Levels;

            base.Enable(fromInspector);

            var slider = new MinMaxSlider("Luminance", levelsNode.min, levelsNode.max, 0, 1);

            sliders.Add(slider);
            slider.RegisterValueChangedCallback(e => {
                owner.RegisterCompleteObjectUndo("Changed Luminance remap");
                levelsNode.min = e.newValue.x;
                levelsNode.max = e.newValue.y;
                foreach (var s in sliders)
                {
                    if (s != null && s.parent != null)
                    {
                        s.SetValueWithoutNotify(e.newValue);
                    }
                }
                NotifyNodeChanged();
            });
            controlsContainer.Add(slider);

            var mode = this.Q <EnumField>();

            mode.RegisterValueChangedCallback((m) => {
                UpdateMinMaxSliderVisibility((Levels.Mode)m.newValue);
            });
            UpdateMinMaxSliderVisibility(levelsNode.mode);

            // Compute histogram only when the inspector is selected
            if (fromInspector)
            {
                owner.graph.afterCommandBufferExecuted += UpdateHistogram;
                controlsContainer.RegisterCallback <DetachFromPanelEvent>(e => {
                    owner.graph.afterCommandBufferExecuted -= UpdateHistogram;
                });
            }

            void UpdateHistogram()
            {
                if (levelsNode.output != null)
                {
                    var cmd = CommandBufferPool.Get("Update Histogram");
                    HistogramUtility.ComputeHistogram(cmd, levelsNode.output, levelsNode.histogramData);
                    Graphics.ExecuteCommandBuffer(cmd);
                }
            }

            UpdateHistogram();

            void UpdateMinMaxSliderVisibility(Levels.Mode mode)
            {
                if (mode == Levels.Mode.Automatic)
                {
                    slider.style.display = DisplayStyle.None;
                }
                else
                {
                    slider.style.display = DisplayStyle.Flex;
                }
            }

            if (fromInspector)
            {
                var histogram = new HistogramView(levelsNode.histogramData, owner);
                controlsContainer.Add(histogram);
            }
        }