700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > unity将预制体写成fbx_unity 将fbx转成prefab

unity将预制体写成fbx_unity 将fbx转成prefab

时间:2020-01-13 08:20:07

相关推荐

unity将预制体写成fbx_unity 将fbx转成prefab

前段时间项目需要大量的fbx模型要转成prefab模式,手动拖入场景再拖出的话太麻烦,不方便,逼格不够高。于是写了个脚步,注意要放在Editor文件夹下。using UnityEngine;using UnityEditor;using System.IO;using System.Collections;/// /// fbx放在资源根目录的fbx文件夹中,脚步会遍历该目录,将fbx转成prefab放在子目录prefab中/// public class FbxToPrefab : Editor{ [MenuItem("Tool/FbxToPrefab")] static void FTP() { //GameObject[] o = AssetDatabase.LoadAllAssetsAtPath("Assets/fbx/") as GameObject[]; //这里不能使用AssetDatabase.LoadAllAssetsAtPath是因为这个方法并不是加载目录中的所有资源,而是用于一个go包含多个mesh的情况,具体看官网描述和下面链接 ///threads/loadallassetsatpath.21444/ ///threads/how-to-get-list-of-assets-at-asset-path.18898/ GameObject[] o = GetAtPath("fbx/"); if (!Directory.Exists(Application.dataPath + "/fbx/prefab")) Directory.CreateDirectory(Application.dataPath + "/fbx/prefab"); foreach (GameObject go in o) { PrefabUtility.CreatePrefab("Assets/fbx/prefab/" + go.name + ".prefab", go); } AssetDatabase.Refresh(); } static T[] GetAtPath(string path) { ArrayList al = new ArrayList(); string[] fileEntries = Directory.GetFiles(Application.dataPath + "/" + path); foreach (string fileName in fileEntries) { int assetPathIndex = fileName.IndexOf("Assets"); string localPath = fileName.Substring(assetPathIndex); Object t = Resources.LoadAssetAtPath(localPath, typeof(T)); if (t != null) al.Add(t); } T[] result = new T[al.Count]; for (int i = 0; i < al.Count; i++) result[i] = (T)al[i]; return result; }}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。