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.
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.
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.
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.
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.
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.
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.
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?