简体   繁体   English

如何检查智能手机在Unity3D中是否具有陀螺仪?

[英]How to check if the smartphone has gyroscope in Unity3D?

I'm using the Google Cardboard SDK . 我正在使用Google Cardboard SDK In older versions of Google Cardboard SDK , it included a file named AndroidManifest.xml 在旧版本的Google Cardboard SDK中 ,它包含一个名为AndroidManifest.xml的文件。

<uses-feature android:name="android.hardware.sensor.gyroscope" android:required="true"/>

So a solution could be to simple add that file back to my project. 因此,解决方案可能是简单地将该文件添加回我的项目中。

However I don't like it because if I do it, the app is hidden in Google Play if the device doesn't have a gyroscope, and that's confusing for the users because they tend to search for it in Google Play. 但是,我不喜欢它,因为如果这样做,该设备没有陀螺仪,则该应用程序会隐藏在Google Play中,这对用户造成困扰,因为他们倾向于在Google Play中进行搜索。

So, how can I check if the device has a gyroscope from the code to show a message to the user like: this smartphone does have gyroscope. 因此,如何从代码中检查设备是否具有陀螺仪,以向用户显示消息,例如:此智能手机确实具有陀螺仪。 Please try with another smartphone. 请尝试使用其他智能手机。

You can check if there is a gyro sensor on the device with Input.isGyroAvailable 您可以使用Input.isGyroAvailable检查设备上是否有陀螺仪传感器

if (Input.isGyroAvailable)
{
    //Gyro is available
}

That's now deprecated and should be used for really old version of Unity. 现在已弃用,应该用于真正的旧版Unity。 For newer version of Unity, use SystemInfo.supportsGyroscope . 对于较新版本的Unity,请使用SystemInfo.supportsGyroscope

if (SystemInfo.supportsGyroscope)
{
    //Gyro is available
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM