SelectList

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Component code)
(Usage)
Line 23: Line 23:
 
== Usage ==
 
== Usage ==
  
<csharp>
+
<csharp> currentSeletion = SelectList( myList, currentSelection, GUI.skin.GetStyle( "Button" ), GUI.skin.GetStyle( "Label" ) );
currentSeletion = SelectList( myList, currentSelection, GUI.skin.GetStyle( "Button" ), GUI.skin.GetStyle( "Label" ) );
+
 
</csharp>
 
</csharp>
  
 
In this example, myList could be an ArrayList of strings or instances of your own type, returning the desired list label in ToString.
 
In this example, myList could be an ArrayList of strings or instances of your own type, returning the desired list label in ToString.

Revision as of 05:35, 27 August 2008

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" ) ); </csharp>

In this example, myList could be an ArrayList of strings or instances of your own type, returning the desired list label in ToString.

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox