このページでは、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 プロジェクト の構造は以下のとおりです。
Unity を別の Android Gradle プロジェクトに統合するには、settings.gradle ファイルを使用して、生成された Android Gradle プロジェクトの unityLibrary モジュールを Android Unity プロジェクトに加える必要があります。
この リポジトリ には、Unity を Android アプリケーションに統合する方法を示すサンプルプロジェクト、プラグイン、ドキュメントが不含まれています。
プレイヤーをコントロールするには、インテントを引き継いで Unity のアクティビティを起動し、必要に応じて拡張します。詳細は、Android デベロッパードキュメントの インテントとインテントフィルタ を参照してください。UnityPlayer Java API を使用することもできます。
IUnityPlayerLifecycleEvents は Unity Player の 2 つの重要なライフサイクルイベントと相互作用する方法を提供します。
Application.Unload
または UnityPlayer.unload()
が Unity Player をアンロードするときに、アプリケーションは IUnityPlayerLifecycleEvents.onUnityPlayerUnloaded
を呼び出します。これにより、Unity プレイヤーは一時停止の状態になり、すべてのシーンがアンロードされますが、他のすべてのシーンはメモリにロードされたままになります。IUnityPlayerLifecycleEvents.onUnityPlayerQuitted
を呼び出します。Unity を実行していたプロセスは、この呼び出しの後に終了します。IUnityPlayerLifecycleEvents
のインスタンスを UnityPlayer コンストラクターに渡すことができます。または、UnityPlayer
と UnityPlayerActivity
のサブクラスでメソッドをオーバーライドできます。
Unity はランタイムの ライフサイクルを コントロールしないため、ライブラリとしての Unity はすべてのシナリオで機能するわけではありません。既知の制限は以下のとおりです。
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.