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. CSU 2151 集训难度【多标记线段树】

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=2151 Input 第一行三个数n,m,v0 表示有n名萌新和m次调整,初始时全部萌新的集训难度 ...

  2. STL容器 -- Stack

    核心:后进后出, LIFO. 头文件: #include <stack> 常用的构造方法: stack<int> st1; //构造一个空的存放 int 型的栈 stack&l ...

  3. Linux命令之rlogin

    rlogin [-8EKLdx] [-e char] [-l username] host rlogin在远程主机host上开始一个终端会话. (1).选项 -8 选项允许进行8位的输入数据传送:否则 ...

  4. HTTP Slow Attack测试工具SlowHTTPTest

    HTTP Slow Attack测试工具SlowHTTPTest   Slow Attack是HTTP常见的一种拒绝服务攻击方式.它通过消耗服务器的系统资源和连接数,导致Web服务器无法正常工作.常见 ...

  5. BM算法--串匹配

    BM(Boyer-Moore)算法,后缀匹配,是指模式串的比较从右到左,模式串的移动也是从左到右的匹配过程,一般情况比KMP算法要快.时间复杂度O(m/n) C++描述(教师版) int BM(cha ...

  6. luogu P1137 旅行计划

    题目描述 小明要去一个国家旅游.这个国家有N个城市,编号为1-N,并且有M条道路连接着,小明准备从其中一个城市出发,并只往东走到城市i停止. 所以他就需要选择最先到达的城市,并制定一条路线以城市i为终 ...

  7. 【位运算】【BFS】移动玩具

    1054: [HAOI2008]移动玩具 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2246  Solved: 1246[Submit][Stat ...

  8. 21点游戏java实现

    21点的基本知识 21点是世界上比较流行的扑克游戏项目 除掉大小王的一副扑克牌,共计52张牌 21点不区分花色,其中A----10均代表扑克牌本身的点数J Q K代表10点 区分庄家和闲家,其中闲家可 ...

  9. Educational Codeforces Round 9 B. Alice, Bob, Two Teams 前缀和

    B. Alice, Bob, Two Teams 题目连接: http://www.codeforces.com/contest/632/problem/B Description Alice and ...

  10. oracle client PLSQL配置

    date:20140525auth:Jin platform :windows 一.服务端启动服务和创建账号# su - oracle$ lsnrctl start$ sqlplus / as sys ...