SelectList

From Unify Community Wiki
Revision as of 21:21, 26 August 2008 by AngryAnt (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

By AngryAnt.

Description

Visualises a list of strings or objects overriding ToString and returns the item selected by the user.

Component code

<csharp> public static object SelectList( ICollection list, object selected, GUIStyle defaultStyle, GUIStyle selectedStyle ) { foreach( object item in list ) { if( GUILayout.Button( item.ToString(), ( selected == item ) ? selectedStyle : defaultStyle ) ) { selected = item; } }

return selected; } </csharp>

Usage

<csharp> currentSeletion = SelectList( myList, currentSelection, GUI.skin.GetStyle( "Button" ), GUI.skin.GetStyle( "Label" ) ); // myList could be an ArrayList of strings or of your own type which returns its label text in ToString </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox