Author Topic: Teleporting focus to buttons, using dpad, by setting UICamera.hoveredObject  (Read 4764 times)

PompeyBlue

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Hello,

I am well underway porting to dpad and there are occasions where I want to reveal a button and to teleport focus on it - this includes having it highlight. Current I am activating it then using

UICamera.hoveredObject = newlyActivatedObject;

This seems to work in the majority of cases however I'm finding that often the hover state (if I have a hover tween texture) isn't set even though focus is on that button. Is there a more "official" way I should be teleporting focus around the screen when navigating by dpad?

Holy Manfred

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 8
  • Posts: 71
    • View Profile
Re: Teleporting focus to buttons, using dpad, by setting UICamera.hoveredObject
« Reply #1 on: September 16, 2016, 09:18:40 AM »
If your UI setup isn't too complicated you could use the UIKeyNavigation component for simple dpad navigation.
For automatically selecting UI elements I always use:

  1. SendMessage("OnHover", true)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Teleporting focus to buttons, using dpad, by setting UICamera.hoveredObject
« Reply #2 on: September 17, 2016, 12:20:54 AM »
Are you manually trying to select a controller's selected object? If so, that should be done via UICamera.controllerNavigationObject. Hovered object is for your mouse.

And yes, as Holy Manfred said, UIKeyNavigation script is what facilitates automatic controller-based UI navigation for you. All you need to do is set the axes used on UICamera. You don't need to write any code.

PompeyBlue

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Teleporting focus to buttons, using dpad, by setting UICamera.hoveredObject
« Reply #3 on: September 21, 2016, 05:18:53 AM »
Thanks. The UIKeyNavigation component is working well however it doesn't handle the case that I need. Which is:

1. User has two buttons, side by side, user uses dpad to navigate to button 2 (on the right) which they click
2. Continue button now appears below the two buttons, I want to automatically navigate to the new continue button so it's a button click to leave the screen rather than a dpad down then button click
3. I need to teleport focus / hover to the continue button have it hover, do it's animations etc.

I'll try the UICamera.controllerNavigationObject to see if that works.