Version: 2023.1
言語: 日本語
iOS 用の開発
iOS デバイスの入力

iOS Scripting

iOS デバイスの大半の機能は InputHandheld クラスを介して公開されています。クロスプラットフォームプロジェクトでは UNITY_IPHONE は iOS 独自の C# コードを条件的にコンパイルするために定義されます。

デバイスプロパティ

アクセス可能なデバイス固有のプロパティが多数あります。以下について詳しくは、各スクリプトリファレンスページを参照してください。

海賊版チェック

一般的にアプリケーションがハッキングされると、AppStore DRM プロテクションを外され、アプリケーションを無料で再配布されてしまいます。Unity での海賊版チェックを使用すると、AppStore に提出した後にハッキングによってアプリケーションが変更されたかを判断することができます。

アプリケーションが本物である (ハッキングされていない) かどうかは、Application.authentic](../ScriptReference/Application-genuine.html) プロパティで確認できます。このプロパティが false を返す場合、ハッキングされたアプリケーションを使用していることをユーザーに警告したり、特定の機能を無効にしたりすることができます。

ノート: Application.genuineCheckAvailableApplication.genuine を併用して、アプリケーションの整合性を検証してください。Application.genuine プロパティへのアクセスはリソースを大量に消費するため、フレームの更新やその他のスピードが重視されるコード中には実行すべきではありません。

バイブレーション対応

バイブレーションを行うには Handheld.Vibrate を呼び出します。バイブレーションの機能がないデバイスでは、この呼び出しは無視されることに注意してください。

アクティブティインジケーター

モバイル OS にはビルトインのアクティビティインジケーターがあり、処理に時間がかかる時に表示すると便利です。使用例については Handheld.StartActivityIndicator docs を参照してください。

画面の向き

iOS と Android デバイス両方で、自由にアプリケーションの画面の向きを制御することができます。ユーザーが持っているデバイスの向きの変更を検出したり、特定の向きに固定することによって、ユーザーがデバイスを持つ向きに合わせてゲームの動作を調整することができます。

デバイスの向きは Screen.orientation プロパティを使って取得できます。以下のような向きがあります。

向き 動作
Portrait 縦向きのモードです。デバイスを直立させると、ホームボタンは下になります。
PortraitUpsideDown 縦向きのモードです。ただし、デバイスを直立させると、ホームボタンが上になります。
LandscapeLeft 縦向きのモードです。デバイスを直立させると、ホームボタンが右側になります。
LandscapeRight 縦向きのモードです。デバイスを直立させると、ホームボタンが左側になります。

Set Screen.orientation to one of the above orientations or use ScreenOrientation.AutoRotation to control the screen orientation. When you enable autorotation, you can still disable some orientations on a case-by-case basis.

For more information, refer to the following API documentation:

The screen orientation of your application may vary depending on the device orientation set by the user, regardless of your application’s default orientation setting.

The following table shows the default screen orientation set for your application and the actual orientation the application loads in based on the device orientation.

Default screen orientation: Autorotate Default screen orientation: Portrait Default screen orientation: Landscape
Device orientation: Autorotate The application screen loads in portrait and can rotate between portrait, landscape right, and landscape left orientations (excluding portrait upside down orientation).
Note: On an iPad, the application screen loads in portrait or landscape orientation based on the device orientation. The screen can rotate between portrait, portrait upside down, landscape right, and landscape left orientations.
The application screen loads and remains locked in portrait orientation. Although portrait upside down orientation is allowed, the screen doesn’t rotate to that orientation.
Note: On an iPad, the application screen loads in portrait and can rotate between portrait and portrait upside down orientations. The splash screen can load in landscape orientation if the device orientation is landscape on launch.
The splash screen loads in the same orientation as the device orientation. The application screen loads in landscape when the scene loads and can rotate between landscape left or landscape right orientations.
Note: On an iPad, the application screen loads in landscape, and can rotate between landscape left and landscape right orientations. The splash screen can load in portrait if the device orientation is portrait on launch.
Device orientation: Portrait lock The application screen loads and remains locked in portrait orientation.
Note: Whilst in portrait orientation, if you set the ScreenOrientation.AutoRotation property for portrait to false, the application screen rotates to landscape orientation. If you now set the ScreenOrientation.AutoRotation property for landscape to false, the screen orientation remains unchanged.
The application screen loads and remains locked in portrait orientation. The splash screen loads in portrait orientation, but the application screen loads in landscape when the scene loads. By default, the application screen remains locked in landscape left orientation.
Note: On an iPad, the splash screen loads in portrait orientation and the scene loads in landscape orientation. The application screen remains locked in landscape orientation.
Device orientation: Landscape lock Not applicable as iPhones don’t have landscape lock setting. If the user turns off the device autorotation setting whilst the application is in landscape, the application screen rotates to and remains locked in portrait orientation.
Note: On an iPad, the application loads and remains locked in landscape orientation.
Not applicable as iPhones don’t have landscape lock setting. The application remains locked in portrait orientation.
Note: On an iPad, the splash screen loads in landscape and the scene loads in portrait orientation. The application screen remains locked in portrait orientation.
Not applicable as iPhones don’t have landscape lock setting. The application screen loads in landscape and can remain locked in both landscape left or landscape right orientations when the application loads.
Note: On an iPad, the application screen loads in landscape and remains locked in either landscape left or landscape right orientation depending on the device orientation.

デバイス世代の判断

デバイスの世代によって、サポートされている機能に違いがあり、さらにパフォーマンスも差があります。デバイスの世代は iOS.DeviceGeneration で判断することができます。

ディスプレイカットアウト

一部のディスプレイでは、他のハードウェアが画面の特定の領域を占有しているために、その領域が隠されているか、機能していない場合があります。Screen.cutouts を使用すると、各カットアウトを囲むバウンディングボックスのリストが返されます。

iOS devices don’t provide a native API to get the display cutout information, so the cutouts are hardcoded in the Xcode project for each available iOS device. You can modify existing data or add additional devices in the Unity Xcode project ReportSafeAreaChangeForView function, which is in the UnityView.mm file.

ゲームのリプレイを録画する

ReplayKit を使用して、ゲームのオーディオと動画を記録し、デバイスのマイクとカメラから取り込んだオーディオと動画の解説を加えることができます。

iOS 用の開発
iOS デバイスの入力