1.资源导入
导入SteamVR
MRTK:Microsoft.MixedReality.Toolkit.Unity.Foundation.2.7.2.unitypackage
LeapMotion:Core.unitypackage
MRTK: Microsoft.MixedReality.Toolkit.Unity.Examples.2.7.2.unitypackage
解决报错:删除报错的代码
2.集成MRTK和LeapMotion
MixedReality->Toolkit->Utilityies->LeapMotion->IntegrateLeapMotionUnityModules
3.添加LeapMotion数据提供程序
3.1打开HandInteractionExamples场景->Hierarchy的MixedRealityToolkit身上的MixedRealityToolkit.cs右侧的Clone,克隆该脚本,然后Hierarchy的
MixedRealityToolkit身上的MixedRealityToolkit.cs上就是新克隆的,可更改
3.2Input-> Clone 自动改成新的Profile
InputDataProviders->AddDataProvider->Type->LeapMotionInput->LeapMotionDeviceManager
Clone->选择不同的模式:放在桌子上/头盔
4.安装
Leap_Motion_Installer_v4-2020-release-updates_public_win_x64_4.1.0+52211_ah1889.exe
5.应用
5.1近距离交互
ObjectManipulator.cs:
ManipulationType:单手、双手
AllowFarManipulation是否允许远距离
OneHandedManipulation 旋转模式
Constraints约束管理器 EnableConstraints使用约束管理器
ConstraintManager.cs约束管理器 可以添加约束条件
AutoConstraintSelection自动添加,选择之后约束脚本自动添加到物体上
ManualConstraintSelection手动
FixedRotationToWorldConstraint.cs HandType选择哪只手约束哪只手
Physics:物理效果,需要添加Rigidbody
ManipulationEvents 事件
NearInteractionGrabbable.cs
CursorContextObjectManipulator.cs 显示光标
5.2关闭跟随摄像机的显示面板
MixedRealityToolkit->Diagnostics->EnableDiagnosticsSystem去掉勾选
6.新建MRTK场景
6.1 MixedReality->Toolkit->Add to Scene and Configure
6.2 配置MixedRealityToolkit.cs 选择新建的
NewMixedRealityToolkitConfigurationProfile
ExperienceSettings -> TargetExperienceScale 可改Room/Standing
Camera->Clone->DisplaySettingsProviders->QualitySetting ->VeryHigh
6.3让物体可抓取、移动、旋转、缩放
添加ObjectManipulator.cs,自动添加约束管理器ConstraintManager.cs
Add Near Interaction Grabbable 允许近距离抓取
7.BoundsControl组件 根据boxcollider显示包围框 选中包围框上的点进行移动、缩放、旋转
TargetObject
Activation 什么情况下显示
BoundsOverride 把碰撞盒放进去
BoxPadding 修改显示框的大小
FlattenAxis 在指定轴对包围框挤压
UniformScaleOnFlattenedAxis 是否统一缩放
Visuals:
ScaleHandlesConfiguration:缩放操纵柄
LinksConfiguration 包围框点与点之间的连线
ShowWireframe是否显示这个连线
ProximityConfiguration手或者Point接触到物体时包围框的点的效果
ProximityEffectActive是否启用该效果
BoxConfiguration
8.缩放约束
ConstraintManager.cs -> Add Constraint to GameObject ->MinMaxScaleContraint
Relative To Initial State 勾选的话,每次缩放,以上次缩放的大小为基础,继续缩放,不勾选,以原始大小为基础进行缩放
9.PressableButton组件
PressableButtonHoloLens2.cs检测手,不能检测射线
PhysicalPressEventRouter.cs 检测Interactable.cs的事件
Interactable.cs检测射线、语音识别
General->SpeechCommand:在MixedRealityToolkit->Input->Speech->Clone->
Add a New Speech Command
Profiles
Events
OnClick仅支持远距离交互需要使用PhysicalPressEventRouter.cs,其他事件不影响
Receivers
ButtonConfigHelper.cs
OnClick与Interactable.cs的OnClick关联,删除就会一起删除
10.创建Theme与States
10.1创建Theme
Project面板Create->MixedReality=>Toolkit->Theme,将创建的State拖到Theme的States里面
在State里添加状态
将Theme拖动给物体Interactable General States
在物体里面编辑 ThemeRuntime ->InteractableScaleTheme Easing√
10.2创建State
Project面板Create->MixedReality=>Toolkit->State
11.Cube按钮
11.1 PressableButton近距离点击按钮
给物体Cube添加PressableButton.cs, Add NearInteractionTouchable component
MovingButtonVisuals 移动的按钮Cube托上去
双击Cube,
DistanceSpaceMode World 最远距离就是MaxPushDistance的位置
浅蓝 StartPushDistance控制,开始点击的动画距离
深蓝 MaxPushDistance控制,最大的移动距离
黄色PressDistance,执行Press事件的距离, DistanceSpaceMode Local模式
离StartPushDistance近才能触发,World模式远也能触发
11.2 Interactable.cs远距离 触发按钮
SpeechCommand添加一个语音关键词
Profiles
Traget 拖入Cube ,CreateandAssignNewTheme,ThemeRuntime选择
ScaleOffsetColorTheme,
远距离事件
Receivers ->AddEvent ->EventReceiverType ->InteractableOnPressReceiver,
InteractionFilter ->FarOnly
11.3 OnClick 远近距离都使用
删除之前添加的Press/Release上的声音事件
在Interactable的OnClick添加点击事件,此时,只是远距离可以触发。
添加PhysicalPressEventRouter.cs,将Cube拖入RoutingTarget,在
PressableButton.cs的Events添加事件,拖入Cube,
PhycalPressEventRouter.OnHandPressTouched/ PhycalPressEventRouter.OnHandPressUntouched/ PhycalPressEventRouter.OnHandPressTriggered/ PhycalPressEventRouter.OnHandPressCompleted
12.让TextMeshPro支持中文:
Window -> TextMeshPro -> FontAssetCreator
SourceFontFile拖入字体文件,字体文件不能包含中文
AtlasResolution 8192*8192
CharacterSet改为CharactersfromFile,拖入中文文本
GenerateFontAtlas
Save
将新生成的字体给TextMeshPro
13.和UGUI交互
将Canvas转为MRTK支持的
ConverttoMRTKCanvas
AddNearInteractionTouchableUnityUI
NearInteractionTouchableUnityUI -> EventsToReceive ->Pointer
14.跟随摄像机
跟随物体上添加FollowMeToggle.cs
15.TouchInteraction.cs
Cube:
HandInteractionTouchRotate.cs:将cube拖入TargetObjectTransform
NearInteractionTouchable.cs
16.PinchSlider:3D滑动
SliderTrack:SliderAxis轴向;SliderStartDistance起始点;SliderEndDistance终点
17.听写
DictationExample场景
在MixedRealityToolkit->Input中有WindowsDictationInput,添加
LeapMotionDeviceManger
运行,点击StartRecording,开始听写
DictationPanel->DictationHandler.cs->RecordingTime一次听写时间
连续听写:
RecordingTime 改为0,运行听写报错,通过报错位置,修改
WindowsDictationInputProvider.cs
Microphone.Start(deviceName, false, recordingTime, samplingRate)中的false改为true
RecordingTime改为非0.就会连续听写,但仍然手InitialSilenceTimeout和
AutiSilenceTimeout限制
事件触发:
OnDictationHypothesis 说话时一直触发
OnDictationResult说话停顿时触发
OnDictationComplete说话停止Timeout之后触发,Microphone.Start false才会执行?
OnDictationError
18.关闭/启用手射线、抓取、戳 功能
DisablePointersExample场景
将DefaultMixedRealityToolkitConfigurationProfile改成新建的
NewMixedRealityToolkitConfigurationProfile
Input添加LeapMotionDeviceManager
Interactable.cs Receivers OnSelect OnDeselect
19.物体跟随手指关节点
PointerResultExample场景
将DefaultMixedRealityToolkitConfigurationProfile改成新建的
NewMixedRealityToolkitConfigurationProfile
PointerHandler.cs OnPointerClicked
点击在面板上,生成方块
HandJointChaserExample场景
将DefaultMixedRealityToolkitConfigurationProfile改成新建的
NewMixedRealityToolkitConfigurationProfile
RightHandChasers-> IndexChasers/ MiddleChasers/ RingChasers/ PinkyChasers/
ThumbChasers/ OtherChasers下的子物体们的->SolverHandler.cs->
TrackedTargetType->HandJoint右手的
TrackedHandness ->Right
Left Hand Chasers左手的
物体跟随关节
20.TextToSpeechExamples场景
文本转语音
需要发布UniversalWindowsPlatform出来才行
21.滚动对象容器
ScrollingObjectCollection场景
换成NewMixedRealityToolkitConfigurationProfile
新建空对象GameObject,添加ScrollingObjectCollection.cs,
ScrollDirection设置上下还是左右滚动
Pagination设置CellsPerTier几行/TiersPerPage几列/PageCell模型大小
在GameObject自动生成Container和ClippingBounds, 在ClippingBounds范围内的渲染,其大小由PageCell控制
在Container创建滚动模型Cube,调整Cube位置,让ClippingBounds能包围Cube,共创建3个Cube,调整位置,Cube超出ClippingBounds自动隐藏
移除Cube的boxcollider
在GameObjec下创建空物体FrontPlate,添加Interactalbe.cs,
NearInteractionTouchable.cs,Boxcollider
NearInteractionTouchable.cs Fixed
Boxcollider拖动到NearInteractionTouchable.cs的TouchableCollider里面
调整FrontPlate Pos0.05 -0.05 0 大小0.1
Cube 用MixedRealityToolkit/Standard的shader的材质,移除Cube上的
MaterialInstance.cs,可以将超出部分的模型切割
GridObjectCollection.cs 改数据,需要点击下面的UpdateCollection才能生效
22.MRTK网址:
MRTK2-Unity 开发人员文档 - MRTK 2 | Microsoft Docs
下载包 包->MRTK包->资产包->GitHub
注意MRTK与LeapMotion的版本对应:支持的设备概述
23.运行出现HTC的提示框,是因为Input的兼容问题,将ProjectSettings->Player->ActiveInputHandling改为Toth;SteamVR的动作没有写入json
Edit->ProjectSettings->Player->ActiveInputHandling->Both,
Window->Steam VR Input ->Save and generate