Hi,
i work on a tool to change all material objects in my level in edit time. I need to apply a different number of textures to each object, with my own shader.
Also i need to create this object in my level as one complete prefab to use it in other scenes. But when i do this, all metarials are lost in the new scene. In the origin scene all materials are still exist.
Has anybody an idea, what to do?
this is my example code from my editor script:
public void OnWizardCreate ()
{
int counter = 0;
foreach( Transform obj in Selection.transforms )
{
MeshFilter meshFilter = obj.GetComponent( typeof( MeshFilter) ) as MeshFilter;
if( meshFilter != null )
{
Material mat = new Material( Shader.Find ( shaderNames[numberLayers] ) );
mat.SetTexture( "_BaseTex", layer1Tex );
meshFilter.renderer.sharedMaterial = mat;
counter++;
}
}
EditorUtility.DisplayDialog( "Message", "materials replaced: " + counter, "OK" );
}
Maybe it has to do with the different of sharedMaterial and material of the renderer object. But i don’t know the “exact” sense and what “realy” happen.
On the other side it makes sense to create a new material in the asset directory for all my dynamic generated materials, but how?
How can i create, for example, 60 materials and store them in the asset folder within a editor script?
Thanks, Horst