Version: 2019.3
Windows
Windows 全般

Integrating Unity into Windows and UWP applications

This page describes how to integrate the Unity Runtime Library into Windows and Universal Windows Platform (UWP) applications using the Unity as a Library feature.

この機能を使用して、3D/2D リアルタイムレンダリング、AR 体験、 3D モデルの相互作用、2D ミニゲームなどの Unity 搭載の機能をアプリケーションに組み込むことができます。Unity Runtime Library は、 アプリケーション内でコンテンツをロード、アクティブ化、アンロードするタイミングと方法を管理するための制御へのアクセスを可能にします。

How it works for UWP

The UWP XAML project output type makes it easy to create a UWP project that embeds Unity. The generated Visual Studio project is a general XAML UWP project with a SwapChainPanel setup to load the Unity Project. You can extend or replace this Project with any other non-Unity application business logic.

When using a SwapchainPanel, you might want to render over other elements. This enables you to render a small object with a transparent background on top of other non-Unity application content. To do this, enable the PlayerSettings.WSA-transparentSwapchain option.

You can unload the Unity engine to reclaim resources when Unity is loaded in-process with Application.Unload.

How it works for Windows

On Windows, you can embed Unity into your application in two different ways.

The simplest option is to launch Unity as an external process from your application, and specify a window in which Unity will initialize and render with the -parentHWND command line argument.

The second option is to embed Unity within your existing process. To do this, build Unity into a UnityPlayer.dll, which can be loaded directly by any Win32 application. The entry point signature is:

extern "C" UNITY_API int UnityMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd);

You can use lpCmdLine to pass any command line arguments to Unity to control resolution, job threads, parent HWND, etc. This enables you to run Unity within your process. When Unity is not in view, you can use Application.Unload to reclaim resources it uses.

制限

別のアプリケーションによってホストされている場合 、Unity はランタイムの ライフサイクルを制御しないため、すべてのシナリオで機能するわけではありません。既知の制限は以下のとおりです。

  • Unity ランタイムの複数のインスタンスを読み込んだり、複数の Unity ランタイムを統合したりすることはできません。
  • 正しく動作させるために ネイティブ プラグインと マネージ プラグインの調整が必要な場合があります。

  • Unity as a Library は 2019.3 に追加NewIn20193
Windows
Windows 全般
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961