c# - 如何使用 C# 和 Unity 知道设备是否已插入

标签 c# unity3d

我正在制作游戏,想知道: 如何在 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/

相关文章:

c# - int[] 和 string[] 类在哪里定义?

c# - 如何在unity3d中隐藏InputField附加输入框

c# - 来回旋转游戏对象

c# - 值为 null,但检查返回其他值?

c# - 更改访问修饰符

ios - 如何为 iOS 构建 Unity3d 插件

c# - 使用 Entity Framework 时为 Select() 创建通用选择器

c# - Sum ListView 特定列

c# - 项目中资源文件夹和图像/文件的真实路径?

c# - 使用哪些设计模式来实现该业务逻辑?