Пример #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);
        }
Пример #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();
 }
Пример #3
0
        private new void Awake()
        {
            base.Awake();
            _ColorPickerBundle = UIUtilities.ColorPickerBundle;
            if (_ColorPickerBundle == null)
            {
                Console.WriteLine("[BeatSaberCustomUI.ColorPicker]: The loading of the 'ColorPicker.assetbundle' resulted into a failure, stopping the ColorPicker creation.");
                return;
            }

            //ColorPickerPreview initialization
            ColorPickerPreview = new GameObject("ColorPickerPreview").AddComponent <ColorPickerPreview>();
            if (ColorPickerPreview != null)
            {
                ColorPickerPreview.transform.SetParent(transform, false);
                (ColorPickerPreview.transform as RectTransform).sizeDelta = new Vector2(8.5f, 8.5f);
                ColorPickerPreview.transform.Translate(-40f, 35.5f, 0);
            }
            else
            {
                Console.WriteLine("[BeatSaberCustomUI.ColorPicker]: The 'ColorPickerPreview' instance was null.");
            }
            //ColorPickerCore initialization
            ColorPickerCore = new GameObject("ColorPickerCore").AddComponent <ColorPickerCore>();
            if (ColorPickerCore != null)
            {
                ColorPickerCore.ColorPickerPreview = ColorPickerPreview;
                ColorPickerCore.ColorPickerBundle  = _ColorPickerBundle;
                ColorPickerCore.Initialize();
                ColorPickerCore.transform.SetParent(transform, false);
                (ColorPickerCore.transform as RectTransform).sizeDelta = new Vector2(50, 50);
            }
            else
            {
                Console.WriteLine("[BeatSaberCustomUI.ColorPicker]: The 'ColorPickerCore' instance was null.");
            }

            //ColorPickerHue background initialization
            ColorPickerHueBG = new GameObject("ColorPickerHueBG").AddComponent <HMUI.Image>();
            if (ColorPickerHueBG != null)
            {
                ColorPickerHueBG.material = new Material(_ColorPickerBundle.LoadAsset <Shader>("HueSlider"));
                ColorPickerHueBG.transform.SetParent(transform, false);
                (ColorPickerHueBG.transform as RectTransform).sizeDelta = new Vector2(50, 7.5f);
                ColorPickerHueBG.transform.Translate(0, 35, 0);
            }
            else
            {
                Console.WriteLine("[BeatSaberCustomUI.ColorPicker]: The 'ColorPickerHueBG' instance was null.");
            }

            //ColorPickerHue slider initialization
            ColorPickerHueSlider = BeatSaberUI.CreateUISlider(transform as RectTransform, 0f, 1f, false, (float value) => {
                if (HueSliderProperties != null)
                {
                    HueSliderProperties.SetCurrentValueFromPercentage(value);
                }
                ColorPickerCore.ChangeColorPickerHue(value);
            });
            if (ColorPickerHueSlider != null)
            {
                HueSliderProperties                  = ColorPickerHueSlider.GetComponent <SliderProperties>();
                ColorPickerHueSlider.value           = 0f;
                ColorPickerHueSlider.gameObject.name = "ColorPickerHueSlider";
                ColorPickerHueSlider.transform.SetParent(transform, false);
                (ColorPickerHueSlider.transform as RectTransform).sizeDelta        = new Vector2(54, 7.5f);
                (ColorPickerHueSlider.transform as RectTransform).anchoredPosition = new Vector2(0, -2f);
                ColorPickerHueSlider.transform.Translate(0, 37f, -0.00001f);
                ColorPickerHueSlider.GetComponent <Image>().color = new Color(0, 0, 0, 0);
                ColorPickerHueSlider.transform.Find("SlidingArea/Handle").GetComponent <Image>().color = new Color(1, 1, 1, 1);
                ColorPickerHueSlider.GetComponentInChildren <TMPro.TextMeshProUGUI>().color            = new Color(1, 1, 1, 0);
            }
            else
            {
                Console.WriteLine("[BeatSaberCustomUI.ColorPicker]: The 'ColorPickerHueSlider' instance was null.");
            }

            Console.WriteLine("[BeatSaberCustomUI.ColorPicker]: ColorPicker awake done.");
        }