[UI] Help building a controller info bar

Started by
2 comments, last by malo88 6 years, 12 months ago

Hello everyone.

I'm developing a PC game with Unity and I have a code design question about the GUI. I'm trying to build an UI system for all my menus in games which gives you the available buttons you can press on this scree. It's like a bar at the bottom of the screen (see pictures attached), which changes every time you change screen and there are different buttons to press. The thing is, I have to switch between PC layout and controller layout. So for example if you plugin a controller it must show you the same actions, but mapped to the controller buttons (see pic ),

[attachment=35509:console.png]

and if you press the keyboard or use the mouse it automatically switch to PC actions (see pic).

[attachment=35508:pc.png]

This kind of bar must be maintained valid every time the gui is on screen and so it should "listen" to all the available inputs and mapped actions.

First of all: do this kind of bar has a common name (so I can look for example myself)? Do you know if there is well known pattern to implement this?

Thanks guys!

Advertisement

Have you looked into Rewired? https://www.assetstore.unity3d.com/en/#!/content/21676

It's really useful for input in general, but it sounds like it could simplify your problem too. If you want to swap back and forth from key to controller controls on connect/disconnect, Rewired makes it easy to track.

http://guavaman.com/projects/rewired/docs/HowTos.html#connect-disconnect-events

Bear in mind that a UI that changes to reflect the game state is a pretty standard concept - whether that's a set of buttons, or a health bar, or whatever - so you wouldn't expect to find a special name for such a thing. The pattern for handling them is quite simple; when the game state alters in a way that might be relevant for the UI element, you tell the UI to update, and then the elements can query the game state to see whether they need to look different (in this case, switching to showing controller buttons).

Thank you guys, sorry for the late answer!

Actually I'm already using Rewired, so I managed to do as cmac suggested.

@Kylotan: you are talking about the MVC pattern I imagine, so yes, I did something like that. The controlbar has a logic and a listener: the listener receives the inputs active at the moment and tells the logic about them. The logic then tells the view (the real Gameobject) to show the buttons icons and labels corresponding to the active actions!

Many thanks!

This topic is closed to new replies.

Advertisement