Unity3d runtime file browser
On JavaScript side, you need code like this:. You can build the plugin server from scratch, for example, if you want to change something in communication or page rendering. In general, just build it. Set the TestClient as the startup project. Change the path to SharedPluginServer in Form1. It may crash for the first time when Windows asks for network access , but after that it should work fine.
Go to source. Basic setup Import the package to Unity. Settings Width and height - width and height of the browser texture. Memory file and Port - in general, you can keep them random. IsOpen property to see if there is an active dialog at the moment. If user presses the Cancel button, onCancel callback is called.
When folderMode is set to true , the file browser will show only folders and the user will pick a folder instead of a file. After the dialog is closed, you can check the FileBrowser. Success was set to true , you can use the FileBrowser. If there is an open dialog and the invokeCancelCallback parameter is set to true , the onCancel callback of the dialog will be invoked.
This function can also be used to initialize the file browser ahead of time, which in turn will reduce the lag when you first open a dialog. When icon parameter is left as null , the quick link will have a folder icon. You can extend this list or remove this restriction altogether using the following function:. To select a default filter, use the following function:.
To open files or directories in the file browser with a single click instead of double clicking , you can set FileBrowser. SingleClickMode to true. On Android, file browser requires external storage access to function properly. You can use the following function to check if we have runtime permission to access the external storage:. Note that FileBrowser automatically calls RequestPermission before opening a dialog.
If you want, you can turn this feature off by setting FileBrowser. AskPermissions to false. If you need to allow the user to upload files to your webplayer, you should go through HTML forms for that. I've done that before and a good trick is to have your webplayer run in a frameset with a zero pixel tall data frame which you would use to communicate with the upload process. You can use Application. The trick is then to have this form target the dataframe with your receiving server-side script - overseeing the file upload operation.
Once the upload is completed, your server-side script now outputting to the hidden dataframe should output javascript to hide the HTML form and send the URL of the uploaded file to the webplayer. Thanks for the info. I'm new to all this so it's a bit beyond my reach at the moment. Is there an easy. As far as I know you can't use flash for server-side scripting. I have just made some experiments on user textures loading into the WebPlayer.
Why not use WWWForm to upload the image? In the editor, you can use EditorUtility. OpenFilePanel to show an window in which the user can select a file, and the path of the selected file is returned. You can then use that load the file or do whatever you want with it. I don't know of anything similar you can use in your actual application, but you could use a simple text field in which the user enters the name of the file they want to load.
Creating a full-blown file-select dialog where the user can browser their hard-drive and external devices would be more difficult. I tried the script found at your link called EditorUtility.
0コメント