改造的unity3d文件打包脚本
-
// 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文件打包脚本的更多相关文章
- Pyinstaller通过spec文件打包py程序(多个py脚本)
Pyinstaller pyinstaller是python的一个第三方模块,使用它可以将python程序打包为可执行文件,实现打包后的程序在没有python环境的机器上也可以运行.pyinstall ...
- unity3d 资源打包加密 整理
资源打包脚本,放到Assets\Editor 文件夹下 using UnityEngine; using System.Collections; using UnityEditor; using Sy ...
- .deb文件打包
最近因项目需要,需要把文件夹打包为.deb格式的包,幸亏一位朋友帮忙指导了我一个晚上,才得以完成,这里再次对他表示感谢. 整理打包流程如下: 请先参考此博客内容,了解deb文件打包 如何制作Deb包和 ...
- Delphi 中将一些 Dll等生成资源文件打包成一个独立的EXE程序方法步骤
资源文件一般为扩展名为res的文件,其自带的资源编译工具BRCC32.EXE(位于/Delphi/BIN目录下) 1.编写rc脚本文本 用记事本或其它文本编辑器编写一个扩展名为rc的文件,格式分别为在 ...
- 将linux下的rm命令改造成移动文件至回收站【转】
转自:http://blog.csdn.net/a3470194/article/details/16863803 [-] 将linux下的rm命令改造成移动文件至回收站 将AIX下的rm命令改造成移 ...
- Unity3D 自动打包整个项目(以AssetBundle实现)
原地址:http://blog.csdn.net/huang7jiao/article/details/18370653 需求: 在移动开发中,手动控制资源的加载.释放和热更新,是很有必要的. 而Un ...
- xcode8.3 shell 自动打包脚本 记录
题记 xcode升级8.3后发现之前所用的xcode自动打包基本无法使用,因此在网上零碎找到些资料,将之前的脚本简化.此次脚本是基于xcode证书配置进行打包(之前是指定描述文件.相对繁琐).因此代码 ...
- 学习rollup.js模块文件打包
学习rollup.js模块文件打包 一:rollup 是什么?Rollup 是一个 JavaScript 模块打包器,可以将小块代码编译成大块复杂的代码. webpack 和 Rollup 对比不同点 ...
- 如何把py文件打包成exe可执行文件
如何把py文件打包成exe可执行文件 1.安装 pip install pyinstaller 或者 pip install -i https://pypi.douban.com/simple pyi ...
随机推荐
- 使用keras时出现 `pydot` failed to call GraphViz的解决办法
问题来源于使用了 keras.utils.plot_model,报错内容为: 2018-08-29 08:58:21.937037: I tensorflow/core/platform/cpu_fe ...
- PIE.htc的使用
文件下载:http://css3pie.com/download/ 使用: .pie_radius{ width:200px; height:200px; background-color:red; ...
- RMQ入门
注:为方便描述算法 便于记忆 所以ST的代码用Pascal书写 见谅 RMQ,即Range Minimum/Maximum Query问题,给定一个区间,询问不同子区间的最值问题. 当询问次数较少时, ...
- 【DFS】奇怪的电梯
奇怪的电梯 题目描述 有一天桐桐做了一个梦,梦见了一种很奇怪的电梯.大楼的每一层楼都可以停电梯,而且第i层楼(1≤i≤N)上有一个数字K:(0≤Ki≤N).电梯只有四 个按钮:开,关,上,下.上下的层 ...
- BZOJ 3399 [Usaco2009 Mar]Sand Castle城堡(贪心)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3399 [题目大意] 将一个集合调整成另一个集合中的数,把一个数+1需要消耗x,-1需要 ...
- 【数位dp】【二分】Gym - 101411H - Hotel in Ves Lagos
数位dp预处理之后,可以容易得到f(x),代表小于等于x的数中,有多少个不含13的.然后就能二分答案啦. #include<cstdio> #include<iostream> ...
- 实验四实验报告————Android基础开发
实验四实验报告----Android基础开发 任务一 关于R类 关于apk文件 实验成果 任务二 活动声明周期 实验成果 任务三 关于PendingIntent类 实验成果 任务四 关于布局 实验成果 ...
- Activity(活动)生命周期(1)--返回栈
Android是使用任务(task)来管理活动的,一个任务就是一组存放在栈里的活动的集合,这个栈也被称为返回栈(Back stack).栈是一种后进先出的数据结构,在默认情况下,每当我们启动了一个新的 ...
- [转]Java中fina以及static的意义
一.final 根据程序上下文环境,Java关键字final有“这是无法改变的”或者“终态的”含义,它可以修饰非抽象类.非抽象类成员方法和变量.你可能出于两种理解而需要阻止改变:设计或效 ...
- MYSQL复习笔记9-存储过程
date: 20140208auth: Jin参考引用:http://blog.sina.com.cn/s/blog_52d20fbf0100ofd5.html mysql存储过程详解一.基本介绍1. ...