访问unity3d中的谷歌玻璃刷卡

时间:2014-01-09 05:00:45

标签: unity3d google-glass google-gdk

我正在尝试访问unity3d项目中的玻璃滑动垫,但它不起作用。 “KeyCode.Escape”适用于向下滑动。但是如何向左滑动并点击工作?

我在OnGUI中使用以下内容检查了“secondaryTouchEnabled”并返回“False”,

GUI.Label (new Rect (300, 100, 200, 60), ""+AndroidInput.secondaryTouchEnabled.ToString());

它不应该返回“真实”吗?

如果有人可以在这里分享示例代码,那就太棒了。

2 个答案:

答案 0 :(得分:2)

您问题中的GUI.Label应该与我在下面设置的两个调试字段相同。下面的代码将数据插入到文本字段中。

void Update () {
#if UNITY_ANDROID
    if (Input.GetKey(KeyCode.Escape))
        Application.Quit(); // HANDLE ESCAPE

    // FINGERS
    debug1.text = "TOUCHES: " + AndroidInput.touchCountSecondary.ToString(); // FINGER TOUCHES

    // TOUCH COORDS
    string resp = "COORDS: \n";
    for (int i = AndroidInput.touchCountSecondary - 1; i > -1; i--) {
    resp += "(id: " + i;
        resp += " x: " + AndroidInput.GetSecondaryTouch(i).position.x;
        resp += " y: " + AndroidInput.GetSecondaryTouch(i).position.y;
        resp += ") \n";
    }
    debug2.text = resp;
#endif
}

如果你想做更高级的GDK方法,你需要注册一个AndroidJavaClass并扩展UnityPlayerNativeActivity。完成后,您可以在Android中注册GestureDetector,并使用UnityPlayer.UnitySendMessage()将结果传回Unity。这也适用于语音转录和其他GDK结果。

答案 1 :(得分:0)

我已经尝试过这样做"如果你想做更高级的GDK方法,你需要注册一个AndroidJavaClass并扩展UnityPlayerNativeActivity。完成后,您可以在Android中注册GestureDetector,并使用UnityPlayer.UnitySendMessage()将结果传回Unity。这也适用于语音转录和其他GDK结果。",使用jainam here提出的代码

但我的UnityPlayerNativeActivity无法将信息发送给Unity,我不知道为什么。

我的快速解决方案是下一个(待优化):

touches = int.Parse(AndroidInput.touchCountSecondary.ToString());
    if (touches > 0) {
        Debug.Log("TOUCHE");
        xCurrent = AndroidInput.GetSecondaryTouch(0).position.x;
        yCurrent = AndroidInput.GetSecondaryTouch(0).position.y;

        if(xInitial == -1 && yInitial == -1){
            xInitial = xCurrent;
            yInitial = yCurrent;
        }
    }else if(xInitial > -1 && yInitial > -1){
        if(yCurrent < yInitial && yCurrent == 0){
            Debug.Log("Swap down");
            Application.Quit();
        }else if(xCurrent - xInitial < -100){
            Debug.Log("Swap Right");
        }else if(xCurrent - xInitial > 100){
            Debug.Log("Swap Left");
        }else{
            Debug.Log("Tap");
        }
        xInitial = yInitial = xCurrent = yCurrent = -1;
    }

您对此解决方案有何看法?

确实存在UnityPlayerNativeActivity的任何解决方案吗?

相关问题