参考文档
关于本文
目前也有很多对于Hololens2开发的文章,我就不重复了,但是我发现对于UI构建并没有人提过,所以在这里把我开发过程中总结的经验谈一下,希望对大家有帮助。
本文以MRTK2工具包为例,现在已经出到3了,逻辑好像变了一些,我没有去了解。
AR脚本
MixedRealityToolkit
MRTK工具包的配置工具,这里指的是指针工具 里面有很多选项
NearInteractionGrabbale
将“NearInteractionGrabbable”组件添加到任何具有**可碰撞对象(Colider)**的游戏对象 在它上面,以使可碰撞的几乎可以抓住。
然后,任何IMixedRealityNearPointer 都将调度指针事件 到最近的近似可抓取对象。
此外,当 修饰对象是离近指针最近的对象
[UnityEngine.AddComponentMenu("Scripts/MRTK/Services/NearInteractionGrabbable")]
public class NearInteractionGrabbable : UnityEngine.MonoBehaviour
-
Inheritance
UnityEngine.MonoBehaviour ->NearInteractionGrabbable
-
Attributes
UnityEngine.AddComponentMenuAttribute
Constructors
无参数的构造函数
Fields
IsBoundsHandles 用于将此交互抓取指定为边界句柄 |
---|
ShowTetherWhenManipulating 显示在AR环境中从手指指向虚拟物体的线条,对于调整大小旋转很有帮助。 |
NearinteractionTouchable
将NearinteractionTouchable添加到场景中并且配置一个可触摸的表面,当指针指向该表面时,并且可以获取到pointerDown和PointerUp事件。
[UnityEngine.AddComponentMenu("Scripts/MRTK/Services/NearInteractionTouchable")]
public class NearInteractionTouchable : Microsoft.MixedReality.Toolkit.Input.NearInteractionTouchableSurface
-
Inheritance
UnityEngine.MonoBehaviour BaseNearInteractionTouchable NearInteractionTouchableSurface NearInteractionTouchable
-
Attributes
UnityEngine.AddComponentMenuAttribute
Constructors
Fields
bounds | |
---|---|
debounceThreshold 你离这个平面多远会收到接触完成事件 | (Inherited from BaseNearInteractionTouchable) |
eventsToReceive 接受的事件类型 | (Inherited from BaseNearInteractionTouchable) |
localCenter 局部空间物体中心 | |
localForward 局部空间物体前进方向 | |
localUp 局部空间上方向 | |
TouchableColider | 必须有一个BoxColider 作为可接触的计算边界和中心的承载体。默认使用物体上自带的Colider |
NearInteractionTouchableSurfac
一个接近可交互的平面,可以在某个方向被触发
Properties
Bounds | 边界指定了触摸交互可以发生的位置,由LocalCenter LocalPressDirection指定的平面上的本地边界(正常边界) |
---|---|
DebounceThreshold | 在你将收到一个触摸完成事件时距离表面前面的距离 |
EventsToReceive | T要接受的事件类型 |
LocalCenter | 交互本地中心点 |
LocalPressDirection | 用户在这个元素上按下的方向 |
TouchableUnityUIClass
使用 unity RectTransform 作为可触摸面? 这个类可以把unity 的UI转化为 AR可交互面
首先添加画布 之后再预期可触摸的Gameobject上添加该组件,把接受事件设置为触摸。
只要实现 IMixedRealityTouchHandler
组件就可以实现可交互。
ObjectManipulator Class
ObjectManipulator Class (Microsoft.MixedReality.Toolkit.UI) | Microsoft Learn
这个类用于设置对象在被操控的过程中可以如何被操控 比如一只手、两只手、伸缩、旋转,还可以将脚本配置为仅启用某些操作,该脚本可用于Hololens的手势操作。
[UnityEngine.HelpURL("https://learn.microsoft.com/windows/mixed-reality/mrtk-unity/features/ux-building-blocks/object-manipulator")]
[UnityEngine.RequireComponent(typeof(Microsoft.MixedReality.Toolkit.UI.ConstraintManager))]
public class ObjectManipulator : UnityEngine.MonoBehaviour, Microsoft.MixedReality.Toolkit.Input.IMixedRealityFocusChangedHandler, Microsoft.MixedReality.Toolkit.Input.IMixedRealityPointerHandler, Microsoft.MixedReality.Toolkit.Input.IMixedRealitySourcePoseHandler, UnityEngine.EventSystems.IEventSystemHandler
-
Inheritance
UnityEngine.MonoBehaviourObjectManipulator
-
Attributes
UnityEngine.HelpURLAttribute UnityEngine.RequireComponentAttribute
-
Implements
IMixedRealityFocusChangedHandler IMixedRealityPointerHandler UnityEngine.EventSystems.IEventSystemHandler IMixedRealitySourcePoseHandler [IMixedRealitySourceStateHandler](
AR Button
AR Button 元素组件组成,包括前背景板视觉效果,点击改变改变坐标的动态效果;语音识别和提示模块;后背景板和画布。通过画布可以改变Button的颜色和效果;图标和文本框,显示按钮的图标和文本框组件
ARButton 检视器属性,每个属性可以影响在AR环境下的交互效果,例如,点击按钮时产生的视觉效果和声音交互效果
针对Button做出了一些解释,希望大家能够理解,使用