zoukankan      html  css  js  c++  java
  • LittleTool之批量修改材质

    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.手动修改参数

      

  • 相关阅读:
    Python3 input() 函数
    Python3 enumerate() 函数
    Python3 ascii() 函数
    Python3 sorted() 函数
    css sprite
    Java 理论与实践: 并发集合类
    关于 Java Collections API 您不知道的 5 件事,第 1 部分
    Treasure! Free Mobile Design Resources
    Indigo Studio
    ionic:Build mobile apps faster with the web technologies you know and love
  • 原文地址:https://www.cnblogs.com/chimo523/p/5201489.html
Copyright © 2011-2022 走看看