コード例 #1
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.");
        }