Ejemplo n.º 1
0
        void Awake()
        {
            if (hsvSlider)
            {
                hsvSlider.texture = HSVUtil.GenerateHSVTexture((int)hsvSlider.rectTransform.rect.width, (int)hsvSlider.rectTransform.rect.height, minHue, maxHue);
            }

            if (sliderR)
            {
                sliderR.onValueChanged.AddListener(newValue =>
                {
                    if (isChanging)
                    {
                        return;
                    }
                    isChanging     = true;
                    r              = (byte)newValue;
                    currentColor.r = r;
                    AssignColor(currentColor);
                    sliderRText.text = "R:" + r;
                    if (hexrgb != null)
                    {
                        hexrgb.ManipulateViaRGB2Hex();
                    }
                    isChanging = false;
                });
            }

            if (sliderG)
            {
                sliderG.onValueChanged.AddListener(newValue =>
                {
                    if (isChanging)
                    {
                        return;
                    }
                    isChanging     = true;
                    g              = (byte)newValue;
                    currentColor.g = g;
                    AssignColor(currentColor);
                    sliderGText.text = "G:" + g;
                    if (hexrgb != null)
                    {
                        hexrgb.ManipulateViaRGB2Hex();
                    }
                    isChanging = false;
                });
            }

            if (sliderB)
            {
                sliderB.onValueChanged.AddListener(newValue =>
                {
                    if (isChanging)
                    {
                        return;
                    }
                    isChanging     = true;
                    b              = (byte)newValue;
                    currentColor.b = b;
                    AssignColor(currentColor);
                    sliderBText.text = "B:" + b;
                    if (hexrgb != null)
                    {
                        hexrgb.ManipulateViaRGB2Hex();
                    }
                    isChanging = false;
                });
            }

            if (hsvImage)
            {
                var startColor = Color.white;

                if (hsvSlider)
                {
                    startColor = ((Texture2D)hsvSlider.texture).GetPixelBilinear(0, 0.035f);
                }

                hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.width, startColor, minHue, maxHue, minSat, maxSat, minV, maxV);
            }

            MoveCursor(cursorX, cursorY);

            sliderPicker.SetSliderPosition(1f - pointerPos);
        }
Ejemplo n.º 2
0
        public Color MovePointer(float newPos, bool updateInputs = true)
        {
            newPos = Mathf.Clamp(1f - newPos, 0.05f, 0.99f);

            /*
             * if (newPos > 1)
             * {
             * newPos %= 1f;
             * }
             */

            pointerPos = newPos;

            var mainColor = ((Texture2D)hsvSlider.texture).GetPixelBilinear(0, pointerPos);

            if (hsvImage && hsvImage.texture != null)
            {
                if ((int)hsvImage.rectTransform.rect.width != hsvImage.texture.width || (int)hsvImage.rectTransform.rect.height != hsvImage.texture.height)
                {
                    Destroy(hsvImage.texture);
                    hsvImage.texture = null;

                    hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, mainColor, minHue, maxHue, minSat, maxSat, minV, maxV);
                }
                else
                {
                    HSVUtil.GenerateColorTexture(mainColor, (Texture2D)hsvImage.texture, minHue, maxHue, minSat, maxSat, minV, maxV);
                }
            }
            else
            {
                hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, mainColor, minHue, maxHue, minSat, maxSat, minV, maxV);
            }

            //sliderPicker.SetSliderPosition(pointerPos);

            if (isChanging)
            {
                return(currentColor);
            }
            isChanging = true;

            currentColor     = GetColor(cursorX, cursorY);
            colorImage.color = currentColor;
            r = currentColor.r;
            g = currentColor.g;
            b = currentColor.b;

            if (updateInputs)
            {
                UpdateInputs();
                onValueChanged.Invoke(currentColor);

                if (hexrgb != null)
                {
                    hexrgb.ManipulateViaRGB2Hex();
                }
            }
            isChanging = false;
            return(currentColor);
        }