示例#1
0
        public Scroller(float lowValue, float highValue, System.Action <float> valueChanged, SliderDirection direction = SliderDirection.Vertical)
        {
            AddToClassList(ussClassName);

            // Add children in correct order
            slider = new Slider(lowValue, highValue, direction, kDefaultPageSize)
            {
                name = "unity-slider", viewDataKey = "Slider"
            };
            slider.AddToClassList(sliderUssClassName);
            slider.RegisterValueChangedCallback(OnSliderValueChange);

            lowButton = new RepeatButton(ScrollPageUp, ScrollWaitDefinitions.firstWait, ScrollWaitDefinitions.regularWait)
            {
                name = "unity-low-button"
            };
            lowButton.AddToClassList(lowButtonUssClassName);
            Add(lowButton);
            highButton = new RepeatButton(ScrollPageDown, ScrollWaitDefinitions.firstWait, ScrollWaitDefinitions.regularWait)
            {
                name = "unity-high-button"
            };
            highButton.AddToClassList(highButtonUssClassName);
            Add(highButton);
            Add(slider);

            this.direction    = direction;
            this.valueChanged = valueChanged;
        }
示例#2
0
        public Slider(
            float val,
            float min,
            float max,
            EventCallback <float> valueCB,
            EventCallback <float> minCB,
            EventCallback <float> maxCB
            )
        {
            ValueCallback = valueCB;
            MinCallback   = minCB;
            MaxCallback   = maxCB;

            Value = val;

            contentContainer.AddToClassList("bounded-float");
            contentContainer.AddToClassList("range");

            Range = new SliderFloat {
                highValue = max,
                lowValue  = min,
                value     = val
            };

            Min = new FloatField {
                value = min
            };
            Current = new FloatField {
                value = val
            };
            Max = new FloatField {
                value = max
            };

            Min.AddToClassList("min-value");
            Current.AddToClassList("current-value");
            Max.AddToClassList("max-value");

            var Fields = new VisualElement();

            Fields.AddToClassList("input-fields");

            Fields.Add(Min);
            Fields.Add(Current);
            Fields.Add(Max);

            contentContainer.Add(Range);
            contentContainer.Add(Fields);

            Range.RegisterValueChangedCallback(CurrentChanged);
            Min.RegisterValueChangedCallback(MinChanged);
            Current.RegisterValueChangedCallback(CurrentChanged);
            Max.RegisterValueChangedCallback(MaxChanged);
        }