Esempio n. 1
0
    private BufferedColor PickColor1D(BufferedColor color, PickerType type, Vector2 v)
    {
        bool  horizontal = IsHorizontal(pickerImages[(int)type]);
        float value      = horizontal ? v.x : v.y;

        return(PickColor1D(color, type, value));
    }
Esempio n. 2
0
    private void UpdateTexture(PickerType type, bool standardized)
    {
        Image image = GetImage((int)type);

        if (!image || !image.gameObject.activeInHierarchy)
        {
            return;
        }

        Material m = image.materialForRendering;

        BufferedColor bc = this.bufferedColor;

        if (standardized)
        {
            switch (type)
            {
            case PickerType.S:
                bc = new BufferedColor(Color.red);
                break;

            case PickerType.Preview:
            case PickerType.PreviewAlpha: break;

            default:
                bc = new BufferedColor(Color.black);
                break;
            }
        }

        bool alpha = IsAlphaType(type);

        m.SetInt("_Mode", GetGradientMode(type));
        Color c1 = PickColor(bc, type, Vector2.zero).color;
        Color c2 = PickColor(bc, type, Vector2.one).color;

        if (!alpha)
        {
            c1 = new Color(c1.r, c1.g, c1.b);
            c2 = new Color(c2.r, c2.g, c2.b);
        }

        m.SetColor("_Color1", c1);
        m.SetColor("_Color2", c2);
        if (type == PickerType.Main)
        {
            m.SetInt("_DoubleMode", (int)mode);
        }
        if (standardized)
        {
            m.SetVector("_HSV", new Vector4(0f, 1f, 1f, 1f));
        }
        else
        {
            m.SetVector("_HSV", new Vector4(bc.h / HUE_LOOP, bc.s, bc.v, alpha ? bc.a : 1f));
        }
    }
    private void OnEnable()
    {
        if (this.bufferedColor == null)
        {
            this.bufferedColor = new BufferedColor(startingColor);
        }

        pickerTexturesStandardized = staticMode;
        UpdateTextures(true);
        MakeModeOptions();
        UpdateMarkers();
    }
    /// <summary>
    /// Update color based on the pointer position in the currently focused picker.
    /// </summary>
    /// <param name="e">Pointer event</param>
    public void PointerUpdate(BaseEventData e)
    {
        Vector2 v = GetNormalizedPointerPosition(canvas, focusedPicker.rectTransform, e);

        this.bufferedColor = PickColor(this.bufferedColor, focusedPickerType, v);

        UpdateMarkers();
        UpdateTextures();

        typeUpdate = true;
        UpdateHex();
    }
    /*----------------------------------------------------------
     * --------------------- COLOR PICKING ----------------------
     * ----------------------------------------------------------
     *
     * Get a new color that is the currently selected color but with
     * one or two values changed. This is the core functionality of
     * the picking images and the entire color picker script.
     */


    /// <summary>
    /// Get a color that is the current color, but changed by the given picker and value.
    /// </summary>
    /// <param name="type">Picker type to base change on</param>
    /// <param name="v">normalized x and y values (both values may not be used)</param>
    private BufferedColor PickColor(BufferedColor color, PickerType type, Vector2 v)
    {
        switch (type)
        {
        case PickerType.Main: return(PickColorMain(color, v));

        case PickerType.Preview:
        case PickerType.PreviewAlpha:
            return(color);

        default: return(PickColor1D(color, type, v));
        }
    }
    private void OnEnable()
    {
        if (this.bufferedColor == null)
        {
            this.bufferedColor = new BufferedColor(startingColor);
        }

        if (multiInstance && !materialsSeperated)
        {
            SeperateMaterials();
            materialsSeperated = true;
        }
        pickerTexturesStandardized = staticMode;
        UpdateTextures(true);
        MakeModeOptions();
        UpdateMarkers();
    }
Esempio n. 7
0
    private void UpdateTexture(PickerType type, bool standardized)
    {
        RawImage image = GetImage((int)type);

        if (!image || !image.gameObject.activeInHierarchy)
        {
            return;
        }

        Texture2D tex    = (Texture2D)(image.texture);
        int       width  = tex.width;
        int       height = tex.height;

        Color[] pixels = new Color[width * height];

        for (int x = 0; x < width; x++)
        {
            float normX = (float)x / (width - 1);

            for (int y = 0; y < height; y++)
            {
                float   normY = (float)y / (height - 1);
                Vector2 v     = new Vector2(normX, normY);

                BufferedColor bc = this.bufferedColor;
                if (standardized)
                {
                    bc = GetDefaultColor(type);
                }
                bc = PickColor(bc, type, v);
                Color c = bc.color;

                if (!IsAlphaType(type))
                {
                    c.a = 1f;
                }

                int pixelIndex = x + y * width;
                pixels[pixelIndex] = c;
            }
        }

        tex.SetPixels(pixels);
        tex.Apply();
    }
Esempio n. 8
0
    private void UpdateDynamic(PickerType type)
    {
        if (!IsPickerAvailable(type))
        {
            return;
        }
        Picker p = pickers[(int)type];

        if (p.dynamicMaterial == null)
        {
            return;
        }

        Material m = p.dynamicMaterial;

        p.image.material = m;
        p.image.color    = Color.white;
        p.image.sprite   = p.dynamicSprite;

        BufferedColor bc = this.bufferedColor;

        bool alpha = IsAlphaType(type);

        m.SetInt(SHADER_MODE, GetGradientMode(type));
        Color c1 = PickColor(bc, type, Vector2.zero).color;
        Color c2 = PickColor(bc, type, Vector2.one).color;

        if (!alpha)
        {
            c1 = new Color(c1.r, c1.g, c1.b);
            c2 = new Color(c2.r, c2.g, c2.b);
        }
        m.SetColor(SHADER_C1, c1);
        m.SetColor(SHADER_C2, c2);
        if (type == PickerType.Main)
        {
            m.SetInt(SHADER_DOUBLE_MODE, (int)mode);
        }
        else
        {
            m.SetVector(SHADER_HSV, new Vector4(bc.h / HUE_LOOP, bc.s, bc.v, alpha ? bc.a : 1f));
        }
    }
    private BufferedColor PickColorMain(BufferedColor color, MainPickingMode mode, Vector2 v)
    {
        switch (mode)
        {
        case MainPickingMode.HS: return(PickColor2D(color, PickerType.H, v.x, PickerType.S, v.y));

        case MainPickingMode.HV: return(PickColor2D(color, PickerType.H, v.x, PickerType.V, v.y));

        case MainPickingMode.SH: return(PickColor2D(color, PickerType.S, v.x, PickerType.H, v.y));

        case MainPickingMode.SV: return(PickColor2D(color, PickerType.S, v.x, PickerType.V, v.y));

        case MainPickingMode.VH: return(PickColor2D(color, PickerType.V, v.x, PickerType.H, v.y));

        case MainPickingMode.VS: return(PickColor2D(color, PickerType.V, v.x, PickerType.S, v.y));

        default: return(this.bufferedColor);
        }
    }
    private BufferedColor PickColor1D(BufferedColor color, PickerType type, float value)
    {
        switch (type)
        {
        case PickerType.R: return(color.PickR(value));

        case PickerType.G: return(color.PickG(value));

        case PickerType.B: return(color.PickB(value));

        case PickerType.H: return(color.PickH(value * HUE_LOOP));

        case PickerType.S: return(color.PickS(value));

        case PickerType.V: return(color.PickV(value));

        case PickerType.A: return(color.PickA(value));

        default:
            throw new Exception("Picker type " + type + " is not associated with a single color value.");
        }
    }
    private BufferedColor PickColor1D(BufferedColor color, PickerType type, float value)
    {
        switch (type)
        {
        case PickerType.R: return(color.PickR(Mathf.Lerp(AS.r.min, AS.r.max, value)));

        case PickerType.G: return(color.PickG(Mathf.Lerp(AS.g.min, AS.g.max, value)));

        case PickerType.B: return(color.PickB(Mathf.Lerp(AS.b.min, AS.b.max, value)));

        case PickerType.H: return(color.PickH(Mathf.Lerp(AS.h.min, AS.h.max, value) * HUE_LOOP));

        case PickerType.S: return(color.PickS(Mathf.Lerp(AS.s.min, AS.s.max, value)));

        case PickerType.V: return(color.PickV(Mathf.Lerp(AS.v.min, AS.v.max, value)));

        case PickerType.A: return(color.PickA(Mathf.Lerp(AS.a.min, AS.a.max, value)));

        default:
            throw new Exception("Picker type " + type + " is not associated with a single color value.");
        }
    }
 public BufferedColor(Color color, BufferedColor source) :
     this(color, source.bufferedHue, source.bufferedSaturation)
 {
     this.Set(color);
 }
Esempio n. 13
0
 /// <summary>
 /// Create buffered color based on the source as a default
 /// for hue and sat values, then overwrites any values as needed.
 /// </summary>
 public BufferedColor(Color color, BufferedColor source) :
     this(color, source.H, source.S)
 {
     this.Set(color);
 }
    /*----------------------------------------------------------
     * ------------------------- UPKEEP -------------------------
     * ----------------------------------------------------------
     */

    private void Start()
    {
        this.bufferedColor = new BufferedColor(startingColor);
        canvas             = GetComponentInParent <Canvas>();
    }
 private BufferedColor PickColor2D(BufferedColor color, PickerType type1, float value1, PickerType type2, float value2)
 {
     color = PickColor1D(color, type1, value1);
     color = PickColor1D(color, type2, value2);
     return(color);
 }
 private BufferedColor PickColorMain(BufferedColor color, Vector2 v)
 {
     return(PickColorMain(color, this.mode, v));
 }
    /*----------------------------------------------------------
     * ------------------------- UPKEEP -------------------------
     * ----------------------------------------------------------
     */

    private void Start()
    {
        this.bufferedColor = new BufferedColor(startingColor);
    }