Assign Color[] var in prefabs using Editor Scripting

Here’s the backstory of what I’m doing:

  • I have 3d models I’m importing and then placing them in prefabs.
  • Each side of my model has it’s own color, which is UV mapped onto a texture.
  • Each prefab has a script that has a variable for Color array.
  • So far I’ve been manually adding the colors in the inspector for each side/color of my models.

Then I did some research into RaycastHit.textureCoord and Texture2D.GetPixelBilinear, and I’ve created a script that will raycast each side of my models and fill in the Color variable with the correct Color based on its texture’s UVs.

The problem: this happens at playtime and I only need it done in the Editor while I’m building my game and before I publish it. What I need in the published build are the correctly assigned variables, that are pre-assigned in the Editor. I don’t want to assign them during playtime.

QUESTION
So what I would like to do is convert my playtime script into something that will work as an Editor script.
Where I can import my models, create my prefabs and assign the script that has Color variable. Then use an Editor script that will find the color of each side of the object and assign/save it to the prefab script.

Is this possible to do, and hopefully any examples/insight of how to do it? I’ve never done Editor scripting before.

Thanks!

Yep: http://unity3d.com/support/documentation/ScriptReference/ExecuteInEditMode.html