Template for a Unity WebGL Player
using HTML File drag-and-drop
interfaces
- Using
Unity WebGL Player
(Web) - Want to Load a local file selected by the user.
- Simple UI: File
Drag and drop
into the frame.
- Platform:
Unity WebGL Player
- Dependent APIs: HTML drag-and-drop interfaces (HTML5 File APIs)
- Unity 2018.2.6f1
- Windows 10 (64 bit)
- Google Chrome 68.0.3440.106 (64 bit)
- View ☛ Example WebGL
- You can drop your local file into the WebGL frame.
SIZE:
will show the size [bytes] of the file.
- Open
FileReceiver
/Example
/Scenes
/SampleScene.unity
- Modify it or clone it.
- Create your script file by copying
FileReceiver.cs
orFileReceiverStats.cs
. - Here, assumes that you set the file name
MyFileReceiver.cs
and the class nameMyFileReceiver
. - Add your C# code into
LoadFile
method. (Your turn) - Select the GameObject named
FileReceiver
(or create it when a new scene) - Add the component
MyFileReceiver
(and remove the componentsFileReceiver
/FileReceiveStats
if it exists) - Open the
Main Menu
:File
/Build Settings…
. - Switch
Platform
toWebGL
(if not set) - Open
Player Settings…
and switchPlayerSettings
/Settings for WebGL
/WebGL Template
➡FileReceiver
(if not set) - Push
Build And Run
onBuild Settings
. (and wait building…) - Built WebGL page will open by your web browser.