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 dropinto 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.csorFileReceiverStats.cs. - Here, assumes that you set the file name
MyFileReceiver.csand the class nameMyFileReceiver. - Add your C# code into
LoadFilemethod. (Your turn) - Select the GameObject named
FileReceiver(or create it when a new scene) - Add the component
MyFileReceiver(and remove the componentsFileReceiver/FileReceiveStatsif it exists) - Open the
Main Menu:File/Build Settings…. - Switch
PlatformtoWebGL(if not set) - Open
Player Settings…and switchPlayerSettings/Settings for WebGL/WebGL Template➡FileReceiver(if not set) - Push
Build And RunonBuild Settings. (and wait building…) - Built WebGL page will open by your web browser.