Unity WebGL は、HTML5 ゲームパッド API をサポートするブラウザーのゲームパッドとジョイスティック用に Input と InputSystem をサポートしています。
一部のブラウザーは、アプリケーションがフォーカスされている間にエンドユーザーがデバイスと相互作用した後にのみ、入力デバイスへのアクセスを許可します。この種のセキュリティ対策は、エンドユーザーが、接続されたデバイスをブラウザーフィンガープリント目的で使用することを妨げます。このため、アプリケーションは、Input.GetJoystickNames() の呼び出しによる接続デバイスのチェック前に、ゲームパッド/ジョイスティックのボタンを押すようにユーザーに指示する必要があります。
古い入力システム用の WebGL ゲームコントローラーマッピングは、W3 仕様 と一致しており、ボタンのマッピングレイアウトは以下のようになっています。
ボタン | 説明 |
---|---|
buttons[0] | 右クラスターの下ボタン = CROSS (X) |
buttons[1] | 右クラスターの右ボタン = CIRCLE |
buttons[2] | 右クラスターの左ボタン = SQUARE |
buttons[3] | 右クラスターの上ボタン = TRIANGLE |
ノート: WebGL は W3 仕様 に準拠しているため、他のプラットフォームと一致しない場合があり、複数のプラットフォーム (Windows とウェブなど) を同時にターゲットにしている場合に独自の処理が必要になります。
Unity WebGL doesn’t officially support mobile devices (see WebGL browser compatibility) yet, but it does implement Input.touches and other related APIs in browsers and devices with touch support. By default, mobile devices display a soft keyboard on the touch screen for entering text into UI input fields. To disable this behavior, use the WebGLInput.mobileKeyboardSupport property.
デフォルトでは、Unity WebGL は、WebGL キャンバスがフォーカスされているかどうかに関わらず、ウェブページが受け取る全てのキーボード入力を処理します。これにより、エンドユーザーが、WebGL キャンバスをクリックすることなくキーボードベースのアプリケーションを使用できるようになります。
以下は、特定のキーボード入力に関するノートです。
キーボード入力の動作 | 説明 |
---|---|
HTML 要素 (テキストフィールドなど) | 一般的には、HTML 要素 (テキストフィールドなど) を導入すると、(それがキーボード入力を受け取るウェブページに含められた場合に) エラーが発生する可能性があります。Unity は、ページの他の部分が入力を受け取れる状態になる前に入力イベントを消費します。 HTML 要素がキーボード入力を受け取るようにするには、 WebGLInput.captureAllKeyboardInput を false に設定します。こうすることで、アプリケーションは、WebGL キャンバスにフォーカスがある場合にのみ入力を受け取るようになります。 |
Esc キー | Esc キーはウェブ環境では保護されているため、Safari のように全画面モードに切り替えるための使用をブロックするブラウザーや、Google Chrome のように動作が予測できないブラウザーもあります。ブラウザーが全画面モードになっている時は、Esc キーは全画面モードを終了する動作のために予約されています。ブラウザーの種類によっては、Esc キーをクリックしてもブラウザーからアプリケーションに転送するイベントがトリガーされるとは限りません。 |
HideMobileInput |
TextMeshPro (TMP としても知られる) 入力フィールドの HideMobileInput オプションは、ウェブプラットフォームには影響しません。これは、ブラウザーで仮想キーボードをトリガーするためにはテキスト入力フィールドが必要なためです。ウェブプラットフォームは、Unity プレーヤーがテキスト入力を想定している時に、テキスト入力フィールドをインスタンス化して仮想キーボードをトリガーします。これは、他のプラットフォーム同様に、仮想キーボードの上に表示されます。仮想キーボードはモバイルのテキスト入力フィールドに依存するため、ウェブプラットフォームでこの表示が隠れることはありません。 |
Unity WebGL は公式にはモバイルデバイスをサポートしていません (WebGL のブラウザー互換性 参照) が、タッチをサポートするブラウザーやモバイルデバイスで、以下のセンサーをサポートしています。
Important: Browsers allow sensor input only in secure contexts, which means, you must serve the page over HTTPS. The single exception is http://localhost
, which you can use during development.
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.