Useful scripts for Quick 'n good UGUI


Hey folks - development of Maintenance Day "Full" is going along fine, got plenty of secrets to tease over the coming months I reckon.

Whilst I crack on, I wanted to share some useful scripts I'd made as I've been doing the main menu for the game. This has been my first real effort into making a menu that supports gamepad AND mouse, so it's been a learning experience for sure:



This all revolves around these 3 scripts and then a load of snazzy reactor scripts, here's one of my button reactors as an example.

Those scripts should be straightforward enough to parse how they work, here's how I've got my UI setup:

  • Always set hidden/inactive UI gameobjects inactive (this is also a general perforamance tip: even if a bit of UGUI is offscreen/set to zero localScale, it causes you render batches)
  • When a UI container/page is enabled (e.g. the settings tabs you see above), there should be one object with the FocusOnEnable component
  • From there, use the built-in navigation options on UGUI, preferring to keep everything in one column, or using the explicit option to drive anything more complex
  • Now, with the pointer being able to focus/unfocus based on hover, if nothing is selected, there should always be a SetFocusedIfNothingSelected component active to grab focus.
  • Then, based on if an object is selected/not, use classes to react to that. In my case the menu is simple enough that I don't need to care about checking on Update.

You'll probably need to cleanup the Input system being used (either the old one, or Rewired, or whatever), but otherwise those 3 have been instrumental - and surprisingly simple once you get down to it.

Hope this helps anyone else!

Get A Day of Maintenance (Jam Version)

Leave a comment

Log in with itch.io to leave a comment.