2014-01-09 3 views
2

내 unity3d 프로젝트에서 유리 스 와이프 패드에 액세스하려고하지만 작동하지 않습니다. 'KeyCode.Escape'는 아래로 스 와이프하여 올바르게 작동합니다. 하지만 어떻게하면 왼쪽으로 스 와이프하여 작동시킬 수 있습니까? unity3d의 Google 유리 스 와이프 패드에 액세스

나는

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

는이 "참"돌아 오지 만일, OnGUI에서 다음과가 "거짓"을 반환 사용하여 "secondaryTouchEnabled"을 확인?

여기에 예제 코드를 공유 할 수 있다면 좋을 것입니다.

+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에 다시 전달할 수 있습니다. Voice Transcriptions 및 기타 GDK 결과에서도 작동합니다.

+0

쿨! 이 질문에 대한 답변을 기쁘게 생각합니다! 고마워요! 나는 이것을 밖으로 시험 할 것이다. 제스처 탐지기 용 작은 플러그인도 만들었습니다. [여기] (http://helpdesk.metaio.com/questions/26155/google-glass-touchpad-unity3d) 링크입니다. 외모를 가지고 나를 도울 수 있다면 좋을 것입니다. – jainam

0

"고급 GDK 메서드를 사용하려면 AndroidJavaClass를 등록하고 UnityPlayerNativeActivity를 확장해야합니다. 일단 그렇게하면 Android에서 GestureDetector를 등록하고 Unity에 결과를 다시 전달할 수 있습니다. UnityPlayer.UnitySendMessage(); 이것은 Voice Transcriptions 및 다른 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에 대한 해결책이 있습니까?