Unity UI on the HoloLens

Following the steps under "Required configuration" will allow Unity UI to continue to work in the editor, but it'll also work in the HoloLens using tap and navigation gestures.

Required configuration:

  • If you don't have any UI objects yet, create one (GameObject -> UI -> Button/Toggle/Slider/etc.)
  • Select the EventSystem object (this GameObject is automatically created for you when you create an UI objects, but unlike other UI objects, does not have Canvas as a parent/ancestor)
  • Add the "HoloLens Input Module" component to EventSystem (leave StandaloneInputModule attached for the UI to still work in the editor with mouse and keyboard)
  • Select the Canvas object (this containing GameObject is automatically created for you, and is a parent/ancestor to your UI objects)
  • Change "Render Mode" to "World Space"
  • Drag the Main Camera object onto the "Event Camera" field
  • Remember to put your camera's position at the origin

Recommended steps to get started with a more useable UI:

  • In the Canvas Scaler component of the Canvas object, change "Dynamic Pixels Per Unit" to 10 - this will remove a lot of text aliasing without shrinking the text size too much
  • At the bottom of the Rect Transform of the Canvas object, change the Scale in both X and Y to somewhere around 1/16 (0.0625) to 1/32 (0.03125) or so to make the size of UI objects more manageable (use the same value for X and Y to avoid non-uniform scaling, of course).
  • Set the Canvas position to 0 for X and Y, and a distance of 3-5 or so along Z (this will make it so that your UI is immediately visible after the splash screen goes away)
  • For sense of scale, create a button, masked background, or some other visible UI object and set its width and height to 100 by 100. Make sure you can see this in the Game window, and deploy to the HoloLens as usual. This should give you a better idea of how you'll want to size and position your UI.
  • Create a cursor to more easily tell where your gaze is pointed at (you can use the HoloToolkit to do this pretty painlessly). Especially if you choose not to create a cursor, it's highly recommended that you make the colors, animations, etc., for different states of your UI objects (Normal/Highlighted/Pressed/Disabled) very noticeably different - during initial development, at least - to make it more obvious what you're looking at and whether the gesture was done and interpreted correctly.

Run-time use:

  • Tap gestures of a gazed-at object will act as a quick single-click at that position. The "Time To Press On Tap" field of the HoloLens Input Module component controls the number of seconds that such taps will leave the UI object in the tapped state for better user feedback.
  • Use navigation gestures where click and drag would normally be needed, such as when moving a slider or scroll bar. The "Normalized Navigation To Screen Offset Scalar" field of HoloLensInputModule defines the number of pixels of emulated mouse movement when a value of positive or negative 1 is reported by the device for a navigation gesture.

Known issues:

    • During a navigation gesture interacting with a Slider object, said object's appearance will change between Highlighted and Pressed. The navigation gesture will still work fine during this apparent state-flickering, however, so aside from altered appearance, it should still behave correctly.

转载于:https://www.cnblogs.com/unity3ds/p/5969809.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值