I'm trying to implement both the tap and double tap gestures in the hololens. Each individual gesture works, however, when I double tap, it single taps also twice. I saw a few using timers to solve it, but I thought there might be a more elegant solution.
Since I'm using the GestureRecogniser, I have a callback method:
private void GestureRecognizer_TappedEvent(InteractionSourceKind source, int tapCount, Ray headRay)
{
switch (tapCount)
{
case 1:
OnTap();
break;
case 2:
OnDoubleTap();
break;
}
}
Can I do anything here, or will I have to resort to having a separate script which checks on it's Update
function?
Thanks!
I used a timer and after the 'double click speed' timer has expired I SingleTap or a second click is detected then I DoubleTap.
The down side is that the double tap takes longer than a double mouse click and therefore adds some delay into the single tap which I am not sure is a good experience.
This is slightly old, so I'm curious what you ended up doing.
There is a way to avoid using a timer as the double tap gesture is recognizable.
void Start()
{
// get a new gesture recognizer
recognizer = new GestureRecognizer();
// set up to receive both tap and double tap events
recognizer.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.DoubleTap);
// see https://docs.unity3d.com/550/Documentation/ScriptReference/VR.WSA.Input.GestureRecognizer.TappedEventDelegate.html
recognizer.TappedEvent += (source, tapCount, ray) =>
{
if (tapCount == 1)
{
Debug.Log("Tap");
}
else if (tapCount == 2)
{
Debug.Log("Double Tap");
}
};
recognizer.StartCapturingGestures();
}
Since there is still no complete (working) answer to this, and I couldn't find one elsewhere, here's how I fixed it. Similar to using a timer, but slightly nicer in my opinion.
const float DELAY = .5f;
void Start()
{
recognizer = new GestureRecognizer();
recognizer.StartCapturingGestures();
recognizer.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.DoubleTap);
recognizer.TappedEvent += (source, tapCount, ray) =>
{
if (tapCount == 1)
Invoke("SingleTap", DELAY);
else if (tapCount == 2)
{
CancelInvoke("SingleTap");
DoubleTap();
}
};
}
void SingleTap()
{
Debug.Log("Single Tap")
}
void DoubleTap()
{
Debug.Log("Double Tap")
}
Note: I couldn't find the delay with which a double tap is recognised, so I assumed it is the Windows default of half a second.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.