LoginSignup
9
4

More than 5 years have passed since last update.

HoloLensでダブルタップを検知する

Last updated at Posted at 2017-04-12

はじめに

3月初めよりインターンで株式会社ゆめみ(https://www.yumemi.co.jp/ja) にてHoloLensの研究開発をしている近大生のよっしーです。
国内でこの1月から提供を開始したMicroSoft製MRデバイスのHoloLensについての記事を書いていきます。

すること

ダブルタップを検知する

HoloLensはシングルタップのみ。みたいに思い込んでいたのですが、実はすごく簡単にダブルタップが取れるのを知ったので解説します。

解説

ドキュメントを見てもらうと一目でわかります。tapCountでタップ数が取れるので、このカウントが1ならシングルタップ、2ならダブルタップとなります。
スクリーンショット 2017-04-12 20.50.27.png
https://docs.unity3d.com/ScriptReference/VR.WSA.Input.GestureRecognizer.TappedEventDelegate.html

実装例

関連部分以外全てを省いているのでご注意ください。

DoubleTap.cs
void Awake() {
    NavigationRecognizer = new GestureRecognizer();

    NavigationRecognizer.SetRecognizableGestures(GestureSettings.Tap);

    NavigationRecognizer.TappedEvent += NavigationRecognizer_TappedEvent;
}

private void NavigationRecognizer_TappedEvent(InteractionSourceKind source, int tapCount, Ray ray) {
    if (tapCount == 1) {
        System.Diagnostics.Debug.WriteLine("Single tap");
    } else if (tapCount == 2) {
        System.Diagnostics.Debug.WriteLine("Double tap");
    }
}

追記: 4/13/2017
古いバージョンのHoloToolkitを気づかずに使っていて投稿時知らなかったのですが、以下の方法も使えます。

IInputClickHandler.cs
using HoloToolkit.Unity.InputModule;
using UnityEngine;

class SomeObject: MonoBehaviour, IInputClickHandler {
    private void Start() {
        InputManager.Instance.AddGlobalListener(gameObject);
    }

    private void OnDestroy() {
        InputManager.Instance.RemoveGlobalListener(gameObject);
    }

    // MARK: - IInputClickHandler
    public void OnInputClicked(InputClickedEventData eventData) {
        if (eventData.TapCount == 1) {
            System.Diagnostics.Debug.WriteLine("Single tap");
        } else if (eventData.TapCount == 2) {
            System.Diagnostics.Debug.WriteLine("Double tap");
        }
    }
}
9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4