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

A working, stylable combo box (drop down list)

Discussion in 'UGUI & TextMesh Pro' started by jbooth, Aug 24, 2014.

  1. dkely

    dkely

    Joined:
    Mar 3, 2014
    Posts:
    22
    Forgot to mention that this will display your open list by default as the list only gets set to the overlay object after being clicked at least once.
    For a quick and dirty fix, you also have to do
    scrollPanelGO.SetActive(false);
    in the initiate code and then the ToggleComboBox() needs you to set it to true again.
     
  2. franzbischoff

    franzbischoff

    Joined:
    Feb 23, 2015
    Posts:
    8
    My current combobox.cs with more fixes:

    - Reposition droplist when screen resize
    - Allow Contant Pixel Size canvas, as well as Scale with Screen and Constant Physical size canvas
     

    Attached Files:

    Meceka likes this.
  3. Gibbonuk

    Gibbonuk

    Joined:
    Dec 10, 2013
    Posts:
    166
    Hi, just tried this and it wokr sgreat but for me, the dropdown is "down" and the list is showing the whole dropdown box is flickering?

    Thanks
     
  4. franzbischoff

    franzbischoff

    Joined:
    Feb 23, 2015
    Posts:
    8
    The flicker I had expericenced in the Editor view, but not in-game. Let me know if you find out why it flickers.
     
  5. TinoChow

    TinoChow

    Joined:
    Aug 8, 2014
    Posts:
    1
    In my case,I have to make a combobox for a list of country.Therefore I have to create around 200 comboboxItem dynamically,which causes my phone or even editor to freeze for around one minute.Is there anyway to do that?Thanks!
     
  6. dkely

    dkely

    Joined:
    Mar 3, 2014
    Posts:
    22
    I had a similar problem. One hacky fix i used was to only have as many display items as fit the viewing area. Then i reused them to display new items based on where the scroll bar was. So if you have 200 items and you can see 10 at any one time and you scroll to the bottom, then you would write the country names from 190-200 in the boxes. If you were in the middle you would write from 100-110 etc.
    Its not clean but it fixed my issue.
     
  7. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
    Sorry, guys, for leaving without any support, I have a long business trip at the US, and I am not sure when I will be able to update this package. Anyway, I'll be back!
     
  8. franzbischoff

    franzbischoff

    Joined:
    Feb 23, 2015
    Posts:
    8
    We'll never forgive you! :p
    Btw, way to go for starting this combobox package :)

    You could put this on github? :)
     
  9. Mike_Gardiner

    Mike_Gardiner

    Joined:
    Mar 21, 2015
    Posts:
    2
    This is great stuff.

    Do you know if it's an easy / difficult fix to allow the user to decide if the droplist shows up underneath the button, or above?

    My dropdown is at the bottom of the screen so it would need to expand upwards. It would also be cool if it could auto-decide based on whether it would spawn the droplist outside of a canvas bounds!

    Thanks again everyone, great work!
     
  10. Sanasad

    Sanasad

    Joined:
    Apr 7, 2015
    Posts:
    2
    Can you please upload this project again ?
     
  11. damenace

    damenace

    Joined:
    Aug 28, 2014
    Posts:
    2
    I recently tried using this on android, and the dropdown text is not visible. However it works perfectly fine in the editor.
     

    Attached Files:

  12. damenace

    damenace

    Joined:
    Aug 28, 2014
    Posts:
    2
    Issued resolved, I had deleted the default camera as the scene used nothing but UI. When I added the main camera back to the scene the text came back.
     
  13. Wiseman17

    Wiseman17

    Joined:
    Aug 17, 2013
    Posts:
    23
    Hi guys, thanks for the nice component.
    Actually had a problem with it when instantiating it as a part of a prefab without UI Canvas (adding it to a component with Canvas just after instantiating). As soon as it was created it failed to find a canvas on any parent inside the canvasTransform getter. What helped me is moving all the initialization stuff to Start().
    Code (CSharp):
    1.     private void Start()
    2.     {
    3.         InitControl();
    4.         lastScreenSize = new Vector2(Screen.width, Screen.height);
    5.  
    6.         scrollPanelGO.transform.SetParent(overlayGO.transform, true);
    7.     }
    Any thoughts on why it would be strongly not recommended? In my case Awake() and Start() actions are happening almost immediately anyways.
     
  14. el_santo

    el_santo

    Joined:
    Feb 27, 2015
    Posts:
    3
    Very good componenet. But do not work correctly if set scale > 1.
     
  15. xydroh

    xydroh

    Joined:
    Mar 7, 2015
    Posts:
    3
    if I use this in a program and I click on it all my other buttons dissapear. Has this happened to someone else too?
     
  16. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
    Sorry for being inavailable for these three months. I'm finally back. I think, I have to work on a new combobox version. This may take some time, but I hope, I will finish it. I'll let you know.
     
  17. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,648
    If you can @Kender either add this as another combobox alternative to the one on the UI Extensions repo (link in sig) which has 3 flavors of the combo box (Pure combo, smart list, autocomplete). Or better yet, add your wisdom to the existing control(s) to enhance them.

    I've also added a Editor Menu option to create each of the combo's to make them easier to use.
    (And my mind is addled and cannot remember if we've had this discussion already :D)
     
  18. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
    We've never discussed it, but I believe, I should try to get some profit of my solution :)
     
  19. Raum266

    Raum266

    Joined:
    Jun 9, 2015
    Posts:
    1
    Having some slight issues with this - At runtime, the combo box disappears completely. I thought I was doing something wrong, but this behavior occurs with the included 'test' project as well. Any suggestions as to why this may occur?

    Thanks!
     
  20. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
    My best guess - it has some problems with new Unity version. I'm working on a new one now.
     
  21. iambrois

    iambrois

    Joined:
    Mar 13, 2013
    Posts:
    5
    Hi @Kender

    Did you ever get around on updating your ComboBox? I'd really like to use it!

    Thanks!
     
  22. w34edrtfg

    w34edrtfg

    Joined:
    Nov 23, 2014
    Posts:
    44
    Your solution looks cool, i will be waiting for your release :)
     
  23. phileday

    phileday

    Joined:
    Feb 8, 2014
    Posts:
    88
    Is there any way of having the drop down list set to always be open. As if you have already clicked the button?
     
  24. phileday

    phileday

    Joined:
    Feb 8, 2014
    Posts:
    88
    don't worry about it. I worked out a solution by adding some functions to the code.
     
  25. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
    Having some problems. Posted here.
    Got no answer so far.
     
  26. Linck

    Linck

    Joined:
    Dec 21, 2013
    Posts:
    9
    Hey Kender, I have tryied out your asset on unity 5.1 and its not working for me. I got the last package you posted here: http://forum.unity3d.com/threads/a-...box-drop-down-list.264167/page-2#post-1965608

    I have created and empty new project, imported your package to it, and loaded the ComboBoxTestScene. Then clicked play, and clicked on the combo box, and it gives the click feedback but no dropdown panel appears. No errors, it just doesn't work.

    Then on the scene, I noticed the script on the ComboBox object is missing, then I dropped the ComboBox script onto it. Clicked play: same thing as before.

    Am I missing something? The items list on the combobox seems to be already populated and everything else looks like its ok. Here is a screenshot:

    ss.png
     
  27. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
    Hello, Linck. I am rewriting combobox right now. It seems like latest Unity version has some UI bugs, that are promised to be fixed in version 5.2. I had no experience with combobox, you are talking, for a long time. Hope, in some time I will publish a small UI asset pack with fixed combobox.

    As I can see, CBOverlay is created after a click. Does it disappear on next combobox click? What's under it?
     
  28. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
    Also, there were some fixes by the community after I published my latest release. Try them.
     
  29. Linck

    Linck

    Joined:
    Dec 21, 2013
    Posts:
    9
    CBOverlay is created on awake or start, but it comes inactive (the very first checkbox on top left corner in the inspector is unchecked), then when I click on the combobox, It becomes active, but nothing changes.

    ss2.png

    Anyway, I ended up making my own combo box, and I'm sticking with it for now.
     
  30. How-Yong-Jun

    How-Yong-Jun

    Joined:
    Apr 23, 2014
    Posts:
    1
    Currently I'm only able to close the combo box by selecting the item or pressing the combo box button. May I know is there a way to collapse the combo box if i click anywhere on the screen? Any guidance is appreciate.
     
  31. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    1,566
    Just came across this via the Unity UI Extensions Collection, the comboBox there which appears to be based on the ones presented here would not work either. When looking at your screenshot though I noticed the scale on the Scroll Panel had become zero. Checking the Overlay and ScrollPanel in the combo box version I had both of those were zero too. That would go along way to explain why you can no longer see this content.

    Checking through the source code I think I see where this is happening, in 'RedrawPanel()' where the overlay and scrollpanel are both temporarily unlinked from the parents then relinked later. Quite why it ends up with zero scaling i'm not sure, but the simple fix for me was to add

    Code (CSharp):
    1.     _overlayRT.localScale         = Vector3.one;
    2.     _scrollPanelRT.localScale     = Vector3.one;
    at the end of the conditional check for '_hasDrawnOnce'.

    In otherwords
    Code (CSharp):
    1.         private void RedrawPanel()
    2.         {
    3.             float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
    4.             _scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
    5.             if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
    6.             {
    7.                 _hasDrawnOnce = true;
    8.                 _inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
    9.                 _inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
    10.  
    11.                 _scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
    12.                 _scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
    13.  
    14.                 //make the overlay fill the screen
    15.                 _overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
    16.                 _overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x);
    17.                 _overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y);
    18.  
    19.                 _overlayRT.SetParent(transform, true);//reattach to this object
    20.                 _scrollPanelRT.SetParent(_overlayRT, true); //reattach the scrollpanel to the overlay
    21.  
    22.                 _overlayRT.localScale         = Vector3.one;
    23.                 _scrollPanelRT.localScale     = Vector3.one;
    24.             }
    25.  
    26.            <snip>
    27.         }
     
  32. demon_666

    demon_666

    Joined:
    Jun 22, 2015
    Posts:
    1
    Hello everyone,
    I am a newby in unity, I am just trying to find some combobox to learn how to use it,
    thank you to discuss about it,
    I want to ask about, how to get a selected item value in string with this combobox.
    Thanks.
     
  33. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
    Hello, demon_666.
    Thank You for Your interest. Sorry for not supporting thi version of combobox anymore. I was working on a new one.
     
  34. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
  35. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,095
    So this requires Unity 5.2? We've got a project stuck on 4.6 and I'm trying to get your free Combo Box working, but uGUI loses all script references when I import the package, and I can't find enough information to reconstruct the combo box in my project.
     
  36. Kender

    Kender

    Joined:
    Nov 16, 2012
    Posts:
    284
    Not sure, if my new combo will work on 4.6.
     
  37. Crixu

    Crixu

    Joined:
    Aug 25, 2014
    Posts:
    21
    How would I create a script that allows me to dynamically create buttons for resolutions in the latest provided package?
    I'm a noob in programming so help would be appreciated!
     
  38. assaf-cohen

    assaf-cohen

    Joined:
    Sep 27, 2013
    Posts:
    92
    I couldn't find RedrawPanel() (I'm using unity 4.6, I guess there are other versions of the script),
    Here is what worked for me:
    In ComboBox.cs, method ToggleComboBox(), just after FixScrollOffset()
    I added:
    scrollPanelGO.GetComponent<RectTransform>().localScale = Vector3.one;
     
  39. KazYamof

    KazYamof

    Joined:
    Jun 26, 2015
    Posts:
    58
    Unity 5.2 has a combobox now. Just saying.
     
    Yukichu and GibTreaty like this.
  40. ZiQiang420

    ZiQiang420

    Joined:
    May 13, 2016
    Posts:
    1
    Great thx. It's very help for me.
     
unityunity