Unity批量处理模型贴图

思路:判断模型文件夹里文件后缀,通过AssetDatabase.LoadAssetAtPath加载后缀为*.mat的文件,类型为Material

[MenuItem("ArtBatch/批量处理贴图颜色")]
    static void DoSetTexture()
    {
        string[] selectedAssets = AssetDatabaseUtility.GetSelectedDeepAssets();
        for (int i = 0; i < selectedAssets.Length; i++)
        {
            string path = selectedAssets[i];
            bool isMat = path.EndsWith(".mat");
            if (isMat)
            {
                Material mat = AssetDatabase.LoadAssetAtPath(path, typeof(Material)) as Material;
                if (mat != null)
                {
                    Color c = new Color();
                    c.r = (float)140 / 255f;
                    c.g = (float)140 / 255f;
                    c.b = (float)140 / 255f;
                    c.a = 1;
                    mat.SetColor("_Color", c);
                    mat.SetFloat("_FinalPower", 2);
                }
            }
 
        }
    }

你可能感兴趣的:(unity)