Version: 2023.1
Developing for Android
Input for Android devices

Android 移动端脚本

For cross-platform Projects, use the UNITY_ANDROID define directive to conditionally compile Android-specific C# code. For more information, refer to Platform dependent compilation.

Access device-specific features and properties

Applications can access most features of an Android device through the Input and Handheld classes. For more information, see:

振动支持

To trigger a vibration, call Handheld.Vibrate. Devices without vibration hardware ignore this call.

活动指示器

Mobile operating systems have built-in activity indicators your application can use during slow operations. For more information, refer to Handheld.StartActivityIndicator.

To access device-specific properties, use these APIs:

脚本 设备属性
SystemInfo.deviceUniqueIdentifier 始终返回 ANDROID_ID 的 md5。有关更多信息,请参阅 Android 开发者文档的 ANDROID_ID 部分。
SystemInfo.deviceName 返回设备名称。对于 Android 设备,Unity 会尝试从安全系统设置中读取 device_namebluetooth_name。如果这些字符串没有值,Unity 将返回 <unknown>
SystemInfo.deviceModel 返回设备型号。这通常包括制造商名称和型号(例如“LGE Nexus 5”或“SAMSUNG-SM-G900A”)。
SystemInfo.operatingSystem 返回操作系统名称和版本。
Developing for Android
Input for Android devices