Version: 2023.2
言語: 日本語
Embedded resources in Web
Configure a Web Canvas size

Input in Web

ゲームパッドとジョイスティックのサポート

Unity Web supports Input and InputSystem for gamepads and joysticks for browsers that support the HTML5 Gamepad API.

一部のブラウザーは、アプリケーションがフォーカスされている間にエンドユーザーがデバイスと相互作用した後にのみ、入力デバイスへのアクセスを許可します。この種のセキュリティ対策は、エンドユーザーが、接続されたデバイスをブラウザーフィンガープリント目的で使用することを妨げます。このため、アプリケーションは、Input.GetJoystickNames() の呼び出しによる接続デバイスのチェック前に、ゲームパッド/ジョイスティックのボタンを押すようにユーザーに指示する必要があります。

The Web game controller mapping for the old input system aligns with the W3 spec, where the button mapping layout is laid out as follows:

ボタン 説明
buttons[0] 右クラスターの下ボタン = CROSS (X)
buttons[1] 右クラスターの右ボタン = CIRCLE
buttons[2] 右クラスターの左ボタン = SQUARE
buttons[3] 右クラスターの上ボタン = TRIANGLE

Note: As Web follows the W3 spec, it might not be consistent with other platforms, and requires unique handling if you’re targeting multiple platforms simultaneously, such as Windows and Web.

タッチのサポート

Unity Web doesn’t officially support mobile devices (see Web 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.

キーボード入力とフォーカスのハンドリング

By default, Unity Web processes all keyboard input the web page receives, regardless of whether the Web canvas has focus or not. This allows the end user use a keyboard-based application without the need to click on the Web canvas.

以下は、特定のキーボード入力に関するノートです。

キーボード入力の動作 説明
HTML 要素 (テキストフィールドなど) Typically, introducing HTML elements (such as text fields) can cause errors if included in the web page that’s meant to receive keyboard inputs. Unity consumes the input events before the rest of the page can receive them.
To make HTML elements receive a keyboard input, set WebGLInput.captureAllKeyboardInput to false. This way, the application receives input only if the Web canvas has focus.
Esc キー Esc キーはウェブ環境では保護されているため、Safari のように全画面モードに切り替えるための使用をブロックするブラウザーや、Google Chrome のように動作が予測できないブラウザーもあります。ブラウザーが全画面モードになっている時は、Esc キーは全画面モードを終了する動作のために予約されています。ブラウザーの種類によっては、Esc キーをクリックしてもブラウザーからアプリケーションに転送するイベントがトリガーされるとは限りません。
HideMobileInput TextMeshPro (TMP としても知られる) 入力フィールドの HideMobileInput オプションは、ウェブプラットフォームには影響しません。これは、ブラウザーで仮想キーボードをトリガーするためにはテキスト入力フィールドが必要なためです。ウェブプラットフォームは、Unity プレーヤーがテキスト入力を想定している時に、テキスト入力フィールドをインスタンス化して仮想キーボードをトリガーします。これは、他のプラットフォーム同様に、仮想キーボードの上に表示されます。仮想キーボードはモバイルのテキスト入力フィールドに依存するため、ウェブプラットフォームでこの表示が隠れることはありません。

モバイルセンサーのサポート

Unity Web doesn’t officially support mobile devices (see Web browser compatibility), but for browsers and mobile devices with touch support, Unity Web includes support for the following sensors:

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.

その他の参考資料

Embedded resources in Web
Configure a Web Canvas size