Translate materal base color into UV'd auto generated color palette texture

Hello,
I wonder if someone already did something similar or have suggestions on implementation.

I’d like to color my models using materials (15-20 in total) for flat coloring. Then after exporting the model we might need to read base color values and translate them into one texture. This could be a color palette texture with UV space that were auto generated from each material color value.

As you can see I have really messy texture by coloring with only color palettes.

So coloring with materials in Blender would be more convenient in terms of having nicely arranged material library. However if we can generate texture then out of materials, final textures could be ugly, because it will be used in Unity only serving tech purpose. But that texture have to be updated every time for old and new models.