/// <summary> /// change color mode /// </summary> private void ChangeColorMode() { ColorMode = (int)++ColorMode > 1 ? 0 : ColorMode++; switch (ColorMode) { case E_ColorMode.RGB: m_rText.text = R; m_gText.text = G; m_bText.text = B; SetRGBA(); break; case E_ColorMode.HSV: m_rText.text = H; m_gText.text = S; m_bText.text = V; m_rColoredTape.SetColors(SEVENCOLOR); var red = Color.r; var green = Color.g; var blue = Color.b; var maxValue = red; if (blue > maxValue) { maxValue = blue; } if (green > maxValue) { maxValue = green; } if (maxValue.Equals(red)) { m_gColoredTape.SetColors(new Color[] { Color.white, Color.red }); m_bColoredTape.SetColors(new Color[] { Color.black, Color.red }); } else if (maxValue.Equals(green)) { m_gColoredTape.SetColors(new Color[] { Color.white, Color.green }); m_bColoredTape.SetColors(new Color[] { Color.black, Color.green }); } else { m_gColoredTape.SetColors(new Color[] { Color.white, Color.blue }); m_bColoredTape.SetColors(new Color[] { Color.black, Color.blue }); } break; } }
/// <summary> /// get nonius position by color /// </summary> /// <param name="color0"></param> /// <returns></returns> private Vector2 getPositionByMixedCT(Color color0) { var result = Vector2.zero; var size = m_colorPalette.GetComponent <RectTransform>().sizeDelta; switch (PaletteMode) { case E_PaletteMode.Hue: break; case E_PaletteMode.Saturation: var x1 = m_firstLayerCT.GetPosition(color0).x; var red1 = color0.r; var green1 = color0.g; var blue1 = color0.b; ArrayList array1 = new ArrayList() { red1, green1, blue1 }; array1.Sort(); Color mainColor1; if (array1[0].Equals(red1)) { mainColor1 = new Color(0, green1, blue1, 1); } else if (array1[0].Equals(green1)) { mainColor1 = new Color(red1, 0, blue1, 1); } else { mainColor1 = new Color(red1, green1, 0, 1); } m_verticalFirstCT.SetColors(new Color[] { mainColor1, Color.white }); m_secondLayerCT.SetColors(new Color[] { new Color(0, 0, 0, 0) * (1 - (float)array1[0]) + new Color(1, 1, 1, 1) * ((float)array1[0]), Color.black }); setValueForVerticalSlider((float)array1[0]); float y1 = (1 - (float)array1[0]) * size.y - size.y / 2.0f; result = new Vector2(x1, y1); break; case E_PaletteMode.Brightness: var x2 = m_firstLayerCT.GetPosition(color0).x; var red2 = color0.r; var green2 = color0.g; var blue2 = color0.b; ArrayList array2 = new ArrayList() { red2, green2, blue2 }; array2.Sort(); Color mainColor2; if (array2[0].Equals(red2)) { mainColor2 = new Color(0, green2, blue2, 1); } else if (array2[0].Equals(green2)) { mainColor2 = new Color(red2, 0, blue2, 1); } else { mainColor2 = new Color(red2, green2, 0, 1); } m_verticalFirstCT.SetColors(new Color[] { mainColor2, Color.black }); m_secondLayerCT.SetColors(new Color[] { new Color(1, 1, 1, (float)array2[0]), Color.white }); setValueForVerticalSlider((float)array2[0]); float y2 = (1 - (float)array2[0]) * size.y - size.y / 2.0f; result = new Vector2(x2, y2); break; } return(result); }
/// <summary> /// vetify first ct color /// </summary> /// <param name="color"></param> private void changedFirstLayerColoredTape(Color color) { m_firstLayerCT.SetColors(new Color[] { Color.white, color }); }
/// <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; } }