Unity は、Emscripten コンパイラー ツールチェーンを使用して、C および C++ で記述された Unity ランタイムコードを WebAssembly(別称 Wasm) にクロスコンパイルします。Emscripten は、生成するコードが小さく、ロード時間とメモリの効率が良く、ネイティブに近い速度での実行を目標に設計されています。Unity における Wasm の詳細については、ブログポスト WebAssembly を参照してください。
Unity は IL2CPP を使用して C# スクリプトの .NET ゲームコードを Wasm に変換します。IL2CPP は .NET バイトコードを取得し、それを対応の C++ ソースファイルに変換します。それが Emscripten を使用してコンパイルされることで、スクリプトが Wasm に変換されます。
Unity bundles the Emscripten compiler with the Web platform package, so that you don’t have to manually download it. The version of Emscripten that the Editor uses varies by Editor version:
Unity バージョン | Emscripten バージョン | サポートされるネイティブプラグインファイル形式 |
---|---|---|
Unity 2023.2 and later | Emscripten 3.1.38-unity | .a、.bc |
Unity 2022.2 以降 | Emscripten 3.1.8-unity | .a、.bc |
Unity 2021.2 以降 | Emscripten 2.0.19.6-unity | .a、.bc |
Unity 2019.2 to 2021.1 | 1.38.11-unity | .bc |
Unity 2018.4 - Unity 2019.2 | 1.37.40-unity | .bc |
Unity 2018.2 - Unity 2018.4 | 1.37.33-unity | .bc |
ノート:
表中のファイル形式のアルファベットは、以下を意味する頭文字です。
.a
).o
).bc
)Unity は、Emscripten 2.0 より前の Emscripten バージョンでは Bitcode
プラグイン (.bc
タイプのファイル) をビルドすることを推奨しています。Emscripten 2.0 以降では、Wasm Object File
プラグイン (.a
タイプの GNU アーカイブファイルにバンドルされた .o
タイプの Wasm オブジェクトファイル) をビルドすることが推奨されます。
Emscripten ツールチェーンの正確なバージョンへのパスは、以下の場所にある emscripten-version.txt
から特定できます。
C:\Program Files\Unity\Hub\Editor\<Editor version>\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emscripten\emscripten-version.txt
Unity アプリケーション用のネイティブ C/C++ プラグインを作成する場合、C/C++ コードをプロジェクトにバンドルする (ネイティブプラグイン 参照) ことも、Emscripten コンパイラーツールチェーンでネイティブコードをプラグインアーカイブに事前にビルドすることも可能です。
プラグインコードを事前にビルドする場合は、Emscripten コンパイラーツールチェーンを使用する必要があります。LLVM バイナリ形式 の互換性を確保するには、プラグインのコンパイルに使用する Emscripten バージョンが、Unity の使用する Emscripten バージョンと一致している必要があります。
通常、プラグインは静的ライブラリアーカイブ形式にコンパイルされます。Unity 2021.2 (Emscripten 2.0) より前のバージョンでは、推奨されるプラグイン形式は LLVM Bitcode ファイル形式 (.bc
) です。
Unity 2021.2 以降で推奨されるプラグイン形式は、WebAssembly オブジェクトファイル (.o
) を含んだ GNU アーカイブファイル形式 (.a
) です。以前の LLVM Bitcode (.bc) プラグインファイルはまだサポートされていますが、これを使用するとコンパイル時間に悪影響が及ぶ可能性があります。
ノート: ネイティブプラグインを、特定の Unity バージョンから (異なるバージョンの Emscripten を使用する) 別のバージョンへ移行する場合、Unity プラグインをソースから再コンパイルすることをお勧めします。なぜなら、LLVM コンパイラープロジェクトは、コンパイラーバージョン間におけるビルドアーティファクトファイルのバイナリ互換性を保証しないためです。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.