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的情况,具体看官网描述和下面链接 //http://forum.unity3d.com/threads/loadallassetsatpath.21444/ //http://forum.unity3d.com/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; }}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值