Ejemplo n.º 1
0
        public void ChangeColor(Color colorToEdit)
        {
            currentColor = colorToEdit;
            savedColor   = colorToEdit;
            prevColor    = colorToEdit;

            aValue = currentColor.a * 255f;
            rValue = currentColor.r * 255f;
            gValue = currentColor.g * 255f;
            bValue = currentColor.b * 255f;

            aText = aValue.ToString("F0");
            rText = rValue.ToString("F0");
            gText = gValue.ToString("F0");
            bText = bValue.ToString("F0");

            currentHSVColor = new HSBColor(currentColor);
            prevHSVColor    = new HSBColor(currentColor);

            GenerateTextures();
            rainbow        = MaterialUtils.GenerateRainbowGradient(120, 20);
            aTexture       = MaterialUtils.GenerateGradientTexture(100, 20, Color.black, Color.white);
            colorField     = MaterialUtils.GenerateColorField(colorFieldSize, colorFieldSize, currentHSVColor.ToColor());
            WindowPosition = new Rect(Screen.width / 2 - 100, Screen.height / 2f, 210, 100);
            showWindow     = true;
        }
Ejemplo n.º 2
0
        protected void DrawColorField()
        {
            GUILayout.BeginVertical();
            GUILayout.Space(4);
            Rect tRect = GUILayoutUtility.GetRect(120, 20, GUILayout.Width(sliderWidth));

            GUI.DrawTexture(tRect, swatch);
            GUILayout.Space(4);
            tRect = GUILayoutUtility.GetRect(150, 20, GUILayout.Width(sliderWidth));
            GUI.DrawTexture(tRect, rainbow);
            hueValue        = GUILayout.HorizontalSlider(hueValue, 0f, 1f, GUILayout.Width(sliderWidth));
            currentHSVColor = new HSBColor(hueValue, currentHSVColor.s, currentHSVColor.b);
            tRect           = GUILayoutUtility.GetRect(colorFieldSize, colorFieldSize, GUILayout.Width(colorFieldSize));
            GUI.DrawTexture(tRect, colorField);

            var eventType = Event.current.type;

            if (eventType == EventType.Repaint)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Vector2 screenPoint = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
                    Rect    screenRect  = GUIUtility.GUIToScreenRect(tRect);


                    if (tRect.Contains(Event.current.mousePosition))
                    {
                        int   x       = (int)Mathf.Clamp(Event.current.mousePosition.x - tRect.xMin, 0, sliderWidth);
                        int   y       = colorFieldSize - (int)Mathf.Clamp(Event.current.mousePosition.y - tRect.yMin, 0, sliderWidth);
                        Color sampled = ((Texture2D)colorField).GetPixel(x, y);
                        Utils.Log($"Color picked at {x}, {y} is {sampled}");
                        currentHSVColor = new HSBColor(sampled);
                        currentColor    = new Color(sampled.r, sampled.g, sampled.b, currentColor.a);
                        aValue          = currentColor.a * 255f;
                        rValue          = currentColor.r * 255f;
                        gValue          = currentColor.g * 255f;
                        bValue          = currentColor.b * 255f;

                        aText = aValue.ToString("F0");
                        rText = rValue.ToString("F0");
                        gText = gValue.ToString("F0");
                        bText = bValue.ToString("F0");
                    }
                }
            }

            GUILayout.EndVertical();
            GUILayout.Space(4);



            if (!currentHSVColor.ToColor().Equals(prevHSVColor.ToColor()))
            {
                colorField   = MaterialUtils.GenerateColorField(colorFieldSize, colorFieldSize, currentHSVColor.ToColor());
                prevHSVColor = currentHSVColor;
            }
        }
Ejemplo n.º 3
0
        public void Update()
        {
            if (!currentColor.Equals(prevColor))
            {
                GenerateTextures();

                currentHSVColor = new HSBColor(currentColor);
                hueValue        = currentHSVColor.h;
                colorField      = MaterialUtils.GenerateColorField(colorFieldSize, colorFieldSize, currentHSVColor.ToColor());
                prevColor       = currentColor;
            }
        }