public void AssignColor(Color color) { var hsv = HSVUtil.ConvertRgbToHsv(color); // Debug.Log(hsv.ToString()); float hOffset = (float)(hsv.H / 360); //if (hsv.S > 1) //{ // hsv.S %= 1f; //} //if (hsv.V > 1) //{ // hsv.V %= 1f; //} MovePointer(hOffset, false); MoveCursor((float)hsv.S, (float)hsv.V, false); currentColor = color; colorImage.color = currentColor; onValueChanged.Invoke(currentColor); }
public void OnStateChange(ShuttleConsoleState newState) { if (newState == ShuttleConsoleState.Off) { SetSafetyProtocols(true); UpdateManager.Remove(CallbackType.PERIODIC_UPDATE, UpdateMe); ClearScreen(); return; } if (newState == ShuttleConsoleState.Normal) { AddRadarItems(); //Important: set values from server using SetValue and not Value Rulers.SetValueServer(rulersColor); RadarScanRay.SetValueServer(rayColor); Crosshair.SetValueServer(crosshairColor); SetSafetyProtocols(true); } else if (newState == ShuttleConsoleState.Emagged) { AddRadarItems(true); //Repaint radar to evil colours Rulers.SetValueServer(HSVUtil.ChangeColorHue(rulersColor, -80)); RadarScanRay.SetValueServer(HSVUtil.ChangeColorHue(rayColor, -80)); Crosshair.SetValueServer(HSVUtil.ChangeColorHue(crosshairColor, -80)); SetSafetyProtocols(false); } UpdateManager.Add(UpdateMe, 1f); OffOverlay.SetValueServer(Color.clear); }
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); }
public Color GetColor(float posX, float posY) { var color = HSVUtil.ConvertHsvToRgb(pointerPos * -360 + 360, posX, posY); return(color); //Debug.Log(posX + " " + posY); //return ((Texture2D)hsvImage.texture).GetPixel((int)(posX * hsvImage.texture.width ), (int)(posY * hsvImage.texture.height)); }
private void RGBChanged() { HsvColor color = HSVUtil.ConvertRgbToHsv(CurrentColor); _hue = color.normalizedH; _saturation = color.normalizedS; _brightness = color.normalizedV; }
private void HSVChanged() { Color color = HSVUtil.ConvertHsvToRgb(_hue * 360, _saturation, _brightness, _alpha); _red = color.r; _green = color.g; _blue = color.b; }
public Color GetColor(float posX, float posY) { posY = Mathf.Clamp(posY, minV, maxV); posX = Mathf.Clamp(posX, minSat, maxSat); var color = HSVUtil.ConvertHsvToRgb(pointerPos * -(minHue + maxHue) + (minHue + maxHue), posX, posY); return(color); }
private void UpdateHSVColor() { Color color = HSVUtil.ConvertHsvToRgb(h * 360, s, v, a); r = color.r; g = color.g; b = color.b; a = color.a; CurrentColor = color; UpdateUIData(); }
private void UpdateColor() { HsvColor hsv = HSVUtil.ConvertRgbToHsv(r, g, b); boxSlider.normalizedValue = hsv.normalizedS; boxSlider.normalizedValueY = hsv.normalizedV; hueSlider.normalizedValue = hsv.normalizedH; Color color = new Color(r, g, b, a); CurrentColor = color; UpdateUIData(); }
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 void AssignColor(Color color) { var hsv = HSVUtil.ConvertRgbToHsv(color); float hOffset = (float)(hsv.H / 360); MovePointer(hOffset, false); MoveCursor((float)hsv.S, (float)hsv.V, false); currentColor = color; colorImage.color = currentColor; onValueChanged.Invoke(currentColor); }
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); }
private void OnStateChange(TabState newState) { //Important: if you get NREs out of nowhere, make sure your server code doesn't accidentally run on client as well if (!IsServer) { return; } switch (newState) { case TabState.Normal: PowerOff(); StartNormalOperation(); //Important: set values from server using SetValue and not Value OffOverlay.SetValueServer(Color.clear); Rulers.SetValueServer(rulersColor); RadarScanRay.SetValueServer(rayColor); Crosshair.SetValueServer(crosshairColor); SetSafetyProtocols(true); break; case TabState.Emagged: PowerOff(); StartNormalOperation(); //Remove overlay OffOverlay.SetValueServer(Color.clear); //Repaint radar to evil colours Rulers.SetValueServer(HSVUtil.ChangeColorHue(rulersColor, -80)); RadarScanRay.SetValueServer(HSVUtil.ChangeColorHue(rayColor, -80)); Crosshair.SetValueServer(HSVUtil.ChangeColorHue(crosshairColor, -80)); AddEmagItems(); SetSafetyProtocols(false); break; case TabState.Off: PowerOff(); //Black screen overlay OffOverlay.SetValueServer(Color.black); SetSafetyProtocols(true); break; default: return; } }
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()); }
private void RegenerateSVTexture() { if (supportsComputeShaders) { float hue = picker != null ? picker.H : 0; compute.SetTexture(kernelID, "Texture", renderTexture); compute.SetFloats("TextureSize", textureWidth, textureHeight); compute.SetFloat("Hue", hue); compute.SetBool("linearColorSpace", QualitySettings.activeColorSpace == ColorSpace.Linear); var threadGroupsX = Mathf.CeilToInt(textureWidth / 32f); var threadGroupsY = Mathf.CeilToInt(textureHeight / 32f); compute.Dispatch(kernelID, threadGroupsX, threadGroupsY, 1); } else { double h = picker != null ? picker.H * 360 : 0; if (image.texture != null) { DestroyImmediate(image.texture); } var texture = new Texture2D(textureWidth, textureHeight); texture.hideFlags = HideFlags.DontSave; for (int s = 0; s < textureWidth; s++) { Color32[] colors = new Color32[textureHeight]; for (int v = 0; v < textureHeight; v++) { colors[v] = HSVUtil.ConvertHsvToRgb(h, (float)s / 100, (float)v / 100, 1); } texture.SetPixels32(s, 0, 1, textureHeight, colors); } texture.Apply(); image.texture = texture; } }
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); }
private void RegenerateSVTexture() { double h = ((!(picker != null)) ? 0f : (picker.H * 360f)); if (image.texture != null) { Object.DestroyImmediate(image.texture); } Texture2D texture2D = new Texture2D(100, 100); texture2D.hideFlags = HideFlags.DontSave; Texture2D texture2D2 = texture2D; for (int i = 0; i < 100; i++) { Color32[] array = new Color32[100]; for (int j = 0; j < 100; j++) { ref Color32 reference = ref array[j]; reference = HSVUtil.ConvertHsvToRgb(h, (float)i / 100f, (float)j / 100f, 1f); } texture2D2.SetPixels32(i, 0, 1, 100, array); }
private void RegenerateSVTexture() { if (SystemInfo.supportsComputeShaders && compute != null) { var hue = picker != null ? picker.H : 0; compute.SetTexture(kernelID, "Texture", renderTexture); compute.SetFloats("TextureSize", textureWidth, textureHeight); compute.SetFloat("Hue", hue); var threadGroupsX = Mathf.CeilToInt(textureWidth / 32f); var threadGroupsY = Mathf.CeilToInt(textureHeight / 32f); compute.Dispatch(kernelID, threadGroupsX, threadGroupsY, 1); } else { double h = picker != null ? picker.H * 360 : 0; if (image.texture != null) { Destroy(image.texture); } var texture = new Texture2D(textureWidth, textureHeight) { hideFlags = HideFlags.DontSave }; for (var s = 0; s < textureWidth; s++) { var colors = new Color32[textureHeight]; for (var v = 0; v < textureHeight; v++) { colors[v] = HSVUtil.ConvertHsvToRgb(h, (float)s / 100, (float)v / 100, 1); } texture.SetPixels32(s, 0, 1, textureHeight, colors); } texture.Apply(); image.texture = texture; } }
protected virtual void HSVChanged(float h, float s, float v) { createPresetImage.color = HSVUtil.ConvertHsvToRgb(h * 360, s, v, 1); //Debug.Log("hsv util color: " + createPresetImage.color); }
private void RegenerateTexture() { Color32 baseColor = picker != null ? picker.CurrentColor : Color.black; float h = picker != null ? picker.H : 0; float s = picker != null ? picker.S : 0; float v = picker != null ? picker.V : 0; Texture2D texture; Color32[] colors; bool vertical = direction == Slider.Direction.BottomToTop || direction == Slider.Direction.TopToBottom; bool inverted = direction == Slider.Direction.TopToBottom || direction == Slider.Direction.RightToLeft; int size; switch (type) { case ColorValues.R: case ColorValues.G: case ColorValues.B: case ColorValues.A: size = 255; break; case ColorValues.Hue: size = 360; break; case ColorValues.Saturation: case ColorValues.Value: size = 100; break; default: throw new System.NotImplementedException(""); } if (vertical) { texture = new Texture2D(1, size); } else { texture = new Texture2D(size, 1); } texture.hideFlags = HideFlags.DontSave; colors = new Color32[size]; switch (type) { case ColorValues.R: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(i, baseColor.g, baseColor.b, 255); } break; case ColorValues.G: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, i, baseColor.b, 255); } break; case ColorValues.B: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, baseColor.g, i, 255); } break; case ColorValues.A: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(i, i, i, 255); } break; case ColorValues.Hue: for (int i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(i, 1, 1, 1); } break; case ColorValues.Saturation: for (int i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, (float)i / size, v, 1); } break; case ColorValues.Value: for (int i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, s, (float)i / size, 1); } break; default: throw new System.NotImplementedException(""); } texture.SetPixels32(colors); texture.Apply(); if (image.texture != null) { DestroyImmediate(image.texture); } image.texture = texture; switch (direction) { case Slider.Direction.BottomToTop: case Slider.Direction.TopToBottom: image.uvRect = new Rect(0, 0, 2, 1); break; case Slider.Direction.LeftToRight: case Slider.Direction.RightToLeft: image.uvRect = new Rect(0, 0, 1, 2); break; default: break; } }
private static string ChangeColorHue(string srcHexColour, int amount) { return(DebugTools.ColorToHex(HSVUtil.ChangeColorHue(DebugTools.HexToColor(srcHexColour), amount))); }
private void RegenerateTexture() { Color32 baseColor = picker != null ? picker.CurrentColor : Color.black; var h = picker != null ? picker.H : 0; var s = picker != null ? picker.S : 0; var v = picker != null ? picker.V : 0; var vertical = direction == Slider.Direction.BottomToTop || direction == Slider.Direction.TopToBottom; var inverted = direction == Slider.Direction.TopToBottom || direction == Slider.Direction.RightToLeft; int size; switch (type) { case ColorValues.R: case ColorValues.G: case ColorValues.B: case ColorValues.A: size = 255; break; case ColorValues.Hue: size = 360; break; case ColorValues.Saturation: case ColorValues.Value: size = 100; break; default: throw new NotImplementedException(""); } var texture = vertical ? new Texture2D(1, size) : new Texture2D(size, 1); texture.hideFlags = HideFlags.DontSave; var colors = new Color32[size]; switch (type) { case ColorValues.R: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(i, baseColor.g, baseColor.b, 255); } break; case ColorValues.G: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, i, baseColor.b, 255); } break; case ColorValues.B: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, baseColor.g, i, 255); } break; case ColorValues.A: for (byte i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = new Color32(i, i, i, 255); } break; case ColorValues.Hue: for (var i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(i, 1, 1, 1); } break; case ColorValues.Saturation: for (var i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, (float)i / size, v, 1); } break; case ColorValues.Value: for (var i = 0; i < size; i++) { colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, s, (float)i / size, 1); } break; default: throw new NotImplementedException(""); } texture.SetPixels32(colors); texture.Apply(); if (image.texture != null) { DestroyImmediate(image.texture); } image.texture = texture; // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault switch (direction) { case Slider.Direction.BottomToTop: case Slider.Direction.TopToBottom: image.uvRect = new Rect(0, 0, 2, 1); break; case Slider.Direction.LeftToRight: case Slider.Direction.RightToLeft: image.uvRect = new Rect(0, 0, 1, 2); break; } }
void SendChangedEvent() { Color c = HSVUtil.ConvertHsvToRgb(_hue * 360f, 1, 1, 1); onColorChanged.Invoke(c); }
public Color GetColor(float posX, float posY) { var color = HSVUtil.ConvertHsvToRgb(pointerPos * -360 + 360, posX, posY); return(color); }
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); }