ExportAssetBundles.rar

// C# Example
// Builds an asset bundle from the selected objects in the project view.
// Once compiled go to "Menu" -> "Assets" and select one of the choices
// to build the Asset Bundle using UnityEngine;
using UnityEditor;
using System.IO; public class ExportAssetBundles {
[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]//(包含依耐关系)
static void ExportResource () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != ) {
// Build the resource file from the active selection.
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
Selection.objects = selection; FileStream fs = File.Open(path+".log", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("文件 " + path + " 中的内容如下:");
foreach (Object obj in Selection.objects)
{
sw.WriteLine("Name: " + obj.name + "\t\t\tType:" + obj.GetType());
if (obj.GetType() == typeof(Object))
{
Debug.LogWarning("Name: " + obj.name + ", Type: " + obj.GetType() + ". 可能是unity3d不能识别的文件,可能未被打包成功");
}
}
sw.Flush();
fs.Flush();
sw.Close();
fs.Close();
/*
BuildAssetBundleOptions.CollectDependencies 包含所有依赖关系,应该是将这个物体或组件所使用的其他资源一并打包 BuildAssetBundleOptions.CompleteAssets 强制包括整个资源。例如,如果传递网格到BuildPipeline.BuildAssetBundle函数并使用CompleteAssets,它还将包括游戏物体和任意动画剪辑,在同样的资源。
应该是,下载一部分,其余一并下载 BuildAssetBundleOptions.DisableWriteTypeTree 禁用写入类型树,在资源包不包含类型信息。指定这个标识将使资源包易被脚本或Unity版本改变,但会使文件更小,更快一点加载。这个标识只影响默认包含的类型信息的平台资源包。 BuildAssetBundleOptions.DeterministicAssetBundle 确定资源包,编译资源包使用一个哈希表储存对象ID在资源包中。
这使您可以重建的资产包,并直接引用资源。当重建资源包对象,在重建之后保证有相同的ID。由于它是一个32位的哈希表空间,如果在资源包有许多对象,这将增加潜在哈希表冲突。
Unity将给出一个错误,而不在这种情况下编译。哈希表是基于资源的GUID和对象的自身ID。
DeterministicAssetBundle加载被标准资源包慢,这是因为线程后台加载API通常期望对象排序的方式,这会使读取加少寻址。
*/
//GC
System.GC.Collect();
}
}
[MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]//(不包含依耐关系)
static void ExportResourceNoTrack () {
// Bring up save panel
string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
if (path.Length != )
{
// Build the resource file from the active selection.
BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path, BuildAssetBundleOptions.CompleteAssets,BuildTarget.StandaloneWindows); FileStream fs = File.Open(path + ".log", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("文件 " + path + " 中的内容如下:");
foreach (Object obj in Selection.objects)
{
sw.WriteLine("Name: " + obj.name + "\t\t\tType: " + obj.GetType());
if (obj.GetType() == typeof(Object))
{
Debug.LogWarning("Name: " + obj.name + ", Type: " + obj.GetType() + ". 可能是unity3d不能识别的文件,可能未被打包成功");
}
}
sw.Flush();
fs.Flush();
sw.Close();
fs.Close();
}
//GC
System.GC.Collect();
}
//------------------------------------------------------------------------------------------------------------------
//单独打包文件夹中的每个文件为*.unity3d文件,放在原来的位置
[MenuItem("Assets/Build AssetBundles From Directory of Files")]
static void ExportAssetBundleEachfile2Path()
{
//在项目视图从选择的文件夹生成资源包
//记住,这个函数不跟踪依赖关系,也不是递归 // Get the selected directory
//获取选择的目录
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
string unity3dFileName;
Debug.Log("Selected Folder: " + path);
if (path.Length != )
{
int pos=path.LastIndexOf('/');
if (pos == -)
{
return;
}
unity3dFileName = path.Substring(pos+,path.Length-pos-);
Debug.Log("unity3dFileName: " + unity3dFileName);
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);
Debug.Log(filePath);
string localPath = "Assets/" + path;
if (index > )
localPath += filePath;
Object t = AssetDatabase.LoadMainAssetAtPath(localPath);
if (t != null)
{
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);
} }
}
//GC
System.GC.Collect();
}
[MenuItem("Assets/Build AssetBundles From by Directory")]
static void ExportAssetBundleByDirectory()
{
int dirs = Selection.objects.Length,i;
string[] filters = new string[]
{//过滤不打包的文件类型
".unity3d",
".log",
".db",
}; string savepath = EditorUtility.OpenFolderPanel("保存目录", System.IO.Directory.GetCurrentDirectory(), "");//.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
if (savepath == null || savepath=="") savepath = System.IO.Directory.GetCurrentDirectory();
bool copyfloderstruct = EditorUtility.DisplayDialog("请选择", "是否复制文件夹结构?", "复制","不复制"); for (i = ; i < dirs; i++)//处理同级文件夹
{
string path = AssetDatabase.GetAssetPath(Selection.objects[i]);
string unity3dFileName;
if (path.Length != )
{
//Debug.Log("path=" + path);
if (!System.IO.Directory.Exists(path)) continue;//说明这不是一个目录
int pos = path.LastIndexOf('/');
if (pos<) pos = ;
unity3dFileName = path.Substring(pos);
//获取文件列表
string[] fileEntries = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly);//仅本级目录 //过滤文件类型
int size = ;
bool[] enable=new bool[fileEntries.Length];
for ( int how = ; how < fileEntries.Length; how++)
{
bool filterFlag = false;
foreach (string s in filters)
{
if (fileEntries[how].EndsWith(s, System.StringComparison.OrdinalIgnoreCase))
{//=
filterFlag = true;
break;
}
}
enable[how] = filterFlag;
if (!filterFlag) size++;
}
if (size != )
{
Object[] objects = new Object[size]; //载入文件
int id = ;
for (int k = ; k < fileEntries.Length; k++)
{
if (enable[k] == false)
{
string fileName = fileEntries[k];
string localPath = fileName.Replace("\\", "/");
objects[id] = AssetDatabase.LoadMainAssetAtPath(localPath);//AssetDatabase.LoadAllAssetsAtPath不知为何不能用?
id++;
}
}
//打包
if (id != )
{
string outpath = savepath;
if (copyfloderstruct) outpath += path.Substring(path.IndexOf('/')); if (!System.IO.Directory.Exists(outpath)) System.IO.Directory.CreateDirectory(outpath); //string outpath = path;
string str = outpath + unity3dFileName + ".unity3d";
// Build the resource file from the active selection.
BuildPipeline.BuildAssetBundle(objects[], objects, str);//, BuildAssetBundleOptions.CompleteAssets,BuildTarget.StandaloneWindows FileStream fs = File.Open(outpath + unity3dFileName + ".log", FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine("文件 " + str + " 中的内容如下:");
foreach (Object obj in objects)
{
sw.WriteLine("Name: " + obj.name + "\t\t\tType: " + obj.GetType());
if (obj.GetType() == typeof(Object))
{
Debug.LogWarning("Name: " + obj.name + ", Type: " + obj.GetType()+". 可能是unity3d不能识别的文件,可能未被打包成功");
}
}
sw.Flush();
fs.Flush();
sw.Close();
fs.Close();
Debug.Log("打包成功! " + str);
}
else
{
Debug.LogError("没有可打包的文件! 目录:" + path);
}
}
else
{
Debug.LogError("没有可打包的文件! 全部被过滤, 目录:" + path);
}
}
}
//GC
System.GC.Collect();
}
//------------------------------------------------------------------------------------------------------------------
}

改造的unity3d文件打包脚本的更多相关文章

  1. Pyinstaller通过spec文件打包py程序(多个py脚本)

    Pyinstaller pyinstaller是python的一个第三方模块,使用它可以将python程序打包为可执行文件,实现打包后的程序在没有python环境的机器上也可以运行.pyinstall ...

  2. unity3d 资源打包加密 整理

    资源打包脚本,放到Assets\Editor 文件夹下 using UnityEngine; using System.Collections; using UnityEditor; using Sy ...

  3. .deb文件打包

    最近因项目需要,需要把文件夹打包为.deb格式的包,幸亏一位朋友帮忙指导了我一个晚上,才得以完成,这里再次对他表示感谢. 整理打包流程如下: 请先参考此博客内容,了解deb文件打包 如何制作Deb包和 ...

  4. Delphi 中将一些 Dll等生成资源文件打包成一个独立的EXE程序方法步骤

    资源文件一般为扩展名为res的文件,其自带的资源编译工具BRCC32.EXE(位于/Delphi/BIN目录下) 1.编写rc脚本文本 用记事本或其它文本编辑器编写一个扩展名为rc的文件,格式分别为在 ...

  5. 将linux下的rm命令改造成移动文件至回收站【转】

    转自:http://blog.csdn.net/a3470194/article/details/16863803 [-] 将linux下的rm命令改造成移动文件至回收站 将AIX下的rm命令改造成移 ...

  6. Unity3D 自动打包整个项目(以AssetBundle实现)

    原地址:http://blog.csdn.net/huang7jiao/article/details/18370653 需求: 在移动开发中,手动控制资源的加载.释放和热更新,是很有必要的. 而Un ...

  7. xcode8.3 shell 自动打包脚本 记录

    题记 xcode升级8.3后发现之前所用的xcode自动打包基本无法使用,因此在网上零碎找到些资料,将之前的脚本简化.此次脚本是基于xcode证书配置进行打包(之前是指定描述文件.相对繁琐).因此代码 ...

  8. 学习rollup.js模块文件打包

    学习rollup.js模块文件打包 一:rollup 是什么?Rollup 是一个 JavaScript 模块打包器,可以将小块代码编译成大块复杂的代码. webpack 和 Rollup 对比不同点 ...

  9. 如何把py文件打包成exe可执行文件

    如何把py文件打包成exe可执行文件 1.安装 pip install pyinstaller 或者 pip install -i https://pypi.douban.com/simple pyi ...

随机推荐

  1. spark sql遇到的问题

    项目背景:计算平台架构hadoop spark   spark on yarn,支持多种sql引擎如hive.spark sql.impala等. 问题描述:SPARK SQL在做insert ove ...

  2. Java实现打包下载BLOB字段中的文件

    概述 web项目的文件打包下载实现:servlet接收请求,spring工具类访问数据库及简化大字段内容获取,org.apache.tools.zip打包. 必要提醒:当前总结是继Java实现下载BL ...

  3. 洛谷P4609 [FJOI2016]建筑师(第一类斯特林数+组合数)

    题面 洛谷 题解 (图片来源于网络,侵删) 以最高的柱子\(n\)为分界线,我们将左边的一个柱子和它右边的省略号看作一个圆排列,右边的一个柱子和它左边的省略号看作一个圆排列,于是,除了中间的最高的柱子 ...

  4. Grunt Gulp Browserify Webpack

    Grunt 是相比后面几个更早的项目,他依赖于各种插件的配置.这是一个很好的解决方案,但是请相信我,你不会想看到一个 300 行的 Gruntfile Gulp 提供了一个不一样的解决方案,而不是依赖 ...

  5. JZYZOJ1445 [noip2014day1-T3]飞扬的小鸟 动态规划 完全背包

    http://172.20.6.3/Problem_Show.asp?id=1445 很容易看出来动态规划的本质,但是之前写的时候被卡了一下(不止一下),还是写一下题解. 直接暴力O(n*m^2)大概 ...

  6. [Codeforces #192] Tutorial

    Link: Codeforces #192 传送门 前两天由于食物中毒现在还要每天挂一天的水 只好晚上回来随便找套题做做找找感觉了o(╯□╰)o A: 看到直接大力模拟了 但有一个更简便的方法,复杂度 ...

  7. 【最小乘积生成树】bzoj2395[Balkan 2011]Timeismoney

    设每个点有x,y两个权值,求一棵生成树,使得sigma(x[i])*sigma(y[i])最小. 设每棵生成树为坐标系上的一个点,sigma(x[i])为横坐标,sigma(y[i])为纵坐标.则问题 ...

  8. hibernate处理视图问题(记录)

    Mark,在使用hibernate处理视图的时候.因为视图没有主键,这个用Myeclipse自动生成的POJO类就有两个.一个类名.java,一个是类名Id.java,而映射文件只有一个.因此造成一个 ...

  9. 【shiro】报错: If the controller requires proxying (e.g. due to @Transactional), please use class-based proxying.

    spring整合shiro,项目报如下错误: ==============异常开始============= java.lang.IllegalStateException: The mapped c ...

  10. jQuery Ajax 参数解析

    简单的例子: $.ajax({ type:"post", data:{a:acon,b:bcon} , url:"ajax.php", async:false ...