简体   繁体   English

在Unity 5中使用Cardboard SDK - 没有触摸事件?

[英]Using Cardboard SDK in Unity 5 - no touch events?

I have a 2D scene that is supposed to show a list of available cardboard scenes (like thumbnails). 我有一个2D场景,应该显示可用的纸板场景列表(如缩略图)。 After the user taps a thumbnail, I am trying to send him to the selected cardboard scene. 用户点击缩略图后,我试图将他发送到选定的纸板场景。 However, I am unable to catch the touch events in the first (list) scene. 但是,我无法捕捉第一个(列表)场景中的触摸事件。 After a tap, nothing happens, simply put. 点击后,没有任何反应,简单地说。 (EDIT: I will add that I tested this only on Android) (编辑:我会补充说我只在Android上测试过这个)

This is what I did to test: 这就是我测试的内容:

  1. I create a new project (Unity 5.0.2f) - 2D 我创建了一个新项目(Unity 5.0.2f) - 2D
  2. I put a UI button and a textfield to the scene 我把UI按钮和文本字段放到了场景中
  3. I add a script that is triggered after clicking the button - it just changes the text of the textfield to "Clicked" --->>> ALL WORKS FINE, tapping the button on the touch screen works as expected, text changed <<<--- 我添加了一个单击按钮后触发的脚本 - 它只是将文本字段的文本更改为“单击”--- >>>所有工作都很精细,点击触摸屏上的按钮按预期工作,文本更改<<< ---
  4. I import Google's Carboard SDK --->>> NO TOUCH EVENT WORKS! 我导入谷歌的Carboard SDK --- >>>没有触摸事件的工作! Click handler never triggered <<<--- 点击处理程序从不触发<<< ---
  5. I delete Google's Cardboard SDK --->>> TAPS WORK AGAIN <<<--- 我删除了Google的Cardboard SDK --- >>> TAPS WORK AGAIN <<< ---

The script of the click that is triggered is simple: 触发的点击脚本很简单:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TestScript : MonoBehaviour {

    public Text text;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }

    public void ButtonClicked() {
        text.text = "Clicked!";
//      Application.LoadLevel ("DemoScene");
    }
}

So basically importing the Cardboard SDK complete breaks the touch events in Unity 5. If I test it directly in unity, mouse events work alright. 因此,基本上导入Cardboard SDK完全打破了Unity 5中的触摸事件。如果我直接以统一方式测试它,鼠标事件就可以正常工作。 The text is changed even when Cardboard SDK is imported. 即使导入Cardboard SDK,文本也会更改。 Anybody has some idea? 有人有点想法吗? Am I doing something wrong or is this a Unity bug? 我做错了什么或者这是一个Unity错误?

Another way to do it, assuming you want to keep the TapIsTrigger / want to have this 2D scene in VR Mode is to use: 另一种方法,假设你想要保持TapIsTrigger /想要在VR模式下拥有这个2D场景是使用:

if(Cardboard.SDK.CardboardTriggered){
    //what you want to happen when the user touches the screen
}

Again, you need to have TapIsTrigger ticked for this to work. 同样,您需要勾选TapIsTrigger以使其正常工作。

Turn off "Tap Is Trigger" in the Cardboard.SDK settings. 在Cardboard.SDK设置中关闭“Tap Is Trigger”。 Note, the new v0.5 release doesn't have this problem anymore. 请注意,新的v0.5版本不再存在此问题。

In my case, this 2-fingers-multi-touch-detected issue only happen when you switch from cardboard scene to non-cardboard scene. 在我的情况下,只有当您从纸板场景切换到非纸板场景时,才会发生这种双指多触摸检测问题。

My Solution is: When you want to load scene from Cardboard scene to non-Cardboard scene, before you execute LoadLevel(), disable the VR Mode Enabled in CarboardMain game object, under Cardboard.cs script, then you execute LoadLevel(). 我的解决方案是:当您想要将场景从Cardboard场景加载到非Cardboard场景时,在执行LoadLevel()之前,禁用CarboardMain游戏对象中的VR Mode Enabled ,在Cardboard.cs脚本下,然后执行LoadLevel()。

ps: When you turn off VR Mode Enabled before loadLevel(), you will experience Cardboard cameras change from VR mode to non-VR in a second (visible but instantly), before you completely jump to the LoadLevel() new scene. ps:在loadLevel()之前关闭VR Mode Enabled时 ,在完全跳转到LoadLevel()新场景之前,您将体验到Cardboard相机在一秒内(可见但立即)从VR模式切换到非VR模式。 This is ugly. 这很难看。

AND my solution is, 我的解决方案是,

You can overcome this by disable the camera first, then only you turn off the VR Mode Enabled in CardboardMain game object, so the scenes-switching flow will be appeared smooth. 您可以通过先禁用相机来解决此问题,然后只关闭CardboardMain游戏对象中的VR Mode Enabled,这样场景切换流程就会显得平滑。

Try following these steps: 请尝试以下步骤:

  1. Delete MainCamera 删除MainCamera
  2. Drag CarboardMain into Scene 将CarboardMain拖动到场景中
  3. From Prefabs/UI place CardboardReticle under Main Camera 从Prefabs / UI将CardboardReticle置于主摄像头下
  4. Add Physics Raycaster to Main Camera Component 将Physics Raycaster添加到主摄像头组件
  5. Add Event System GameObject 添加事件系统GameObject
  6. Add GazeInputModule Script to Event System 将GazeInputModule脚本添加到事件系统
  7. Add Touch Input Module to Event System 将触摸输入模块添加到事件系统

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

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