Hi guys and gals, I’ve been trying to get a Filebrowser working for the unity webplayer but I can not get it to work. The browser works perfectly within the unity application but once compiled and brought into a browser it does not work. I’d imagine it has something to do with the path being used and if not that maybe the DirectoryInfo does not work with web locations. Any ideas?
string location = Application.dataPath+"/Models/";
public Vector2 fileScroll = new Vector2(20,30);
public bool fileBrowser;
public GUISkin guiskin;
public bool FileBrowser( ref string location, ref Vector2 fileScroll )
{
bool complete;
DirectoryInfo directoryInfo= new DirectoryInfo(@Application.dataPath+"/Models/");
FileInfo fileSelection;
int contentWidth;
// Return state - altered by the "Select" button
complete = false;
// Handle the files list
GUILayout.BeginArea( ( new Rect( 20, 40, 500, 300 )));
GUILayout.Label( "Files:" );
fileScroll = GUILayout.BeginScrollView( fileScroll );
fileSelection = SelectList( directoryInfo.GetFiles(),null) as FileInfo;
GUILayout.EndScrollView();
GUILayout.EndArea();
if( fileSelection != null )
// If a file was selected, update our location to it
{
location = fileSelection.FullName;
}
// The manual location box and the select button
GUILayout.BeginArea( new Rect( 10, 350, 410, 20 ) );
GUILayout.BeginHorizontal();
GUILayout.Label( location );
contentWidth = ( int )GUI.skin.GetStyle( "Button" ).CalcSize( new GUIContent( "Select" ) ).x;
if( GUILayout.Button( "Select", GUILayout.Width( contentWidth ) ) )
{
complete = true;
}
GUILayout.EndHorizontal();
GUILayout.EndArea();
return complete;
}
public static object SelectList( ICollection list, object selected)
{
foreach( object item in list )
{
if( GUILayout.Button( item.ToString()))
{
if( selected == item )
selected = null;
else
selected = item;
}
}
return selected;
}