700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > unity 材质球无法编辑_【每天一个Unity技巧】批量修改材质球的主贴图和添加法线贴图...

unity 材质球无法编辑_【每天一个Unity技巧】批量修改材质球的主贴图和添加法线贴图...

时间:2020-01-22 21:40:05

相关推荐

unity 材质球无法编辑_【每天一个Unity技巧】批量修改材质球的主贴图和添加法线贴图...

注释以后有空再写吧,加班到现在还没吃饭呢

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEditor;

using System.IO;

using System.Text.RegularExpressions;

///

/// 根据材质球上的主贴图名字进行改为同名的其他后缀的贴图,并且加上法线贴图

///

public class Replace

{

[MenuItem("Tools/replace")]

public static void Rename()

{

Object[] m_objects = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);//选择的所以对象

foreach (Object item in m_objects)

{

string path = AssetDatabase.GetAssetPath(item);

Debug.Log("材质球的位置:");

Debug.Log(path);

if (Path.GetExtension(path) != "")//判断路径是否为空

{

if (item.GetType() == typeof(Material))

{

Material m = (Material)item;

path = AssetDatabase.GetAssetPath(m.mainTexture);

Debug.Log("材质球上主贴图的位置:");

Debug.Log(path);

string[] strs = path.Split('.');

string afterpath = strs[0] + ".jpg";

Debug.Log("材质球上主贴图相应后缀的位置:");

Debug.Log(afterpath);

if (AssetDatabase.LoadAssetAtPath(afterpath))

m.mainTexture = AssetDatabase.LoadAssetAtPath(afterpath);

string strNormalMap = strs[0] + "_NRM.jpg";

Texture texturebump = AssetDatabase.LoadAssetAtPath(strNormalMap);

if (texturebump != null)

m.SetTexture("_BumpMap", texturebump);

}

}

}

AssetDatabase.SaveAssets();

AssetDatabase.Refresh();

Debug.Log("Complete!");

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。