Hololens2基础之button交互

主要是控制功能太多且不能同时赋予一个物体,如tap to place, bounds control,object manipulator写到一个例子中,用button控制开关省事,顺便上一节的路标Chevron也开关控制一下试试。

参考官网:Exercise - Panel of buttons and dynamic menus - Learn | Microsoft Docs

1. Create Empty,name the object Buttons,

2.use the Add Component button to add the GridObjectCollection component and configure it as follows:

  • Sort Type: Child Order
  • Layout: Horizontal
  • Cell Width: 0.2
  • Anchor: Middle Left

 上面的喇叭太烦人了,挡视野,点击Gizmos按钮解决了。如下:

 3.In the Project window, navigate to the Assets > MRTK.Tutorials.GettingStarted > Prefabs folder, click-and-drag the PressableRoundButton prefab on to the Buttons object, then right-click on the PressableRoundButton and select Duplicate to create a copy, repeat until four.全部改名字如下图。

Then In the Hierarchy window, 选择buttons选项,click the Update Collection button to update the position of the Buttons,按钮自动如上图排列。

 4..For each button, select the SeeItSayItLabel > TextMeshPro child object, then in the Inspector window, change the respective TextMeshPro - Text component text to match the button names:

5.In the Hierarchy window, select the indicator button object, then in the Inspector window, configure the Interactable.OnClick () event as follows:

  • Assign the Chevron object to the None (Object) field
  • From the No Function dropdown, select directionalindicator > bool enabled to set this function as the action to be executed when the event is triggered

Chevron设置如下,add compoment 添加了Directionalindicator函数,不能勾:

Directionalindicator函数位置如下:

 

 

按钮添加函数过程如下两图:

勾上勾。

 

 

6.tap to place 添加一个函数,控制cube,如下图:

 7. manipulate enable添加两个函数,控制cube,如下,记得勾上:

 

8. manipulate disable添加两个函数,控制cube,如下,不能勾:

经测试,很好用。跟朋友探讨过,以上的方式 开和关要两个按钮才办得到。不怎么好。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值