Hello! Is it possible to have a color used as asset? I mean save a color and use it in the inspector to feed button image or others components with it. Then if I change this color all components are updated at once.
Or, is it possible to have a CSS like system, to edit ui themes with ease?
I know there is the swatches system in palettes, but still I have to change all ui element by hand if I decide to change one color.
Thank you neginfinity, I just tested presets as it sounds promissing but as documentation say: When you change the properties in a Preset, your changes do not affect items you have already applied the Preset to. For example, if you apply a Preset for a Rigidbody component to a GameObject, and then edit the Preset, the settings in the Rigidbody component do not change.
So it doesn’t really help because with presets I still have to find and update all component if I modify a preset.
However I found someone who wrote a script to change presets at runtime : [Free] Using Presets at runtime - Unity Forum , maybe something can be made with this. But it will involve adding a script component to every gameobjects we need to apply a preset to, or at the opposite build a script to store a list of all gameobjects using presets.
If I were looking for a component like that for GUI, I’d consider two approaches:
Add, say “ButtonThemeSupport” component which will track external “style” asset (also made by me) and apply any changes to it to a button that is placed on the same object.
Roll out my own UI components.
Generally, if you want an ability to change the “style” at runtime (as in, change one or two colors and immediately see the difference), this is going to be more involved. As you’ll need to broadcast that changes happened (which will require approach #1), OR you’ll need to alter the way component paints itself, so during every repaint he pulls the data from the scriptable asset. This is likely to require approach #2.
For UGUI use prefabs. If you change the parent prefab, you can change all children at once. Otherwise you can check out the new UI system which has CSS-like properties. It’s called UI Toolkit, depending on what Unity version you use and how much you are willing to fiddle with preview packages, you may find it useful (doesn’t have everything UGUI already has just yet, that’s why it is preview).