Monday, 16 December 2013

UI & game state management

I delved a little into the Unity GUI stuff this week.  I'm not entirely sure what I was expecting compared to XNA but I was surprised it wasn't a bit more...developed I guess.  I don't want to speak  too ill of Unity as the gui code is neat,  but when I think about how sophisticated 3D rendering in games is, font rendering seems primitive in comparison.  It's rendering textured quads, using a bunch of helper methods for positioning and cutting things up.  But if you wanted to scale up or down for different resolutions it can look like mud.    Compare this for example to the text on this web page which is very smooth and highly scale-able.  Games have so many different types/needs/platforms that it's probably not a fair comparison.  I'm just wondering how other engines handle it.

You can still get good results though, here I'm just picking a nice font with some useful coloring.   When drawing frames, you can see below I also get some glitching from the way it stretches the texture, I managed to fix it by altering the texture settings.  The borders don't seem to have tiling at the sides which is a bit of a bummer, I might end up needing to write a bunch of rectangle drawing.  All the other widgets like horizontal sliders, and in particular being able to add colors within the strings are a super helpful.

Unity stretching the ui texture instead of tiling them :(
I spent some time on the game state too.  This is the kind of code that I often get paralyzed by, it's like putting a puzzle together when you don't have a final image to work from.  I'm basing it off the xna gamestate stuff that I really like.  A particular point of puzzlement was the OnGUI() method in Unity.  This is where the UI stuff is both used and drawn, like clicking a GUI.button, but, you as it turns out don't want process other input here like key presses as it runs differently.  e.g. a single key press will fire multiple times instead of once.  And the reverse of that, you don't want mouse interaction on the GUI menus to also then interact with the 3d scene beneath it.    Then there's other stuff like where do you want to hold your list of game objects, how do you handle updating them, keeping track of what's picked, stuff like that I struggle with. 

I might try and get another build done for the end of the week but after that I'll be away for the holidays, so if I don't post again... Merry Christmas!