Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Color Picker

Discussion in 'UGUI & TextMesh Pro' started by judah4, Sep 7, 2014.

  1. smokinpuppy

    smokinpuppy

    Joined:
    Sep 1, 2018
    Posts:
    39
    Hi @judah4 , I'm having another issue, the color picker window isn't letting me drag it past the center point (from bottom left to top left) or (bottom left to bottom right). When in the inspector, I can see that the knob is going outside the bounds of the color box, like the bounds are shifted 50% to the left and 50% down. When I click on the elements, they all seem to be aligned properly, so I don't know why that would be happening. Is there somewhere in the scripts that I can adjust that?

    P.S, it might have something to do with the new AssignColor function as that is used in the SliderChanged function in SVBoxSlider script, but I could be wrong.
     
    Last edited: Sep 3, 2019
  2. smokinpuppy

    smokinpuppy

    Joined:
    Sep 1, 2018
    Posts:
    39
    Okay, I got it working. I changed the 2nd AssignColor function in ColorPicker.cs to AssignDirectColor (That didn't change anything) but then I set the Knob's X and Y Rect Value to 0 and 0 and that worked
     
  3. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    This is a great tool, thanks!
    Only thing I can't seem to figure, is where the initial start color is set. For some reason it chooses #FF0000, when I want it to just be #FFFFFF on start. If anyone knows where this is set please tag me :D
     
  4. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    Thanks!

    You can set the starting color with a helper script for now. Take a look at ColorPickerTester.cs in the Other folder. You can use that to set the starting color or your own script that sets the current color property on the color picker.
     
    Avalin likes this.
  5. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    Thanks I figured it out! Works perfectly for my case.
    Thanks again!
     
  6. SolarFalcon

    SolarFalcon

    Joined:
    Nov 28, 2015
    Posts:
    167
    This is an awesome asset. I just have one question: Is it possible to allow HDR colors? I don't trust myself enough to tamper with the code to try and add this.

    Edit:
    Nevermind! I surprised myself and figured it out. This is an invaluable asset and as soon as I can I will send you some money. Not sure how much I'd be willing to pay for this, but I will send you some funds ASAP.
     
    Last edited: Jan 24, 2020
  7. SolarFalcon

    SolarFalcon

    Joined:
    Nov 28, 2015
    Posts:
    167
    For those interested:
    Make a callback for OnSliderValueChanged(float) in the script you are using to control the color, make a new slider (under Alpha, seemed like a nice place to put it) in the Picker prefab. Name it whatever (I just put a "+" for mine), and link the callback in the On Value Changed (single) event. Use this code:

    Code (CSharp):
    1. public void OnSliderValueChanged(float n)
    2.     {
    3.         intensity = n;
    4.  
    5.         swordMaterial.SetColor("_EmissionColor", swordMaterial.GetColor("_EmissionColor") * intensity);
    6.     }
    Note: It's kinda buggy, if you change the color with this bar it will change the intensity, but it might look weird, until you change the color again ( like with the HSV value). Not sure how to change this, if I figure out how to fix this I'll edit this post.
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Once you get it right, put in a pull request to the original repo.
     
  9. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    Awesome! I'm glad you like it
     
  10. essometer

    essometer

    Joined:
    Oct 11, 2018
    Posts:
    2
    Hey judah4, thank you so much for this colorpicker, works perfectly.
     
    judah4 likes this.
  11. BigEScherer

    BigEScherer

    Joined:
    Aug 20, 2019
    Posts:
    7
    Hi there, judah4! I love your tool, but I'm struggling with the coding to get it to apply the new color to UI text. (Noob here!) Any help would be much appreciated!
     
  12. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    Hi! I can probably help with that. Can you post the code you have so far? I'm guessing you want to do something like the mesh renderer color changing code that is in the project.
     
  13. BigEScherer

    BigEScherer

    Joined:
    Aug 20, 2019
    Posts:
    7
    Thanks so much for responding! Yes - instead of changing the material color of an object, I just want to change the color of text in a menu. The user inputs their name in an UI InputField, then selects the color of the text they would like (using your tool), then hits the Submit button. Then the next menu screen displays their name in whatever color they chose.

    So here is my first script, attached to the canvas in the first scene:

    public class MySettings : MonoBehaviour
    {
    public static string thePoststr;

    public Text thePost;

    }

    // Start is called before the first frame update
    void Start()
    {
    thePost.text = thePoststr;

    }
    }

    Then the next script attached to the canvas and triggered when the Submit button is clicked:

    public class PostButton : MonoBehaviour
    {
    public InputField thePost;

    public void OnSubmit()
    {
    MySettings.thePoststr = thePost.text;

    SceneManager.LoadScene(1);
    }
    }

    And then the script attached to the Text on the next scene:

    void Start()
    {
    GetComponent<Text>().enabled = true;
    }

    So this is my basic scripting, without incorporating yours yet. Would I only need to modify your ObjectColor script and incorporate it in this last script?

    public class ObjectColor : MonoBehaviour {

    void OnSetColor(Color color)
    {
    [What, if anything, would I change here?]
    Material mt = new Material(GetComponent<Renderer>().sharedMaterial);
    mt.color = color;
    GetComponent<Renderer>().material = mt;
    }

    void OnGetColor(ColorPicker picker)
    {

    picker.NotifyColor(GetComponent<Renderer>().material.color);
    }
    }


    I doubt it's not quite that simple; I'm guessing I'd need to modify at least a couple of the scripts. I have your ColorPicker and DrawColorPickers included in the hierarchy of the first Scene. Do I need to include either one in the hierarchy of the second Scene? Sorry if this is confusing - I am very new to Unity and C#
     
  14. BigEScherer

    BigEScherer

    Joined:
    Aug 20, 2019
    Posts:
    7
    Oops, wasn't quite finished... I'm guessing this last bit of your ObjectColor script would definitely need to be modified, I just am not sure how:

    void OnGetColor(ColorPicker picker)
    {

    picker.NotifyColor(GetComponent<Renderer>().material.color);
    }
    }

    Thanks again for any help!
     
  15. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    I think if I'm understanding right, instead of
    GetComponent<Renderer>().material.color
    for assigning the color, you can do
    GetComponent<Text>().color
    or
    text.color
    .

    I'm having a hard time following your code, but you would want to write the color to your settings like you do the input field, and then load it all on the next scene.
     
  16. BigEScherer

    BigEScherer

    Joined:
    Aug 20, 2019
    Posts:
    7
    So since I'm trying to change the color of text and not the color of a material, would I use your ObjectColor script at all? And if so, how would I change it?

    public class ObjectColor : MonoBehaviour {

    void OnSetColor(Color color)
    {
    [What, if anything, would I change here?]
    Material mt = new Material(GetComponent<Renderer>().sharedMaterial);
    mt.color = color;
    GetComponent<Renderer>().material = mt;
    }

    void OnGetColor(ColorPicker picker)
    {
    [Obviously, this would need to change to, as you say, GetComponent<Text>().color]
    picker.NotifyColor(GetComponent<Renderer>().material.color);
    }
    }
     
  17. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    yes, instead of this:
    Code (CSharp):
    1. void OnSetColor(Color color)
    2. {
    3. //[What, if anything, would I change here?]
    4. Material mt = new Material(GetComponent<Renderer>().sharedMaterial);
    5. mt.color = color;
    6. GetComponent<Renderer>().material = mt;
    7. }
    You can do this instead to the text:
    Code (CSharp):
    1. void OnSetColor(Color color)
    2. {
    3.     GetComponent<Text>().color = color;
    4. }
     
  18. BigEScherer

    BigEScherer

    Joined:
    Aug 20, 2019
    Posts:
    7
    Awesome, thanks for the help, judah4! Great tool!
     
  19. KazFoxsen

    KazFoxsen

    Joined:
    Apr 6, 2020
    Posts:
    6
    I want to use this, but I can't figure out how to get it working. I downloaded the .zip from GitHub and put all the contents into my project (overwriting folders that share the same names), but I get compiler errors.

    It says "You are trying to replace or create a Prefab from the instance 'Presets' that contains the script 'Color Presets', which does not derive from MonoBehaviour. This is not allowed."
    --------------
    EDIT: I didn't realize my version of Unity was out of date. Getting the latest made the Color Picker work.
     
    Last edited: Apr 16, 2020
  20. ZolnierGames

    ZolnierGames

    Joined:
    Feb 19, 2018
    Posts:
    88
    How do I scale this so it's larger and is a better size for my screen on mobile? Right now, when I add the prefab to my Canvas, it is tiny. If I just go into the properties and change the scale value, it makes everything blurry.
     
  21. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    Instead of scaling, you'll have to increase the size of the picker and controls. You might have to adjust positions to get it looking right again.
     
  22. ZolnierGames

    ZolnierGames

    Joined:
    Feb 19, 2018
    Posts:
    88
    Quick question: So while I pass RGBA values into color picker as 0-255 byte Color32 values, when I grab the picker.CurrentColor.r values, it comes back as a Color float like 0.531956 etc. Is there a setting or way to have it automatically output Color32 (0-255) values or does it always return Color float values?
     
  23. muratksml4

    muratksml4

    Joined:
    Feb 8, 2020
    Posts:
    1
    merhaba ben uzun bir süre sonra bile colorpicker kaydetmeme yardım etmeye çalıştım ama kötü İngilizce için üzgünüm herhangi bir yeni renk değeri değerleri kaydetmedim:(
     
  24. xikst1

    xikst1

    Joined:
    Apr 18, 2020
    Posts:
    13
    Hi guys. Thank you for the plugin. I bought like 4 color pickers from the store and no one worked in the world canvas view. I mean, they will look perfect but they will not work correctly. They will get completely messed up and will not pick the colors right and you can not move the scrolling bars and so on. Issues everywhere. I tested this color picker and I found that it works well.

    I will like to point out some issues that may be good to fix. I tried to choose a maximum number of saved colors and when I reached the max, I can not add anymore and the add options is gone. I think it will be nice to get additional rows downwards in order to save more colors. 2) A way to remove or reset a saved color. 3) It will help if the color picker had an eye dropper. That will save some time and will help the functionality of the color picker. I saw a color picker where I was able to load a local image and then color pick that image. That was amazing too.

    Anyways, I'm just leaving my humble opinion. The plugin freaking works man. Thank you so much for the work.
     
  25. xikst1

    xikst1

    Joined:
    Apr 18, 2020
    Posts:
    13
    Hi guys. I have a question. How do I make this color picker code also be able to change the LIGHT>COLOR and the MATERIALS>EMMISION>HDR COLOR?

    I will really appreciate it.

    SIncerely,
    Gianfranco

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class ColorPickerTester : MonoBehaviour
    4. {
    5.  
    6.     public new Renderer renderer;
    7.     public ColorPicker picker;
    8.  
    9.     public Color Color = Color.red;
    10.  
    11.     // Use this for initialization
    12.     void Start ()
    13.     {
    14.         picker.onValueChanged.AddListener(color =>
    15.         {
    16.             renderer.material.color = color;
    17.             Color = color;
    18.         });
    19.  
    20.         renderer.material.color = picker.CurrentColor;
    21.  
    22.         picker.CurrentColor = Color;
    23.     }
    24.    
    25.     // Update is called once per frame
    26.     void Update () {
    27.    
    28.     }
    29. }
    30.  
    upload_2020-7-5_20-0-30.png

    upload_2020-7-5_20-1-52.png
     
  26. jhellermann

    jhellermann

    Joined:
    Aug 27, 2017
    Posts:
    7
    Hey judah4, may I ask a quick one? I try to use the AssignColor method the exact way, you describe it here, but it returns a compiler error (Unity 2019.4.1f1):

    Assets\ColorChanger.cs(29,10): error CS7036: There is no argument given that corresponds to the required formal parameter 'value' of 'ColorPickerControl.AssignColor(ColorValues, float)'
     
  27. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    Hi, I think the code might have changed since then. You can assign the color directly to the CurrentColor property.
     
  28. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    SolarFalcon likes this.
  29. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    975
    Unity 2019.4 Feedback:
    1. Prefab on Scene can't be saved. I have "*" state of scene which tries to indefinitely suggest me to save the scene.
    2. If I click "ColorBox container" and "Hue" at random moments then I have missed feedback of color changing.
    3. Performance are bad. My MacBook Pro 2017 starts cooling When I use your tool. It's not normal. P.S. I experienced with such situation when I incorrectly wrote my own shader.
    4. Saved Color on "Presets" are reset on game stop.
    5. C# scripts are provided, but When I click on script name with "CMD" then assembly browser is opened instead of c#-script. Visual Studio for Mac 2019.
     
  30. nikelodionka

    nikelodionka

    Joined:
    Mar 3, 2021
    Posts:
    1
    Hello, how can I fix the color picker in the prefab on 2D object?
     
    Last edited: Mar 3, 2021
  31. smokinpuppy

    smokinpuppy

    Joined:
    Sep 1, 2018
    Posts:
    39
    Hi, I'd like to have the color picker send an event when the color stops being changed as opposed to on the change. How can I do that?

    Thank you in advance,

    Robert
     
  32. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    So, instead of each change when the user is changing sliders, you want an event for the end? That would require an update at the moment but for a workaround you could have the event send to a variable and a previous update variable. Then each update, you could compare if they are the same or different. If they are the same then the user is probably done editing and you can write the color where you want. This does have issues because it will be a frame behind and won't handle well if the user is still holding the color silders but not moving them. But, it could work for the time being.

    I added a github issue if I understand what you want correctly. https://github.com/judah4/HSV-Color-Picker-Unity/issues/46
     
  33. smokinpuppy

    smokinpuppy

    Joined:
    Sep 1, 2018
    Posts:
    39
    Yes that is exactly correct. I thought about doing it that way, and I'm thinking might be better to check if pointer down during the OnChange event and only take the change once pointer is up. Do you think that would work?

    Thank you,

    Robert
     
  34. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    Yes, if you're comfortable adding your own events to the color picker. I think you could get it working that way.
     
  35. mwlazlo885

    mwlazlo885

    Joined:
    May 17, 2018
    Posts:
    6
    Hiya! How can we save all preset list and load them at runtime? appreciate any help <3
     
    makaka-org likes this.
  36. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    Right now nothing is saved during runtime but you can preinitialized preset lists using the ColorPresetManager.
    https://github.com/judah4/HSV-Color...ter/Assets/HSVPicker/UI/ColorPresetManager.cs

    Somewhere in a script awake method you could setup some preset lists by loading data from PlayerPrefs or some other source. For saving, you would need to check for existing PresetLists and save their contents some where. I hope this gives you some ideas.
     
  37. TheOriginalHansTheMan

    TheOriginalHansTheMan

    Joined:
    Jan 17, 2020
    Posts:
    4
    My project is in Unity 2020.3 lts -
    is it hard to get the picker working in that version ? Do you plan to upgrade soon ? Thanks for making this and making it available :D
     
  38. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    I use it in 2020.3 LTS. Are you having issues?
     
  39. smokinpuppy

    smokinpuppy

    Joined:
    Sep 1, 2018
    Posts:
    39
    Hi @judah4, I remember that there was a way to attach a slider to the alpha channel of the color picker, but I can't seem to find how to do that now. How can I do that?

    Thank you in advance,

    Robert
     
  40. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    The bottom slider should be attached to Alpha already. Did you want another slider elsewhere for it?
     
  41. smokinpuppy

    smokinpuppy

    Joined:
    Sep 1, 2018
    Posts:
    39
    Yes, I want to put a slider elsewhere on the page. After you mentioned that it was below, I found it in the demo and found the Color Slider script. Added it to my slider and attached the color picker object to it. Then set it to alpha. That's the right way right?

    Thank you,

    Robert
     
  42. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    That sounds right. It's through event methods so you should be able to set up the new slider to the method on the ColorPicker script.
     
    smokinpuppy likes this.
  43. smokinpuppy

    smokinpuppy

    Joined:
    Sep 1, 2018
    Posts:
    39
    Thank you, yes that worked :)
     
    judah4 likes this.
  44. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
  45. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
  46. NgoHaiLinh

    NgoHaiLinh

    Joined:
    Jun 21, 2021
    Posts:
    3
    Thanks for the fantastic tools!

    just one question: Can I change the preset colors after adding it?
     
  47. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    256
    Yes, look at the configuration and set the Default Preset colors https://github.com/judah4/HSV-Color-Picker-Unity#setup-settings. I don't remember how you would set them during runtime but you should be able to. If runtime preset colors is what you need I'll have to dig into the code and make sure that can be done.
     
    makaka-org likes this.
  48. NgoHaiLinh

    NgoHaiLinh

    Joined:
    Jun 21, 2021
    Posts:
    3
    yeah, I mean runtime change or delete those colors cus right now we can only adding new colors to the preset
     
    Last edited: Nov 24, 2022
    judah4 likes this.
  49. NgoHaiLinh

    NgoHaiLinh

    Joined:
    Jun 21, 2021
    Posts:
    3
    maybe change the preset list to group toggle and edit the active color?
     
  50. VolodyaPahom

    VolodyaPahom

    Joined:
    Jan 20, 2023
    Posts:
    1
    Can you help me how to transfer object color between scenes?
     

    Attached Files: