2014-01-09 62 views
2

我想在我的unity3d项目中使用玻璃刷卡,但它不起作用。 “KeyCode.Escape”适用于轻扫。但是,如何向左轻扫并点按工作?unity3d中访问谷歌玻璃刷卡

我查了“secondaryTouchEnabled”使用OnGUI以下,并返回“假”,

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

难道不应该返回“真”?

如果有人能够在这里分享示例代码,那将会很棒。

+0

@BrentMarshall这将是伟大的,如果你能分享你如何得到它的工作.. – jainam

回答

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结果。

+0

酷!我很高兴回答这个问题!非常感谢!我会试试这个。我还为手势探测器制作了一个小插件,[这里](http://helpdesk.metaio.com/questions/26155/google-glass-touchpad-unity3d)是链接。如果你能看一眼并帮助我,这将是一件好事。 – jainam

0

我试过这样做“如果你想要做更高级的GDK方法,你需要注册一个AndroidJavaClass并且扩展UnityPlayerNativeActivity。一旦你这样做了,你可以在Android中注册一个GestureDetector,并将结果传回给Unity UnityPlayer.UnitySendMessage();这也适用于语音转录和其他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的任何解决方案?