简体   繁体   English

Google Cardboard Unity SDK 倾斜无法在设备上运行

[英]Google Cardboard Unity SDK Tilted not working on a device

I'm trying to make an app that responds to the Cardboard.SDK.Tilted flag in some Update() method.我正在尝试在某些 Update() 方法中制作一个响应 Cardboard.SDK.Tilted 标志的应用程序。

When running in Unity Player, by pressing the Esc button, Cardboard.SDK.Tilted is set to true, so here's all good.在 Unity Player 中运行时,通过按 Esc 按钮,Cardboard.SDK.Tilted 被设置为 true,所以一切都很好。 But when i Build the app for Android, Cardboard.SDK.Tilted stays false if I tilt the device.但是当我为 Android 构建应用程序时,如果我倾斜设备,Cardboard.SDK.Tilted 保持错误。 Other VR apps with tilt actions work fine on my phone.其他带有倾斜动作的 VR 应用程序在我的手机上运行良好。 Is there any other option I have to enable before building for Android to make this work?在为 Android 构建之前,我还需要启用其他选项吗?

I'm using Unity v5.3.3f1 and a Cardboard SDK v0.6, the devices I've tried on are Xperia Z2, Samsung Galaxy S3 and iPhone 6.我使用的是 Unity v5.3.3f1 和 Cardboard SDK v0.6,我试过的设备是 Xperia Z2、三星 Galaxy S3 和 iPhone 6。

EDIT: So, I've tried putting this code into both Update() and LateUpdate() methods:编辑:所以,我尝试将此代码放入 Update() 和 LateUpdate() 方法中:

if (Cardboard.SDK.Tilted) {
            print("tilted, next scene");
            NextScene ();
}

When the screen is tilted, new scene should be loaded.当屏幕倾斜时,应加载新场景。 But as I've said, it works only in Unity Player by pressing the Esc button to trigger the tilt, on a real device nothing happens - the Cardboard.SDK.Tilted variable is never set to true.但正如我所说,它只能在 Unity Player 中通过按下 Esc 按钮触发倾斜来工作,在真实设备上什么也没有发生 - Cardboard.SDK.Tilted 变量从未设置为 true。

I've seen on https://recordnotfound.com/cardboard-unity-googlesamples-6780/issues that there was a issue of discontinuation of Tilt in v0.6, is it possible that this is no longer supported?我在https://recordnotfound.com/cardboard-unity-googlesamples-6780/issues上看到,在v0.6中存在停止 Tilt 的问题,这是否可能不再受支持? But it's strange that it works in Unity Player but not on a real device.但奇怪的是它在 Unity Player 中有效,但在真实设备上无效。

I can verify that the Cardboard.SDK.Tilted flag does not appear to working as in previous versions of the SDK.我可以验证 Cardboard.SDK.Tilted 标志似乎不像以前版本的 SDK 那样工作。 The escape button triggers it in the debugger, but the tilt action does not trigger it in builds.退出按钮在调试器中触发它,但倾斜动作不会在构建中触发它。

However, you can implement an equivalent quite simply with Input.acceleration:但是,您可以使用 Input.acceleration 非常简单地实现等效项:

float angle = 80.0f / 360.0f * 2.0f * Mathf.PI;
bool isTilted = Mathf.Abs(Input.acceleration.normalized.x) > Mathf.Sin(angle);
if (Cardboard.SDK.Tilted || isTilted)
{
    //Action here
}

If the device's acceleration is entirely due to gravity, the angle float is the angle of the device from horizontal.如果设备的加速度完全是由重力引起的,则角度浮动是设备与水平面的角度。 Attempting to normalize a Vector3 that is too small sets it to zero, so small vectors shouldn't trip the conditional.尝试规范化太小的 Vector3 会将其设置为零,因此小向量不应触发条件。 Pre-calculate your sine to save a cycle.预先计算您的正弦以节省周期。

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

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