名字的特点:
1,有规律
2,有相同的内容
可以用这个工具,修改物体的名字,在菜单中生成的自定义目录“DCCTools/Rename”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ReplanName : ScriptableWizard
{
[MenuItem("DCCTools/Rename")]
static void CreateWizard()
{
ScriptableWizard.DisplayWizard<ReplanName>("替换名称","确定");
}
[Header("物体中包含的内容")]
public string originalName="需要替换的的内容";
public string replanContent="替换的内容";
private void OnWizardCreate()
{
GameObject[] Prefabs = Selection.gameObjects;
foreach (GameObject go in Prefabs)
{
if (go.name.Contains(originalName))
{
Debug.Log(go.name);
go.name = go.name.Replace(originalName, replanContent);
}
Transform[] m_childTransformArray = go.GetComponentsInChildren<Transform>();
if (m_childTransformArray.Length>=1)
{
for (int i = 0; i < m_childTransformArray.Length; i++)
{
if (m_childTransformArray[i].name.Contains(originalName))
{
m_childTransformArray[i].name = m_childTransformArray[i].name.Replace(originalName, replanContent);
}
}
}
}
}
//刚打开的时候和改变数值的时候调用
private void OnWizardUpdate()
{
helpString = "";
errorString = "";
string Name = "";
if (Selection.gameObjects.Length > 0)
{
GameObject[] Prefabs = Selection.gameObjects;
foreach (GameObject go in Prefabs)
{
Name += go.name + "、";
}
helpString = "当前选择了" + Name + "物体";
}
else
{
errorString = "请选择物体";
}
}
//选择的物体改变的时候调用
private void OnSelectionChange()
{
OnWizardUpdate();
}
}