LittleTool之批量修改材质
2016-02-19 16:38
225 查看
using UnityEngine; using System.Collections; using UnityEditor; public class ChangeMaterial : EditorWindow { static string path = "Assets/_Materials/"; static string shaderName="Custom/CurvedWorld"; static string tempName1="_Curvature";//材质球参数,需要手动修改 static string tempName2="_Axis"; static float temp1=1; static float temp2=1; public static string [] postfix = { ".png",".jpg",".tga","psd" }; [MenuItem ("Custom/ChangeMaterial")] public static void Change() { if (Selection.activeGameObject != null) { foreach (GameObject go in Selection.gameObjects) { Renderer render = go.GetComponentInChildren<Renderer> (); if (render != null) { Texture texture = GetTexture (go.name);//根据对象名获取图片 if (texture != null) { Material newMat = new Material (Shader.Find(shaderName)); newMat.SetFloat(tempName1,temp1); newMat.SetFloat (tempName2,temp2); AssetDatabase.CreateAsset (newMat, path + go.name+".mat"); render.sharedMaterial=newMat; render.sharedMaterial.mainTexture = texture; Debug.Log ("成功!"); } else { Debug.Log ("失败!"); } } } } } static Texture GetTexture(string name) { foreach(string str in postfix) { Texture texture = AssetDatabase.LoadAssetAtPath("Assets/_Textures/" + name+str,typeof(Texture)) as Texture; if(texture != null) return texture; } return null; } }
注意:
1.将要用到的模型都制作为预制体!!!
2.手动修改参数
相关文章推荐
- 工具的使用——windows操作系统的使用(创建宽带连接)
- OC中的关键字,weak,assign,copy,strong,nonatomic,retain
- [codevs1993]草地排水(最大流)
- hdu5534 Partial Tree
- lua中的require机制
- LeetCode 129. Sum Root to Leaf Numbers 解题报告
- XIB和storyboard
- loadrunner 并发操作集合点配置
- 关于redis启动流程介绍
- iOS 快速遍历 效率分析 for loop for in enumerateBlock 适用条件
- Integrity Measurement Architecture (IMA)
- Docker安装
- css3实现各种角度的三角形
- Spring MVC下 Excel 导入导出(poi)
- JavaScript 基础知识之对比记忆学习
- css 实现未知图片垂直居中
- 懒加载
- PHPStorm中的快捷键
- .net变量判断
- 指针减法