Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Color Picker

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

  1. smokinpuppy

    smokinpuppy

    Joined:
    Sep 1, 2018
    Posts:
    18
    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:
    18
    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:
    56
    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:
    232
    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:
    56
    Thanks I figured it out! Works perfectly for my case.
    Thanks again!
     
  6. MaximumTre

    MaximumTre

    Joined:
    Nov 28, 2015
    Posts:
    152
    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. MaximumTre

    MaximumTre

    Joined:
    Nov 28, 2015
    Posts:
    152
    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,732
    Once you get it right, put in a pull request to the original repo.
     
  9. judah4

    judah4

    Joined:
    Feb 6, 2011
    Posts:
    232
    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:
    232
    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:
    232
    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:
    232
    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:
    52
    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:
    232
    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:
    52
    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:
    5
    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:
    232
    Hi, I think the code might have changed since then. You can assign the color directly to the CurrentColor property.
     
unityunity