コード例 #1
0
ファイル: ColorPicker.cs プロジェクト: zjwmyl/UnityCodes
        /// <summary>
        /// get color from mixed cts
        /// </summary>
        /// <param name="noniusPos"></param>
        /// <returns></returns>
        private Color mixedTwoColoredTapeColor(Vector2 noniusPos)
        {
            Color first  = m_firstLayerCT.GetColor(noniusPos);
            Color second = m_secondLayerCT.GetColor(noniusPos);
            float alpha  = second.a;
            Color result = Color.white;

            switch (PaletteMode)
            {
            case E_PaletteMode.Hue:
                result = new Color(second.r, second.g, second.b) * alpha +
                         new Color(first.r, first.g, first.b) * (1 - alpha);
                result.a = Color.a;
                break;

            case E_PaletteMode.Saturation:
                result = new Color(second.r, second.g, second.b) * alpha +
                         new Color(first.r, first.g, first.b) * (1 - alpha);
                result.a = Color.a;
                break;

            case E_PaletteMode.Brightness:
                result = new Color(second.r, second.g, second.b) * (alpha) +
                         new Color(first.r, first.g, first.b) * (1 - alpha);
                result.a = Color.a;
                break;
            }
            return(result);
        }
コード例 #2
0
ファイル: ColorPicker.cs プロジェクト: zjwmyl/UnityCodes
        /// <summary>
        /// set color by slider
        /// </summary>
        /// <param name="value"></param>
        private void verticalSliderChanged(float value)
        {
            float height = m_verticalFirstCT.transform.GetComponent <RectTransform>().sizeDelta.y;

            switch (ColorMode)
            {
            case E_ColorMode.RGB:
                switch (PaletteMode)
                {
                case E_PaletteMode.Hue:
                    Color color = m_verticalFirstCT.GetColor(new Vector2(0, height * (1 - value) - height / 2.0f));
                    changedFirstLayerColoredTape(color);
                    Color = mixedTwoColoredTapeColor(m_nonius.localPosition);
                    break;

                case E_PaletteMode.Saturation:
                    m_secondLayerCT.SetColors(new Color[]
                    {
                        new Color(0, 0, 0, 0) * (1 - value) + new Color(1, 1, 1, 1) * (value),
                        new Color(0, 0, 0, 1),
                    });
                    Color = mixedTwoColoredTapeColor(m_nonius.localPosition);
                    break;

                case E_PaletteMode.Brightness:
                    m_secondLayerCT.SetColors(new Color[]
                    {
                        new Color(1, 1, 1, 0) * (1 - value) + new Color(0, 0, 0, 1) * (value),
                        new Color(1, 1, 1, 1) * (1 - value) + new Color(0, 0, 0, 1) * (value)
                    });
                    Color = mixedTwoColoredTapeColor(m_nonius.localPosition);
                    break;

                case E_PaletteMode.Red:
                    var redTL = m_multiCT.TopLeft;
                    var redTR = m_multiCT.TopRight;
                    var redBL = m_multiCT.BottomLeft;
                    var redBR = m_multiCT.BottomRight;
                    redTL.r = 1 - value;
                    redTR.r = 1 - value;
                    redBL.r = 1 - value;
                    redBR.r = 1 - value;
                    m_multiCT.SetColors(new Color[] { redTL, redTR, redBL, redBR });
                    setRedSliderValue(1 - value);
                    var temp1 = m_multiCT.GetColor(m_nonius.localPosition);
                    Color = new Color(1 - value, temp1.g, temp1.b, Color.a);
                    break;

                case E_PaletteMode.Green:
                    var greenTL = m_multiCT.TopLeft;
                    var greenTR = m_multiCT.TopRight;
                    var greenBL = m_multiCT.BottomLeft;
                    var greenBR = m_multiCT.BottomRight;
                    greenTL.g = 1 - value;
                    greenTR.g = 1 - value;
                    greenBL.g = 1 - value;
                    greenBR.g = 1 - value;
                    m_multiCT.SetColors(new Color[] { greenTL, greenTR, greenBL, greenBR });
                    setGreenSliderValue(1 - value);
                    var temp2 = m_multiCT.GetColor(m_nonius.localPosition);
                    Color = new Color(temp2.r, 1 - value, temp2.b, Color.a);
                    break;

                case E_PaletteMode.Blue:
                    var blueTL = m_multiCT.TopLeft;
                    var blueTR = m_multiCT.TopRight;
                    var blueBL = m_multiCT.BottomLeft;
                    var blueBR = m_multiCT.BottomRight;
                    blueTL.b = 1 - value;
                    blueTR.b = 1 - value;
                    blueBL.b = 1 - value;
                    blueBR.b = 1 - value;
                    m_multiCT.SetColors(new Color[] { blueTL, blueTR, blueBL, blueBR });
                    setBlueSliderValue(1 - value);
                    var temp3 = m_multiCT.GetColor(m_nonius.localPosition);
                    Color = new Color(temp3.r, temp3.g, 1 - value, Color.a);
                    break;
                }
                break;

            case E_ColorMode.HSV:
                switch (PaletteMode)
                {
                case E_PaletteMode.Hue:
                    //todo
                    break;

                case E_PaletteMode.Saturation:
                    //todo
                    break;

                case E_PaletteMode.Brightness:
                    //todo
                    break;

                case E_PaletteMode.Red:
                    //todo
                    break;

                case E_PaletteMode.Green:
                    //todo
                    break;

                case E_PaletteMode.Blue:
                    //todo
                    break;
                }
                break;
            }
        }