You can use IL2CPP as an alternative to Mono for scripting backend when building projects for Windows Player.
IL2CPP を使用してプロジェクトをビルドする場合、Unity はネイティブのバイナリを作成する前に、IL コードをスクリプトやアセンブリから C++ に変換します。詳細は IL2CPP を参照してください。
You can add C++ (.cpp) code files directly into a Unity Project when using the IL2CPP scripting backend. The C++ files act as plugins within the Plugin Inspector. If you configure the C++ files to be compatible with Windows Player, Unity compiles them together with C++ code that gets generated from managed assemblies.
To view the plugin importer settings for C++ files, click a .cpp file and select the appropriate Windows option in the Platform settings section of the Inspector:
関数は生成された C++ コードでまとめてリンクされているため、_P/Invoke
への別の DLL はありません。このため、DLL 名の代わりに "__Internal"
キーワードを使用します。これにより、関数をランタイムにロードするのではなく、関数を解決するのは C++ リンカーの役割となります。以下はその例です。
[DllImport("__Internal")]
private static extern int
CountLettersInString([MarshalAs(UnmanagedType.LPWStr)]string str);
You can define this kind of function in NativeFunctions.cpp
as follows:
extern "C" **declspec(dllexport) int **stdcall CountLettersInString(wchar_t* str)
{
int length = 0;
while (*str++ != L'\0')
length++;
return length;
}
Because the linker resolves the function call, any error made in the function declaration on the managed side (C# code that executes under managed run time) produces a linker error instead of a run-time error. This means, no dynamic loading can take place during run time, and the function is called directly from C#, which significantly decreases the performance overhead of a P/Invoke
call.
Unity compiles source code plug-ins with the same C++ compiler arguments as the generated C++ code, which can’t be modified. If some plug-in source code requires control over C++ compiler arguments, you must build a native plug-in instead. For more information, see Native plug-in.
A project using the IL2CPP scripting backend typically produces these files:
The following files are common to projects that use IL2CPP:
ファイル | 説明 |
---|---|
a_Data | ゲームデータを持つフォルダー |
a.exe | メインのゲーム実行ファイル |
UnityCrashHandler64.exe | クラッシュハンドラの実行ファイル |
UnityPlayer.dll | すべてのネイティブコードを含む Unity Player ライブラリ |
WinPixEventRuntime.dll | PIX for Windows runtime. This file is present only in development builds. |
a_BackUpThisFolder_ButDontShipItWithYourGame | ゲームのデバッグに必要なデータを格納するフォルダー。PDB (デバッグ情報) ファイルや、スクリプトから生成された C++ コードなどが含まれます。このフォルダーは、ビルドを出荷するたびにバックアップする必要がありますが、再配信しないでください。 |
GameAssembly.dll | IL2CPP ランタイムとすべてのスクリプトコードを含むライブラリ |
SymbolMap | File containing a list of all managed function addresses and their lengths. IL2CPP needs this to resolve managed stack traces. If you delete it, you can still run your game but there’s no gurantee that exceptions will generate sensible call stacks. |
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.