Unity3D教程:格式的导出与加载

本文介绍了一种将Unity3D项目的资源文件批量转换为Unity3D格式的方法。通过使用提供的脚本,开发者只需简单地选择文件夹并点击菜单项即可完成资源的打包工作。

1.导出Unity3D格式资源:

把以下代码的脚本放到一个文件夹里面,选中该文件夹,再点击菜单栏上的按钮“Asset/Build AssetBundles From Directory of Files”,就成功转成Unity3D格式了。


以下是unity3d脚本

    using UnityEngine;  
    using UnityEditor;  
    using System.IO;  
    public class BuildAssetBundlesFromDirectory {  
 
        [@MenuItem("Asset/Build AssetBundles From Directory of Files")]  
 
        static void ExportAssetBundles () {  
 
            // Get the selected directory  
 
            //获取选择的目录  
 
            string path = AssetDatabase.GetAssetPath(Selection.activeObject);  
 
            Debug.Log("Selected Folder: " + path);  
 
            if (path.Length != 0) {  
 
                path = path.Replace("Assets/", "");  
 
                string [] fileEntries = Directory.GetFiles(Application.dataPath+"/"+path);  
 
                foreach(string fileName in fileEntries) {  
 
                    string filePath = fileName.Replace("\\","/");  
 
                    int index = filePath.LastIndexOf("/");  
 
                    filePath = filePath.Substring(index+1);  
 
                    Debug.Log("filePath:"+filePath);  
 
                    string localPath = "Assets/" + path+"/";  
 
                    if (index > 0)  
 
                    localPath += filePath;  
 
                    Object t = AssetDatabase.LoadMainAssetAtPath(localPath);  
 
                    if (t != null) {  //Unity3D教程手册:www.unitymanual.com
 
                        Debug.Log(t.name);  
 
                        string bundlePath = "Assets/" + path + "/" + t.name + ".unity3d";  
 
                        Debug.Log("Building bundle at: " + bundlePath);  
 
                        // Build the resource file from the active selection.  
 
                        //从激活的选择编译资源文件  
 
                        BuildPipeline.BuildAssetBundle  
 
                        (t, null, bundlePath, BuildAssetBundleOptions.CompleteAssets);  
 
                    }  
 
 
 
                }  
 
            }  
 
        }  
 
    }  

unity3d

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值