# 环境
- Windows 10 教育版 18363.1379
- Unity 2019.4.20f1c1
- VS2019 16.8.6
- WIN SDK 10.0.18362.0
- Hololens2 内部预览版本 10.0.20301.1000
# 创建项目

# 切换平台
在菜单栏 File -> Build Settings 中切换为 UWP 平台

# 创建新场景
使用 Ctrl + N , Ctrl + S 创建新场景并保存为 StreamingScene 。

# 构建 Hololens2 研究模式动态链接库
找一个位置 Clone HoloLens2-Unity-ResearchModeStreamer 仓库。
在 VS2019 中打开
HL2RmStreamUnityPlugin解决方案。选择
Release, ARM64生成解决方案在
HL2RmStreamUnityPlugin/ARM64/Release/HL2RmStreamUnityPlugin下可以找到HL2RmStreamUnityPlugin.dll。如下图:![]()
# Unity 中调用动态链接库
在 Unity 编辑器中,创建
Assets/Plugins/WSAPlayer/ARM64文件夹拷贝上一步生成的
HL2RmStreamUnityPlugin.dll到刚创建的文件夹中创建
Assets/Scripts文件夹,然后在文件夹中创建StartStreamerC# 脚本双击在 VS2019 中打开脚本文件,然后编辑如下:
using System.Runtime.InteropServices;
using UnityEngine;
public class StartStreamer : MonoBehaviour
{#if ENABLE_WINMD_SUPPORT[DllImport("HL2RmStreamUnityPlugin", EntryPoint = "StartStreaming", CallingConvention = CallingConvention.StdCall)]
public static extern void StartStreaming();
#endif// Start is called before the first frame updatevoid Start()
{#if ENABLE_WINMD_SUPPORT
StartStreaming();
#endif}// Update is called once per framevoid Update()
{}}保存,返回 Unity 编辑器
可以把脚本挂在到
Main Camera上:![]()
在菜单栏打开
Edit -> Project Settings。在Player -> Publishing Settings确保以下权限被勾上:- InternetClient
- InternetClientServer
- PrivateNetworkClientServer
- WebCam
- SpatialPerception
![]()
![]()
Ctrl + S保存项目。打开菜单栏File -> Build Settings,添加场景,然后构建。![]()
# 部署到 Hololens2
找到生成的文件夹,在文本编辑器中打开
UnityHL2RmStreamer\Package.appxmanifest文件,并按照如下配置,以确保研究模式被允许:- 添加
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"到Package - 添加 rescap 到 Ignorable Namespaces:
IgnorableNamespaces="... rescap" - 添加
<rescap:Capability Name="perceptionSensorsExperimental" />到Capabilities - 保存然后关闭
Package.appxmanifest
![]()
- 添加
在 VS2019 中打开
UnityHL2RmStreamer.sln解决方案,用Release, ARM64生成解决方案,然后部署到 Hololens2 设备上。
# Python 客户端接收 Hololens2 视频帧
Python 脚本可在此处获得:hololens2_simpleclient.py
注意把脚本中的 Host 改成自己 Hololens2 设备的 IP 地址
# 运行结果

后期我会尝试把研究模式的加速度计、陀螺仪和磁力计流整合进 Unity 项目~
# 致谢
- HoloLens2-Unity-ResearchModeStreamer
- Implementation of the IMU inside the StreamRecorder App #67
- HoloLens2ForCV





