MRが楽しい

MRやVRについて学習したことを書き残す

MRTK v2のドキュメントを少しずつ読み解く テレポートシステム

本日は MRTKv2 の調査枠です。
MRTKv2 の Guides ドキュメントを少しずつ読み進めていきます。

MRTKv2のGuidesドキュメント

以下のドキュメントを読み進めていきます。
microsoft.github.io

以下のページでは有志による本ドキュメントの日本語翻訳が行われています。
投稿時点でこちらで未翻訳、または著者が興味のある部分について記事にしていきます。
hololabinc.github.io

本記事では以下のページを読み進めます。
microsoft.github.io
f:id:bluebirdofoz:20200404191912j:plain

テレポートシステム

テレポートシステムはMRTKのサブシステムです。
アプリケーションが不透明なディスプレイを使用しているときにユーザーのテレポートを処理します。
HoloLensなどのAR体験では、テレポーテーションシステムはアクティブではありません。
没入型HMDエクスペリエンス(OpenVR、WMR)の場合、テレポートシステムを有効にできます。

有効化と無効化

テレポートシステムは、プロファイルのチェックボックスを切り替えることで有効または無効にできます。
これはシーンでMixedRealityToolkitオブジェクトを選択し、[Teleport]をクリックして、[Enable Teleport System]チェックボックスを切り替えることで実行できます。
f:id:bluebirdofoz:20200404191925j:plain

これは実行時にも行うことができます。

void DisableTeleportSystem()
{
    CoreServices.TeleportSystem.Disable();
}

void EnableTeleportSystem()
{
    CoreServices.TeleportSystem.Enable();
}

f:id:bluebirdofoz:20200404191936j:plain

イベント

テレポートシステムは、IMixedRealityTeleportHandler インターフェイスを介してイベントを公開します。
テレポートアクションが開始、終了、またはキャンセルされたときの信号を提供します。
イベントのメカニズムとそれに関連するペイロードの詳細については、リンクされたAPIドキュメントを参照してください。
microsoft.github.io

使用法

以下のコードは、テレポーテーションイベントをリッスンするMonoBehaviourを作成する方法を示しています。
このコードは、テレポートシステムが有効になっていることを前提としています。

using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Teleport;
using UnityEngine;

public class TeleportHandlerExample : MonoBehaviour, IMixedRealityTeleportHandler
{
    public void OnTeleportCanceled(TeleportEventData eventData)
    {
        Debug.Log("Teleport Cancelled");
    }

    public void OnTeleportCompleted(TeleportEventData eventData)
    {
        Debug.Log("Teleport Completed");
    }

    public void OnTeleportRequest(TeleportEventData eventData)
    {
        Debug.Log("Teleport Request");
    }

    public void OnTeleportStarted(TeleportEventData eventData)
    {
        Debug.Log("Teleport Started");
    }

    void OnEnable()
    {
        // This is the critical call that registers this class for events. Without this
        // class's IMixedRealityTeleportHandler interface will not be called.
        CoreServices.TeleportSystem.RegisterHandler<IMixedRealityTeleportHandler>(this);
    }

    void OnDisable()
    {
        // Unregistering when disabled is important, otherwise this class will continue
        // to receive teleportation events.
        CoreServices.TeleportSystem.UnregisterHandler<IMixedRealityTeleportHandler>(this);
    }
}

f:id:bluebirdofoz:20200404191947j:plain