public Color MovePointer(float newPos, bool updateInputs = true) { dontAssignUpdate = updateInputs; 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); } dontAssignUpdate = false; isChanging = false; return(currentColor); }
void Awake() { hsvSlider.texture = HSVUtil.GenerateHSVTexture((int)hsvSlider.rectTransform.rect.width, (int)hsvSlider.rectTransform.rect.height); sliderR.onValueChanged.AddListener(newValue => { if (isChanging) { return; } isChanging = true; r = (byte)newValue; currentColor.r = r; AssignColor(currentColor); sliderRText.text = "R:" + r; hexrgb.ManipulateViaRGB2Hex(); isChanging = false; }); sliderG.onValueChanged.AddListener(newValue => { if (isChanging) { return; } isChanging = true; g = (byte)newValue; currentColor.g = g; AssignColor(currentColor); sliderGText.text = "G:" + g; hexrgb.ManipulateViaRGB2Hex(); isChanging = false; }); sliderB.onValueChanged.AddListener(newValue => { if (isChanging) { return; } isChanging = true; b = (byte)newValue; currentColor.b = b; AssignColor(currentColor); sliderBText.text = "B:" + b; hexrgb.ManipulateViaRGB2Hex(); isChanging = false; }); hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, ((Texture2D)hsvSlider.texture).GetPixelBilinear(0, 0)); MoveCursor(cursorX, cursorY); }
public Color MovePointer(float newPos, bool updateInputs) { if (updateInputs == null) { updateInputs = true; } dontAssignUpdate = updateInputs; if (newPos > 1) { newPos %= 1f;//hsv } pointerPos = newPos; var mainColor = ((Texture2D)hsvSlider.texture).GetPixelBilinear(0, pointerPos); if (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); } else { HSVUtil.GenerateColorTexture(mainColor, (Texture2D)hsvImage.texture); } } else { hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, mainColor); } sliderPicker.SetSliderPosition(pointerPos); //pointer.rectTransform.anchoredPosition = new Vector2(0, -pointerPos * hsvSlider.rectTransform.rect.height); currentColor = GetColor(cursorX, cursorY); colorImage.color = currentColor; if (updateInputs) { UpdateInputs(); onValueChanged.Invoke(currentColor); } dontAssignUpdate = false; return(currentColor); }
void Awake() { hsvSlider.texture = HSVUtil.GenerateHSVTexture((int)hsvSlider.rectTransform.rect.width, (int)hsvSlider.rectTransform.rect.height); sliderR.onValueChanged.AddListener(newValue => { currentColor.r = newValue; if (dontAssignUpdate == false) { AssignColor(currentColor); } sliderRText.text = "R:" + Mathf.RoundToInt(currentColor.r * 255f); hexrgb.ManipulateViaRGB2Hex(); }); sliderG.onValueChanged.AddListener(newValue => { currentColor.g = newValue; if (dontAssignUpdate == false) { AssignColor(currentColor); } sliderGText.text = "G:" + Mathf.RoundToInt(currentColor.g * 255f); hexrgb.ManipulateViaRGB2Hex(); }); sliderB.onValueChanged.AddListener(newValue => { currentColor.b = newValue; if (dontAssignUpdate == false) { AssignColor(currentColor); } sliderBText.text = "B:" + Mathf.RoundToInt(currentColor.b * 255f); hexrgb.ManipulateViaRGB2Hex(); }); hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, ((Texture2D)hsvSlider.texture).GetPixelBilinear(0, 0)); MoveCursor(cursorX, cursorY); //ADDED By ED. AssignColor(GameObject.Find("ShapeManager").GetComponent <OnlineCSManager>().getColorAsColor()); }
void Awake() { hsvSlider.texture = HSVUtil.GenerateHSVTexture((int)hsvSlider.rectTransform.rect.width, (int)hsvSlider.rectTransform.rect.height); sliderR.onValueChanged.AddListener(newValue => { currentColor.r = newValue; if (dontAssignUpdate == false) { AssignColor(currentColor); } sliderRText.text = "R:" + (int)(currentColor.r * 255f); hexrgb.ManipulateViaRGB2Hex(); }); sliderG.onValueChanged.AddListener(newValue => { currentColor.g = newValue; if (dontAssignUpdate == false) { AssignColor(currentColor); } sliderGText.text = "G:" + (int)(currentColor.g * 255f); hexrgb.ManipulateViaRGB2Hex(); }); sliderB.onValueChanged.AddListener(newValue => { currentColor.b = newValue; if (dontAssignUpdate == false) { AssignColor(currentColor); } sliderBText.text = "B:" + (int)(currentColor.b * 255f); hexrgb.ManipulateViaRGB2Hex(); }); hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, ((Texture2D)hsvSlider.texture).GetPixelBilinear(0, 0)); MoveCursor(cursorX, cursorY); }
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); }