Ejemplo n.º 1
0
        public static HMUI.Scrollbar CreateUISlider(RectTransform parent, float fromValue, float toValue, bool intValues, UnityAction <float> onValueChanged = null)
        {
            HMUI.Scrollbar     slider = Instantiate(Resources.FindObjectsOfTypeAll <HMUI.Scrollbar>().First(), parent, false);
            SliderProperties[] sps    = slider.gameObject.GetComponents <SliderProperties>();
            for (int i = 0; i < sps.Length; ++i)
            {
                Destroy(sps[i]);
            }
            SliderProperties sliderProperties = slider.gameObject.AddComponent <SliderProperties>();

            sliderProperties.FromValue = fromValue;
            sliderProperties.ToValue   = toValue;
            sliderProperties.IntValues = intValues;
            sliderProperties.SetCurrentValueFromPercentage(slider.value);

            slider.GetComponentInChildren <TextMeshProUGUI>().text = sliderProperties.CurrentValue.ToString("N1");
            slider.onValueChanged.AddListener(delegate(float value) {
                TextMeshProUGUI valueLabel    = slider.GetComponentInChildren <TextMeshProUGUI>();
                valueLabel.enableWordWrapping = false;
                sliderProperties.SetCurrentValueFromPercentage(value);
                valueLabel.text = sliderProperties.CurrentValue.ToString("N1");
            });
            if (onValueChanged != null)
            {
                slider.onValueChanged.AddListener(onValueChanged);
            }
            return(slider);
        }
Ejemplo n.º 2
0
 public override void Init()
 {
     _sliderInst           = transform.GetComponentInChildren <HMUI.Scrollbar>();
     _sliderPropertiesInst = _sliderInst.gameObject.GetComponent <SliderProperties>();
     _sliderPropertiesInst.CurrentValue = GetInitValue();
     _textInst         = _sliderInst.GetComponentInChildren <TMPro.TextMeshProUGUI>();
     _sliderInst.value = _sliderPropertiesInst.GetPercentageFromValue(_sliderPropertiesInst.CurrentValue);
     _sliderInst.onValueChanged.AddListener(delegate(float value) {
         _sliderPropertiesInst.SetCurrentValueFromPercentage(value);
         RefreshUI();
     });
     RefreshUI();
 }