Recommendation for a UI styling template system

Hi all,

I am looking for a simple templating system for Unity uGUI, so that I can maintain a global style that automatically applied to various buttons/texts/list etc.

I would love to hear some suggestions if anyone had previous experience developing or working with such a system, is it worth the trouble to roll my own template system, or is there any existing asset store solution you find adequate?

I am not aiming for any fancy UI, just a consistent UI (think iOS), so that I can say: ok this is a template for “Medium-sized Button”, any button with such template attached will use the same font/color/size/transition etc.

My hope for such a system is to cut my manual labor by 50%; I don’t expect it to handle fancy layout or provide a large UI framework.

Thx in advance!

1 Like

Just make a set of control widgets using just a couple of grfx. Make a manager that stores all the image components and grfx in groups and allows drag and drop grfx changing, text labels and color manipulation per group. That is your framework. I could set such up in less than an hour.

1 Like

Thx for the response, so you are saying:

  • Create a few widgets (prefabs with control script and some ui elements).
  • When use, just copy and paste prefab instance, and change text label etc.

My questions:

  • How does it make sure styles are synced across prefab instances?
  • Widgets are not supposed to know each other, is the manager script controlling styling for all widgets?

I might be misunderstanding your reply as I don’t know what “grfx” stands for.

Better place to post would have been Unity Engine - Unity Discussions

AFAIK, there is nothing close to a standardized method for handling styling.

I’ve messed around with a couple low effort methods but have more or less just ended up giving up on it. It really depends on the type of layout you want and the degree of change you might expect to do.

Prefabs can work to some degree. Just make a ‘medium button’ prefab and use this. Changes to the prefab source will propagate to instances. This will work if you keep your prefabs atomic and don’t start doing stuff that requires nested prefabs.

2 Likes

You can also do something like:

Make a prefab/scriptableobject that has a font, colors, etc. Have a script that references the prefab/scriptable object and uses the values there. So like “button” script has a reference to “colortemplate” scriptable object.

At least you have a centralized method for changing everything. I do this for button colors (highlight, press, etc), and a few other things and it works pretty well.

Edit:
here’s a screenshot example:

Although I tend to only use for colors, I think you could do fonts, colors, sizes, etc and it’d work well enough.

Has the advantage of being very simple and requires pretty minimal code. Again, it’s best if you don’t generally instance these (scriptable object might be better), although I kind of like having the option.

1 Like

Thx, ScriptableObject seems like a reasonable approach, it’s just a bunch of settings after all, I can write a script that apply them automatically and recursively.

My project isn’t large enough to make this worthwhile yet, so I opted for some layout prefabs, then just copy and break instance from prefab.

1 Like

So, I did make one a while back. It started out for NGUI, but worked for UGUI as well, and too a degree for any gameobject with attributes you want to reuse. (particle systems, etc).


It worked similar to illustrator/indesign styles. you could create a new style and choose which elements were part of that style, so it could be the whole thing (size, alignment, font, color, ect) or fewer, like just color. A reference to that object (or id if a prefab) was stored in a scriptable object container. So you could apply the style, update the style, and apply it globally or edit the style directly. In general, it worked pretty well (worked really well for particle systems). but was a little slow for a large project when you changed the style and applied it, as it would have to crawl through everything.

Ultimately, it didn’t get a ton of use, because by time I got around to building and finishing it, the visual style was solid and required very little changes. The reality is (at least for that single project), it took way more time to build than it ever saved. If it had been built earlier, or used across more projects, it would have been a more efficient use of time.

5 Likes

I gotta admit, I love seeing screenshots of your work.

That a lot of eye candy for an internal tool

Unity Technologies published a few learning videos recently, that seem to show pretty much what you’re looking for.

https://www.youtube.com/watch?v=HkUSmI7F304

2 Likes

The technique they shown in that series seem pretty tedious. You would have to manually code every single aspect of everything you want to skin. Isn’t it better to just use reflection to expose everything?

That’s funny, that’s basically how I did it…aside from the weird class hierarchy based design

I personally do like having the settings be monobehaviour prefabs instead of SO’s. The advantage to monobehaviour is you can attach a ‘local style’ to a node in hierarchy and have child elements use it without adding additional clutter to files.

Like adding a “Button Style” to the UI root GameObject and all children pick up the style from the parent by default? And if you want to override a (child) button to a specific style, you add that style to the button GameObject?

yeah that’s basically how i did it. So you can stash the style as a prefab or attach to root element.

It depends on how complex a ui you need to make. The real value is just having some centralized location to store values so you can change them.

The reason I use these primarially w/ buttons is that buttons have like 6 colors that are all needed, so manually editing that is a nightmare.

Late in development, I do regret not using something similar for fonts.

1 Like