Version: 2022.3
言語: 日本語
Android プレイヤーのコマンドライン引数を指定する
Android のディープリンク

Unity を Android アプリケーションに統合

このページでは、Unity Runtime Library をライブラリ機能として Android アプリケーションに統合する方法を説明します。

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

重要: プロジェクトを Unity 2019.4 以上にアップグレードする場合、Unity as a Library の導入によって、Android 向けに正しく動作するように ネイティブマネージ のプラグインを調整する必要があるかもしれません。Gradle マニフェストに変更を加えるプラグインは、Using Unity as a library in native iOS/Android apps で概説されている Gradle の変更を使用する必要があります。

仕組み

Unity から Gradle プロジェクトをビルドする場合は、特になにも変更する必要はありません。

Unity が生成するすべての Android Gradle プロジェクト の構造は以下のとおりです。

  • A library part in the unityLibrary module that you can integrate into any other Gradle project. This contains the Unity runtime and Player data.
  • A thin launcher part in the launcher module that contains the application name and its icons. This is a simple Android application that launches Unity. You can replace this module with your own application.

Unity を別の Android Gradle プロジェクトに統合するには、settings.gradle ファイルを使用して、生成された Android Gradle プロジェクトの unityLibrary モジュールを Android Unity プロジェクトに加える必要があります。

この リポジトリ には、Unity を Android アプリケーションに統合する方法を示すサンプルプロジェクト、プラグイン、ドキュメントが不含まれています。

プレイヤーをコントロールするには、インテントを引き継いで Unity のアクティビティを起動し、必要に応じて拡張します。詳細は、Android デベロッパードキュメントの インテントとインテントフィルタ を参照してください。UnityPlayer Java API を使用することもできます。

IUnityPlayerLifecycleEvents

IUnityPlayerLifecycleEvents は Unity Player の 2 つの重要なライフサイクルイベントと相互作用する方法を提供します。

  • Unload - The application calls IUnityPlayerLifecycleEvents.onUnityPlayerUnloaded when Application.Unload or UnityPlayer.unload() unloads the Unity Player. This puts the Unity Player in a paused state where it unloads all Scenes, but keeps everything else loaded in the memory.
  • Quit - The application calls IUnityPlayerLifecycleEvents.onUnityPlayerQuitted when the Unity Player quits. The process that was running Unity ends after this call.

IUnityPlayerLifecycleEvents のインスタンスを UnityPlayer コンストラクターに渡すことができます。または、UnityPlayerUnityPlayerActivity のサブクラスでメソッドをオーバーライドできます。

制限

Unity はランタイムの ライフサイクルを コントロールしないため、ライブラリとしての Unity はすべてのシナリオで機能するわけではありません。既知の制限は以下のとおりです。

  • Unity as a Library only supports full-screen rendering, and doesn’t support rendering on part of the screen.
  • You can’t load or integrate more than one instance of the Unity runtime.
  • You might need to adapt third-party plug-ins (both native and managed) to work with the Unity runtime.
  • Unity as a Library isn’t compatible with the Xamarin app platform.

その他の参考資料

Android プレイヤーのコマンドライン引数を指定する
Android のディープリンク
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961