HoloLens多用户协同(共享场景和操作)
目标:实现多台HoloLens看同一虚拟物体处于物理空间的同一位置。
实现该目标的方法有很多,本文介绍的是基于 Photon Unity Networkiing插件的方法和基于 Azure Spatial Anchors的方法,实现多用户协同。
基于Photon Unity Networkiing插件
环境和版本
Unity 2019.4.12f1
MRTK v2.4.0
Azure Spatial Anchors SDK Core 2.8.1
Azure Spatial Anchors SDK for Windows 2.8.1
MRTK.HoloLens2.Unity.Tutorials.Assets.GettingStarted.2.4.0.unitypackage
MRTK.HoloLens2.Unity.Tutorials.Assets.AzureSpatialAnchors.2.4.0.unitypackage
MRTK.HoloLens2.Unity.Tutorials.Assets.MultiUserCapabilities.2.4.0.unitypackage
环境搭建
这里笔者默认已经完成了前两步,即Unity 2019.4.12f1,MRTK v2.4.0;没有完成的参考官方文档:Initializing your project and deploying your first application
Azure Spatial Anchors SDK安装
下载MixedRealityFeatureTool,根据官方教程进行配置,选配如下:
MRTK.HoloLens2.Unity.Tutorials.Assets
笔者将这三个版本的包打包上传了:https://download.csdn.net/download/qq_41452267/23521081
设置 Photon Unity Networking
设置 Photon Unity Networking
如果导入Photon后出现错误Assets\MRTK.Tutorials.MultiUserCapabilities\Scripts\OwnershipHandler.cs(10,55): error CS0535: 'OwnershipHandler' does not implement interface member 'IPunOwnershipCallbacks.OnOwnershipTransferFailed(PhotonView, Player)'
,直接把继承出错的类删除即可,这是因为:
OnOwnershipTansferFailed was recently added in v2.29 - 15. March 2021 (see version history).
The Microsoft HoloLens guide was made before that.
Simply implement the interface to fix the error (add empty method with that signature).
具体见链接:https://forum.photonengine.com/discussion/18509/error-cs0535-occurred-while-following-the-steps-of-mrtk-tutorial-in-ms-docs-hololens-2
场景搭建
基于Azure Spatial Anchors
环境搭建
基于Azure Spatial Anchors与基于Photon Unity Networkiing插件的方法所用的Unity、MRTK、ASA版本均相同,不同的是,需要额外安装插件MRTK.HoloLens2.Unity.Tutorials.Assets.AzureSpatialAnchors.LegacyWSA.2.5.3.unitypackage:
场景搭建
将多台HL之间共享的虚拟物体设置为Anchor,该方法需要 Create a Spatial Anchors resource,具体步骤见:
Getting started with Azure Spatial Anchors