自动更换Lightmap shder和添加Lightmap贴图
@MenuItem("MyPlugins/CreatLightMaterial")static function Apply ()
{
var TransformParent : Transform= Selection.activeTransform as Transform;
var trname:String;
var txname:String;
var i:int=0;
//var bumpMap : Texture;
// var www : WWW = new WWW ("http://images.earthcam.com/ec_metros/ourcams/fridays.jpg");
var bumpMap:Object[];
//var Tr:Transform[];
var TrArray=new Array();
if(TransformParent==null)
{
EditorUtility.DisplayDialog("选择","选择一个包含子物体的Transform对象", "确定");
return;
}
if(TransformParent.childCount==0)
{
EditorUtility.DisplayDialog("选择","选择的Transform对象没有子物体", "确定");
return;
}
var Tr=TransformParent.gameObject.GetComponentsInChildren( Transform );
bumpMap= Resources.LoadAll("New", Texture2D);
for(var tr:Transform in Tr)
{
if(tr!=TransformParent)
{
if(tr.renderer)
{
var mycolor:Color=Color(154,154,154,255);
var material = new Material (Shader.Find("Legacy Shaders/Lightmapped/Diffuse"));
if(!(tr.name+".mat"))
AssetDatabase.CreateAsset(material, "Assets/Resources/New/"+tr.name+".mat");
else {
i++;
if(!(tr.name+i+".mat"))
AssetDatabase.CreateAsset(material, "Assets/Resources/New/"+tr.name+i+".mat");
}
tr.gameObject.renderer.sharedMaterial=material;
}
trname=tr.name+"VRay 完成贴图";
for(var tx:Texture2D in bumpMap)
{
txname=tx.name;
if(trname==txname)
{
tr.gameObject.renderer.sharedMaterial.SetColor ("_Color",Color.gray );
tr.gameObject. renderer.sharedMaterial .SetTexture("_LightMap", tx);
}
}
}
}
}
楼主是超人 好帖就是要顶 真心顶 难得一见的好帖 说的非常好 好帖就是要顶 顶顶多好 难得一见的好帖 说的非常好