diff --git a/Assets/HSVPicker/ColorPickerTester.cs b/Assets/HSVPicker/ColorPickerTester.cs index 5d91f82..dedd47b 100755 --- a/Assets/HSVPicker/ColorPickerTester.cs +++ b/Assets/HSVPicker/ColorPickerTester.cs @@ -10,11 +10,11 @@ public class ColorPickerTester : MonoBehaviour // Use this for initialization void Start () { - picker.onValueChanged.AddListener(color => +/* picker.onValueChanged.AddListener(color => { renderer.material.color = color; }); - } +*/ } // Update is called once per frame void Update () { diff --git a/Assets/HSVPicker/HSVPicker.cs b/Assets/HSVPicker/HSVPicker.cs index fea5246..e3ff4e2 100755 --- a/Assets/HSVPicker/HSVPicker.cs +++ b/Assets/HSVPicker/HSVPicker.cs @@ -9,7 +9,6 @@ public class HSVPicker : MonoBehaviour { public static Color currentColor; public Image colorImage; - public Image pointer; public Image cursor; public RawImage hsvSlider; public RawImage hsvImage; @@ -18,6 +17,7 @@ public class HSVPicker : MonoBehaviour { //public InputField inputG; //public InputField inputB; + public Slider sliderRGB; public Slider sliderR; public Slider sliderG; public Slider sliderB; @@ -31,7 +31,7 @@ public class HSVPicker : MonoBehaviour { public float cursorY = 0; - public HSVSliderEvent onValueChanged = new HSVSliderEvent(); +// public HSVSliderEvent onValueChanged = new HSVSliderEvent(); private bool dontAssignUpdate = false; @@ -39,10 +39,20 @@ void Awake() { hsvSlider.texture = HSVUtil.GenerateHSVTexture((int)hsvSlider.rectTransform.rect.width, (int)hsvSlider.rectTransform.rect.height); + sliderRGB.onValueChanged.AddListener(newValue => + { + Color color=((Texture2D)hsvSlider.texture).GetPixel((int)(hsvSlider.rectTransform.rect.width*.5f),(int)(hsvSlider.rectTransform.rect.height*(newValue))); + currentColor=color; + if (!dontAssignUpdate) + { + AssignColor(currentColor); + } + hexrgb.ManipulateViaRGB2Hex(); + }); sliderR.onValueChanged.AddListener(newValue => { currentColor.r = newValue; - if (dontAssignUpdate == false) + if (!dontAssignUpdate) { AssignColor(currentColor); } @@ -52,7 +62,7 @@ void Awake() sliderG.onValueChanged.AddListener(newValue => { currentColor.g = newValue; - if (dontAssignUpdate == false) + if (!dontAssignUpdate) { AssignColor(currentColor); } @@ -62,7 +72,7 @@ void Awake() sliderB.onValueChanged.AddListener(newValue => { currentColor.b = newValue; - if (dontAssignUpdate == false) + if (!dontAssignUpdate) { AssignColor(currentColor); } @@ -75,26 +85,14 @@ void Awake() MoveCursor(cursorX, cursorY); } - // Update is called once per frame - void Update () { - //if (Input.GetKeyDown(KeyCode.R)) - //{ - // var color = new Color(45f / 255, 200f / 255, 255f / 255); - // Debug.Log(color); - // AssignColor(color); - - // } - - - } - public void AssignColor(Color color) { - var hsv = HSVUtil.ConvertRgbToHsv(color); - - // Debug.Log(hsv.ToString()); + dontAssignUpdate=true; + HsvColor hsv = HSVUtil.ConvertRgbToHsv(color); + + // Debug.Log(hsv.ToString()); float hOffset = (float)(hsv.H / 360); @@ -109,18 +107,19 @@ public void AssignColor(Color color) MovePointer(hOffset, false); MoveCursor((float)hsv.S, (float)hsv.V, false); - currentColor = color; + UpdateInputs(); colorImage.color = currentColor; - onValueChanged.Invoke(currentColor); - +// onValueChanged.Invoke(currentColor); +//z hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, currentColor); + dontAssignUpdate=false; } - - + + public Color MoveCursor(float posX, float posY, bool updateInputs=true) { - dontAssignUpdate = updateInputs; +// dontAssignUpdate = updateInputs; if (posX > 1) { posX %= 1; @@ -144,9 +143,9 @@ public Color MoveCursor(float posX, float posY, bool updateInputs=true) if (updateInputs) { UpdateInputs(); - onValueChanged.Invoke(currentColor); +// onValueChanged.Invoke(currentColor); } - dontAssignUpdate = false; +// dontAssignUpdate = false; return currentColor; } @@ -158,20 +157,20 @@ public Color GetColor(float posX, float posY) public Color MovePointer(float newPos, bool updateInputs = true) { - dontAssignUpdate = updateInputs; +// dontAssignUpdate = updateInputs; if (newPos > 1) { newPos %= 1f;//hsv } pointerPos = newPos; - var mainColor =((Texture2D)hsvSlider.texture).GetPixelBilinear(0, pointerPos); + Color 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; +// Destroy(hsvImage.texture); +// hsvImage.texture = null; hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, mainColor); } @@ -185,7 +184,7 @@ public Color MovePointer(float newPos, bool updateInputs = true) hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, mainColor); } - pointer.rectTransform.anchoredPosition = new Vector2(0, -pointerPos * hsvSlider.rectTransform.rect.height); + sliderRGB.value = 1f-pointerPos; currentColor = GetColor(cursorX, cursorY); colorImage.color = currentColor; @@ -193,15 +192,15 @@ public Color MovePointer(float newPos, bool updateInputs = true) if (updateInputs) { UpdateInputs(); - onValueChanged.Invoke(currentColor); +// onValueChanged.Invoke(currentColor); } - dontAssignUpdate = false; +// dontAssignUpdate = false; return currentColor; } public void UpdateInputs() { - + dontAssignUpdate=true; sliderR.value = currentColor.r; sliderG.value = currentColor.g; sliderB.value = currentColor.b; @@ -209,6 +208,8 @@ public void UpdateInputs() sliderRText.text = "R:"+ (currentColor.r * 255f); sliderGText.text = "G:" + (currentColor.g * 255f); sliderBText.text = "B:" + (currentColor.b * 255f); + dontAssignUpdate=false; + } void OnDestroy() diff --git a/Assets/HSVPicker/PickerTestVertical.unity b/Assets/HSVPicker/PickerTestVertical.unity index 6c30a31..12ffc68 100644 Binary files a/Assets/HSVPicker/PickerTestVertical.unity and b/Assets/HSVPicker/PickerTestVertical.unity differ