问题描述:
最近返现建模那边给的资源名包含一些#字符,导致加载AB时,报空的情况,一些模型资源名字包含一些特殊字符和很多空格. 在网上找了几个文章,都不是很适合,看整合了一下代码.
原因分析:
不知道啥原因
解决方案:
1.在编辑器里写一个扩展,自动检测资源名,删除特殊字符,空格. 在Project里面点击要操作的文件夹,然后调用扩展方法,把脚本放到Editor里面,
[MenuItem("资源管理/去除Gameobject名字特殊字符")]
public static void ReName()
{
UnityEngine.Object[] m_objects = UnityEditor.Selection.GetFiltered(typeof(UnityEngine.Object) , UnityEditor.SelectionMode.DeepAssets);
int index = 0;
for (int i = 0; i < m_objects.Length; i++)
{
string newName = m_objects[i].name;
Regex reg = new Regex(@"[^a-zA-Z0-9\u4e00-\u9fa5\s]");
Match m = reg.Match(newName);
bool isRename= newName.Contains(" ");
if (m.Success|| isRename)
{
if (System.IO.Path.GetExtension(UnityEditor.AssetDatabase.GetAssetPath(m_objects[i])) != "")
{
string path = UnityEditor.AssetDatabase.GetAssetPath(m_objects[i]);
newName = Regex.Replace(newName , @"[^a-zA-Z0-9\u4e00-\u9fa5\s]" , "");
newName = newName.Replace(" " , "");
UnityEditor.AssetDatabase.RenameAsset(path , newName);
}
}
index++;
}
UnityEditor.AssetDatabase.SaveAssets();
UnityEditor.AssetDatabase.Refresh();
}
|