Search Unity

Selection List

Discussion in 'Immediate Mode GUI (IMGUI)' started by mattimus, Jul 21, 2008.

  1. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    I need to work with a menu system that has large quantities of individually selectable items. The best way I've found to handle this is to put them into a lable like this:



    This much I can get done within Unity. The difficulty arises when I start to deal with user interaction:

    - Making the selection bar
    - Swapping text color of the list item within the selection bar
    - dynamic text within list items to swap out when something has been purchased
    -firing an event when an item is selected and clicked or enter is pressed
    -how to handle cursor movement input from the user. I'd like both keyboard and mouse support for the list.

    Are there any resources out there on how to do more advanced things like this with the Unity GUI system? I've been through the GUI Scripting Guide and that mostly focuses on menus that use buttons and sliders.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Create a GUIStyle for the highlight and set GUI.style to use that before the selected item.
    Set GUI.color (like GUI.style in the first one)
    Code (csharp):
    1.  
    2. if (itemIsPurchased) GUILayout.Label("Item");
    3. else GUILayout.Label("Item (purchased)");
    4.  
    For that one, you'll probably have to make the items buttons using a label style, as opposed to labels.
    Most everything else is pretty standard programming (at least standard game programming) stuff. You can use if statements, loops, etc in GUI functions just like anywhere else.
     
  3. mattimus

    mattimus

    Joined:
    Mar 8, 2008
    Posts:
    576
    I've made considerable progress in my menu system. I started using a SelectionGrid for the various menu items. I'm close to the desired results, but there are a few tweaks yet that I can't solve.

    You can see what I have so far here:
    http://mheiniger.com/stuff/MenuSystem.html
    (for code, see attached)

    Arrow Keys navigate the highlight to scroll through the index of the buttons. Pressing enter will activate the selected button. Also, clicking on any one of the buttons will activate that button and change the selection to that button.

    Where I'm stuck:
    -Index currently numbers from left to right and then wraps down to the next line. Can a SelectionGrid be set up to scroll vertical and then wrap to the next column?
    -From what I can tell, SelectionGrids do not allow for empty spaces between buttons. The only way I can figure to put in group headers is to make multiple selection grids. However, each grid would start out with its index back at 0. Is it possible to append to a grid array somewhere else in the group?
     

    Attached Files: