首页 文章

访问unity3d中的谷歌玻璃刷卡

提问于
浏览
2

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

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

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

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

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

2 回答

  • 0

    您问题中的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结果 .

  • 2

    我尝试使用jainam here提出的代码"If you want to do more advanced GDK methods you will need to register an AndroidJavaClass and extend UnityPlayerNativeActivity. Once you do that you can register a GestureDetector in Android and pass the results back to Unity using UnityPlayer.UnitySendMessage(); This also works with Voice Transcriptions and other GDK results."

    但是我的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的任何解决方案?

相关问题