您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

24 行
971 B

using System.IO;
using UnityEngine;
namespace UnityEditor.Perception.AssetPreparation
{
public class CreatePrefabFromSelectedAssets : MonoBehaviour
{
/// <summary>
/// Function for creating prefabs from multiple models with one click. Created prefabs will be placed in the same folder as their corresponding model.
/// </summary>
[MenuItem("Assets/Perception/Create Prefabs from Selected Models")]
static void CreatePrefabsFromSelectedModels()
{
foreach (var selection in Selection.gameObjects)
{
var path = AssetDatabase.GetAssetPath(selection);
var tmpGameObject = Instantiate(selection);
var destinationPath = Path.GetDirectoryName(path) + "/" + selection.name + ".prefab";
PrefabUtility.SaveAsPrefabAsset(tmpGameObject, destinationPath);
DestroyImmediate(tmpGameObject);
}
}
}
}