0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Unity WebGLのローカルサーバーを起動する方法(Windows版)(Unity6対応)

Posted at

UnityのWebGLの開発で、ビルドを実行しようとすると、以下のことが不便でした。

  • 「Build And Run」からだと、毎回ビルドするし、ポート番号も変わってしまう
  • python -m http.server 8000npx http-serverだと、Gzipに対応していないので、ビルド設定をいじらないといけない。インストールする必要もある

「何とかならないものか」と手段を調べてみると、Unityエディタのフォルダの中にある「SimpleWebServer.exe」を直接起動する方法が見つかりました。
以下、そのコマンドです。
buildFolderが、開きたいビルドしたWebGLアプリのフォルダとしています)
(バージョンは適宜置き換えてください)
(デフォルトでインストールした場合のフォルダです)

  • Unity 6000.0.48f1 の場合
"C:\Program Files\Unity\Hub\Editor\6000.0.48f1\Editor\Data\MonoBleedingEdge\bin\mono.exe" "C:\Program Files\Unity\Hub\Editor\6000.0.48f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\SimpleWebServer.exe" buildFolder http://localhost:8000/
  • Unity 2022.3.60f1 の場合
"C:\Program Files\Unity\Hub\Editor\2022.3.60f1\Editor\Data\MonoBleedingEdge\bin\mono.exe" "C:\Program Files\Unity\Hub\Editor\2022.3.60f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\SimpleWebServer.exe" buildFolder 8000
  • Unity 2021.3.45f1 の場合
"C:\Program Files\Unity\Hub\Editor\2021.3.45f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\SimpleWebServer.exe" buildFolder 8000

上記のコマンドを「コマンドプロンプト」などから実行すると起動できます。
毎回入力するのが面倒であれば、batファイルなどにするといいでしょう。


最初は2021では起動したものの、2022・6ではエラーで起動せず。
どうしたらいいかと調べたら、monoで起動していたみたいだったので、それを試してみたら2022でも起動しました。
また、6ではポート番号からURLに変更になったようで、そちらを変更してみたら上手くいきました。

困っている人の参考になれば幸いです。
以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?