1.以下代码摘自Unity 脚本API,但有调整,不调整无法正常使用
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
public class CreateMultiPrefab : Editor
{
static string path = "/Prefabs/Models/";
[MenuItem("[Neo-Unity3D 2016-2022]/Create Multi-Prefab")]
static void Create()
{
// Keep track of the currently selected GameObject(s)
GameObject[] objectArray = Selection.gameObjects;
// Loop through every GameObject in the array above
foreach (GameObject gameObject in objectArray)
{
// Create folder Prefabs and set the path as within the Prefabs folder,
// and name it as the GameObject's name with the .Prefab format
if (!Directory.Exists(path))
AssetDatabase.CreateFolder("Asssets/Prefabs/", "Models");
string localPath = path + gameObject.name + ".prefab";
// Make sure the file name is unique, in case an existing Prefab has the same name.
//localPath = AssetDatabase.GenerateUniqueAssetPath(localPath);
//Debug.Log(localPath);
// Create the new Prefab and log whether Prefab was saved successfully.
bool prefabSuccess;
PrefabUtility.SaveAsPrefabAsset(gameObject,Application.dataPath+ localPath, out prefabSuccess);
if (prefabSuccess == true)
Debug.Log("Prefab was saved successfully");
else
Debug.Log("Prefab failed to save" + prefabSuccess);
}
}
}