批量生成对象,然后把对象保存成预设,并且设置导出的命名。
[MenuItem("生成/生成")]
static void GetXXX()
{
//首先读取json
DirectoryInfo direction = new DirectoryInfo("Assets/ps");
DirectoryInfo[] directs = direction.GetDirectories();//文件夹
DirectoryInfo dir;
//遍历ps下的所有目录
for (int i = 0; i < directs.Length; i++)
{
dir = directs[i];
//按照目录名生成一个对象
GameObject objRoot = new GameObject("ps_" + dir.Name);
//把对象保存到预设
string prefabpath = "Assets/psPrefab/" + objRoot.name;
string localPath = prefabpath + ".prefab";
//这个代码屏蔽掉会覆盖现有预设
localPath = AssetDatabase.GenerateUniqueAssetPath(localPath);
//创建一个预设,并且设置导出的命名
PrefabUtility.SaveAsPrefabAssetAndConnect(objRoot, localPath, InteractionMode.UserAction);
AssetImporter assetImporter = AssetImporter.GetAtPath(localPath); //得到Asset
assetImporter.assetBundleName = objRoot.name;
assetImporter.assetBundleVariant = "ps";
}
}