2014-01-09 61 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的任何解決方案?