Android で使用可能なブラウザコンポーネント (WebView
/ GeckoView
) を uGUI (Texture2D) として利用するためのプラグイン
- キーボード入力
- タッチ操作
- ファイルダウンロード (blob, data urlを含む)
- リサイズ
- Javascriptの実行
ドキュメントはこちら
スニペットはこちら
Javaプラグインのソースコードはこちら
- Unity 2021
- Unity 2022
- OpenGLES
- Vulkan
Android13, Adreno 619で実行した画面
OS | Android 10 ~ 14 |
GPU | Qualcomm Adreno 505, 619 |
Unity | 2021.3 |
- TLabVKeyborad
v1.0.1
こちらをご覧ください
以下のコマンドでリポジトリをクローンしてください
git clone https://github.com/TLabAltoh/TLabWebView.git
or
git submodule add https://github.com/TLabAltoh/TLabWebView.git
Unity Package Managerでadd package from git ...
から以下のurlでパッケージをダウンロードしてください
https://github.com/TLabAltoh/TLabWebView.git#upm
このプラグインを使用したアプリをアプリストアに出した場合,以下のような警告を受ける場合があります.
Your application may contain an unsafe implementation of the WebView's onReceivedSslError() method with a call to `handler.proceed() with insufficient validations. This may cause the WebView to ignore SSL certificate validation errors, making the application vulnerable to man-in-the-middle attacks.
your app is using an unsafe implementation of
WebviewClient.onReceivedSslError
handler
その場合は,アプリストアに対応したバージョンのパッケージに切り替えてください.
add package from git URL ...
https://github.com/TLabAltoh/TLabWebView.git#appstore-compatible-upm
アプリストア対応バージョンはセキュアではないウェブサイトを読み込むことができない点をあらかじめご了承ください.
こちらをご覧ください
- Build Settings
Property | Value |
---|---|
Platform | Android |
- Project Settings
Property | Value |
---|---|
Color Space | Linear |
Minimum API Level | 26 |
Target API Level | 30 (Unity 2021), 31 ~ 32 (Unity 2022) |
- Project Settings --> Player --> Other Settings に以下のシンボルを追加(ビルド時に使用)
UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
- Scene
BrowserManager
をシーン内のいずれかのGameObjectにアタッチしてください.(EventSystemにアタッチするのが一番望ましいかも ...).
PluginsフォルダーをAssets以下に作成し,以下のファイルを置いてください.また,BrowserContainer.browser
にWebView
の代わりにGeckoView
をアタッチしてください.また,GeckoView
の使用には API level 33
~ が求められます.Project Settings
からターゲットAPIレベルを33以上に設定してください.
- gradleTemplate.properties
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
# android.enableR8=**MINIFY_WITH_R_EIGHT**
unityStreamingAssets=**STREAMING_ASSETS**
**ADDITIONAL_PROPERTIES**
android.useAndroidX=true
# android.enableJetifier=true
- mainTemplate.gradle
...
dependencies {
implementation "androidx.annotation:annotation-jvm:1.9.1"
def collection_version = "1.4.3"
implementation "androidx.collection:collection:$collection_version"
def lifecycle_version = "2.6.1"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"
}
...
- GeckoView plugin (
.aar
) (現在 125.0.20240425211020 version のみで開発・テストを行っているので,同じバージョンのものをダウンロードしてください.)
以下に置いてあるプレハブをCanvasに追加することでWebViewを実装できます
/Resources/TLab/WebView/Browser.prefab
Note
外部ストレージ(/Download
や/Picture
など)にファイルをダウンロードしたい場合,以下のパーミッションをAndroidManifest.xml
に追加してください.これは,Android 11以降のデバイスで必要になります (詳細はこちら).
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
Warning
Android WebViewは WebXR API をサポートしません.
Warning
OculusQuestはいくつかのHTML5 input タグをサポートしていません(下記参照).それらを使用したい場合,GeckoView
をWebView
の代わりにBrowser
として使用してください.uGUIで実装したウィジェットを表示します.以下は,このプラグインによる,HTML5 inpu タグの対応状況です.
Warning
このプラグインは,OpenGLES
とVulkan
の両方をサポートしていますが,Vulkan API
を使用する場合は,デバイスがOpenGLES 3.1
以上をサポートしている必要があることに留意してください.