FBX生成Prefab

来源:互联网 发布:男鞋推荐学生知乎 编辑:程序博客网 时间:2024/05/17 22:44
using UnityEngine;using UnityEditor;using System.IO;using System.Collections;public class GeneratePrefab {    private static string prefabDirectory = "/Prefab/Monster";    private static string prefabExtension = ".prefab";    [MenuItem("Example/Generate prefab")]    public static void Generate()    {        GameObject selectedGameObject = Selection.activeGameObject;        string selectedAssetPath = AssetDatabase.GetAssetPath(selectedGameObject);        if(string.IsNullOrEmpty(selectedAssetPath))        {            return;        }        string modelAssetPath = string.Concat(Application.dataPath,prefabDirectory);        string modelParentPath = string.Concat("Assets/Resources", prefabDirectory);        string modelFullPath = string.Concat(modelParentPath, "/", "model");        if (!Directory.Exists(modelFullPath))        {            AssetDatabase.CreateFolder(modelParentPath , "model");        }        GameObject cloneObj = GameObject.Instantiate<GameObject>(selectedGameObject);        cloneObj.name = cloneObj.name.Replace("(Clone)", string.Empty);        string genPrefabFullName = string.Concat(modelFullPath, "/", cloneObj.name, prefabExtension);        Object prefabObj = PrefabUtility.CreateEmptyPrefab(genPrefabFullName);        GameObject prefab = PrefabUtility.ReplacePrefab(cloneObj, prefabObj);        GameObject.DestroyImmediate(cloneObj);    }}

0 0
原创粉丝点击