When I click on a color in the inspector, the "Color" window opens, showing the corresponding color. How can I assign/copy this color value to a different color field in the inspector, another material, etc.? Or if that isn't possible, how to copy color settings directly from component A to component B?
I didn't find any context menus for this, no drag&drop, or similar. The pipette next to the color shown in the inspector doesn't seem to do anything, either (what's it for?)
asked Feb 16 '10 at 02:32 PM
The only way I've found to do this is to manually copy the R,G,B (or H,S,B) values across - either by remembering the 3 values while switching to the destination colour, or by noting down the values in notepad or something. Not ideal at all, but it's one of those things that I've gotten so used to doing (in many other apps too, not just unity) that I didn't even notice it was a missing feature.
In fact, now you mention it, I don't ever recall seeing an app where you can copy and paste colour values!
answered Feb 16 '10 at 04:28 PM
Unfortunately you can't change Color fields while editing AFAIK. If you do try that, then changing color does not have any effect on the new selection. You have to create your custom code for copying colors from one field to another. One way to do this would be an editor script. If you do some magic with reflection to find all the color fields on a selected target A, and all the color fields on a selected target B, then you could write code that copies color (or any variable) from A.a to B.b if you get my drift.
System.Reflection contains classes you'd want to use for this purpose. Basically you should find all field member of a selected object, and for all member field who has a field type of Color, you should display in a list. FieldInfo is the class you want to use for accessing and manipulating data, and it should be available from the objects Type (someObject.GetType()).
When you want to get some value from a field with reflection, you basically call someFieldInfo.GetValue(someObject); where someObject is the object you want to get the field data from. Likewise, someFieldInfo.SetValue(someObject, value) sets value to the field on someObject. GetValue returns a variable type of object, so you have to cast it to the expected type before you work with it.
Actually, this sounds like a good add-on, and I might get around making a general-purpose variable copier. I would be happy to share it with all of you, but if you want it now then its best you roll your own code because I have a lot on my hands these days.
Reflection might sound scary to some people, but it is just about enumerating the members of some type, then through that member you can call/read/write stuff. Type, FieldInfo and BindingFlags should be the only "strange" classes you should have to work with.
There might exist other more simple solutions to this problem, and if you find a simple solution, always go for the simplest solution.
I hope you find a solution to your problem.
answered Feb 16 '10 at 04:30 PM
Ah, I recently discovered a bit of a hacky way to do this quickly. It relies upon the fact that you can have multiple inspector tabs open at once, and lock them onto a single target.
1) select the GameObject you want to copy a color from. Lock its inspector.
2) click on the options widget (upper-right hand corner) on a separate window area (such as project folder window) and select Add Tab > Inspector.
3) select the GameObject you want to copy the color to. Observe that you have one inspector for target and one inspector for source now.
4) Click the pipette on the target color swatch and mouse-over then click on the color swatch area from the source color. Your color is "copied" directly.
5) Repeat with new target GameObjects as necessary.
It's not as quick as CTRL-C, CTRL-V, but it gets the job done quite quickly for me. Hope that helps!
answered Apr 25 '12 at 11:06 PM
when you change the color it will change that property after you close the window. then you can get that color property and assign it to others. use the selection class and get the property that you want. for example
then you can copy c to any other color property.
answered Feb 16 '10 at 04:10 PM
If you're using OS X, you have the option in the Unity preferences to use the OS X color picker. This is quite a bit more robust than the Unity color picker, and has among other things the option of creating your own color lists and swatches, which basically amounts to being able to copy and paste colors.
As far as the pipette next to the color, it allows you to pick a color from any pixel you move the cursor over. This can be anywhere on the screen, not just the Unity window, so you could potentially create color swatches and use the pipette to pick from them.
answered Feb 16 '10 at 08:21 PM