I’ve been trying to get a combobox working as a compound gui element but am not having much success. This code does what I want but can anyone help turn it into a compound?
public var menuItems : String[];
public var mySelectedItem : String;
public var customButton : GUIStyle;
public var customSelectionGrid : GUIStyle;
private var scrollPosition : Vector2;
private var showMenu : boolean = false;
function OnGUI() {
if(GUI.Button(Rect(0,0,100,20), mySelectedItem, customButton)) {
showMenu = !showMenu;
}
if(showMenu) {
var s : int = 0;
GUILayout.BeginArea(Rect(0,20,100,60));
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
s = GUILayout.SelectionGrid(s, menuItems, 1, customSelectionGrid);
mySelectedItem = menuItems[s];
GUILayout.EndScrollView();
GUILayout.EndArea();
}
}
Like I said, it works but I’d like to get it into it’s own function, so that I can use it something like so:
mySelectedItem = ComboBox(buttonRect, screenRect, mySelectedItem, items);
The problem as I see it is the ‘showMenu’ flag. If I put it inside the function it gets reset (makes sense!) but I don’t want to have to remember to declare it outside the function every time I use the combobox.
Anyone have any ideas? My current solution involves creating a class and then calling it’s ‘drawComboBox’ function. This works but I’m hoping I can avoid that and get it working like the built-in GUI elements work.
Thanks!
psx