我正在制作游戏,想知道: 如何在 Unity 中使用 C# 纯代码知道 Android 设备是否已插入(即电池正在充电)?
最佳答案
设备已插入:
SystemInfo.batteryStatus == BatteryStatus.Charging || SystemInfo.batteryStatus == BatteryStatus.Full || SystemInfo.batteryStatus == BatteryStatus.NotCharging
电池正在充电:
SystemInfo.batteryStatus == BatteryStatus.Charging
来源:
https://docs.unity3d.com/ScriptReference/SystemInfo-batteryStatus.html
Returns the current status of the device's battery (Read Only).
See the BatteryStatus enumeration for possible values.
The battery status includes information about whether the device is plugged in to a power source and whether the battery is charging. If battery status is not available on your target platform, this property returns BatteryStatus.Unknown.
https://docs.unity3d.com/ScriptReference/BatteryStatus.html
未知 无法确定设备的电池状态。如果电池状态在您的目标平台上不可用,SystemInfo.batteryStatus 将返回此值。
充电设备已插入并正在充电。
Discharge Device 已拔下并正在放电。
NotCharging 设备已插入,但未充电。
完整设备已插入且电池已充满。
关于c# - 如何使用 C# 和 Unity 知道设备是否已插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49323785/