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. python判断一个对象是可迭代?

    1.介绍一下如何判断一个对象是可迭代的? 通过collections模块的Iterable类型判断: >>> from collections import Iterable > ...

  2. java过滤敏感词汇

    前言 现在几乎所有的网站再发布带有文字信息的内容时都会要求过滤掉发动的.不健康的.影响社会安定的等敏感词汇,这里为大家提供了可以是现在这种功能的解决方案 第一种方式 创建敏感词汇文件:首先需要准备一个 ...

  3. 《深入浅出Nodejs》笔记——模块机制(2)

    前言 书上还有很大一部分讲了C/C++模块的编译过程.核心模块编写和C/C++扩展模块的内容,不过我对C++一窍不通因此没有仔细看,如果以后需要再自习看吧. 包与NPM 第三方模块中,模块和模块之间是 ...

  4. RabbitMQ (九) 消息的参数详解

    上篇文章讲了声明一个队列时的参数设置,这篇文章主要说一说发布消息时的参数设置. 发布消息时的完整入参是这样的: channel.BasicPublish ( exchange: "test_ ...

  5. 开发Android逆向工具

    韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha  313134555@qq.com 源代码及演示程序,请点击这里下载 下载地址: [北方网通]    [电信网通] [下载说明] ...

  6. 【BZOJ 2646】【NEERC 2011】flight

    http://www.lydsy.com/JudgeOnline/problem.php?id=2646 夏令营alpq654321讲课时说这道题很简单但并没有几个人提交,最近想复习一下线段树,脑袋一 ...

  7. [Codeforces #210] Tutorial

    Link: Codeforces #210 传送门 A: 贪心,对每个值都取最大值,不会有其他解使答案变优 #include <bits/stdc++.h> using namespace ...

  8. 【树形dp】Godfather

    [POJ3107]Godfather Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7212   Accepted: 253 ...

  9. 【最小割】【Dinic】Gym - 101128F - Landscaping

    http://blog.csdn.net/lxy767087094/article/details/68942422 #include<cstdio> #include<cstrin ...

  10. 【后缀自动机】hihocoder1441 后缀自动机一·基本概念

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi:今天我们来学习一个强大的字符串处理工具:后缀自动机(Suffix Automaton,简称SAM).对于一个字符串 ...