How do I run a local Unity WebGL (file:// url) build?

我怕爱的太早我们不能终老 提交于 2020-12-06 15:48:28

问题


Multiple browsers (Chrome, Firefox, Internet Explorer) give the following error when trying to open a local Unity WebGL build:

It seems your browser does not support running Unity WebGL content from file:// urls. Please upload it to an http server, or try a different browser.

Microsoft Edge is able to run it, but I would like to know if there are any settings that can be changed to get it to run on Chrome/Firefox/other browsers.


回答1:


The correct way to run your Unity-WebGL app locally is to use a simple server.

Even Unity itself runs as a small web server run you run a WebGL build from the editor.

Here's one, Here's another, here's a whole list others

Turning off your browser security is as poor advice as turning off your virus scanner or your firewall. Don't do it. Especially when the correct way is so trivial.




回答2:


These instructions were found in Dr. Tim Chamillard's game development course:

Firefox (recommended browser for running WebGL)

  1. Type about:config in the navigation bar
  2. Search for the security.fileuri.strict_origin_policy parameter
  3. Click that parameter to change it to false

Chrome

  1. Add a shortcut to Chrome on your desktop if you don't have one
  2. Right click the shortcut and select Properties
  3. Select the Target text box, go to the end, add a space and add --allow-file-access-from-files
  4. Double-click the index html file for the WebGL build and copy the URL in the navigation bar when the browser opens
  5. Close the browser
  6. Start the browser using the shortcut, paste in the URL you copied in Step 4 and press enter

Microsoft Edge

No need to do anything, WebGL builds work fine.

Safari

  1. Enable the develop menu using the preferences panel, under Advanced → “Show develop menu in menu bar”
  2. From the safari “Develop” menu, select “Disable local file restrictions”

As a general rule, restart your computer after making these changes since browsers require it and some don't.




回答3:


just open your terminal and go into your directory (where the HTML file lies), and start the server using one of the commands below.

python -m CGIHTTPServer 8360
python -m http.server --cgi 8360
python3 -m http.server --cgi 8360

This will open the port for you.

Then direct your browser to http://localhost:8360/YOURFILENAME.html The default one would usually be index.html ;)



来源:https://stackoverflow.com/questions/62517962/how-do-i-run-a-local-unity-webgl-file-url-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!