using System;
using UnityEngine;
using UnityEditor;
public class AddChild : ScriptableWizard
{
GameObject addObj;//要增加子物体的对象
public int addObjectCount = 10; //要增加的数量
public string prefix = "Shoot";
public bool isAddObj = true;
public string addObjectDividingLine = "-----我是分割线-----";
void AddChilds()
{
addObj = Selection.activeGameObject;
if (!addObj)
{
throw new NullReferenceException("没有找到目标");
}
int objCount = addObj.transform.childCount;
string p = prefix;
for (int index = objCount; index < objCount + addObjectCount; index++)
{
GameObject clone = new GameObject();
if (prefix.ToLower() == "shoot")
{
prefix = p;
if (index >= 0 && index < 10)
prefix = prefix + "00";
else if (index >= 10 && index < 100)
prefix = prefix + "0";
else if (index >= 100 && index < 1000)
prefix = prefix + "";
}
clone.name = prefix + index;
clone.transform.parent = addObj.transform;
}
}
void OnWizardCreate()
{
if (isAddObj)
AddChilds();
}
[MenuItem("File/Export/Wavefront %#L")]
static void CreateWizard()
{
DisplayWizard("Panel", typeof(AddChild), "Finish");
}
}
按下快捷键ctrl+shift+L会弹出一个窗口
功能就是为选中的物体增加一定数量的有前缀的子物体