通过代码设置资源名字,为打包AssetBundle做准备,以及新打包系统
核心代码就是 importer.assetBundleName = name; 但是在这之前,我们需要超找到具体的资源,我们当然是不希望一个一个手动去查找。如果我选择一个文件夹,就可以查找到里边所有的资源并且标记,那么会省去很多力气
1. 首先选择一个物体,获得他的路径
2. 剔除unity 自带的 .meta文件
3. 遍历选中路径下的文件系统,如果是文件,那么标记,如果是文件夹,那么继续向下遍历,
3. 进行标记
这里说一下有点坑的地方,AssetImporter.GetAtPath(path); 这个IPA,里边的path不能是e:/sss/sss/xxx这种的,需要是相对路径Assets/xxx/xxx 这个坑坑的我好惨
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO; public class BuilderAssetsBunlds
{
//打包、、、、、、、、、、、、、、、、、、、、、、
[MenuItem("Tools/打包")]
public static void BundlerAssets()
{
// Debug.LogError("打包Assets");
BuildPipeline.BuildAssetBundles(GetOutAssetsDirecotion(), BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
} public static string GetOutAssetsDirecotion()
{
string assetBundleDirectory = Application.streamingAssetsPath;
if (!Directory.Exists(assetBundleDirectory))
{
Directory.CreateDirectory(assetBundleDirectory);
}
return assetBundleDirectory;
} // 设置资源名称///////////////////////////// [MenuItem("Tools/设置Assetbundle名字")]
public static void SetAssetBundellabls()
{
CheckFileSystemInfo();
} public static void CheckFileSystemInfo() //检查目标目录下的文件系统
{
AssetDatabase.RemoveUnusedAssetBundleNames(); //移除没有用的assetbundlename
Object obj = Selection.activeObject; //选中的物体
string path = AssetDatabase.GetAssetPath(obj);//选中的文件夹
CoutineCheck(path);
} public static void CheckFileOrDirectory(FileSystemInfo fileSystemInfo, string path) //判断是文件还是文件夹
{
FileInfo fileInfo = fileSystemInfo as FileInfo;
if (fileInfo != null)
{
SetBundleName(path);
}
else
{
CoutineCheck(path);
}
} public static void CoutineCheck(string path) //是文件,继续向下
{
DirectoryInfo directory = new DirectoryInfo(@path);
FileSystemInfo[] fileSystemInfos = directory.GetFileSystemInfos(); foreach (var item in fileSystemInfos)
{
// Debug.Log(item);
int idx = item.ToString().LastIndexOf(@"\");
string name = item.ToString().Substring(idx + ); if (!name.Contains(".meta"))
{
CheckFileOrDirectory(item, path + "/" + name); //item 文件系统,加相对路径
}
}
} public static void SetBundleName(string path) //设置assetbundle名字
{
var importer = AssetImporter.GetAtPath(path);
string[] strs = path.Split('.');
string[] dictors = strs[].Split('/');
string name = "";
for (int i = ; i < dictors.Length; i++)
{
if (i < dictors.Length - )
{
name += dictors[i] + "/";
}
else
{
name += dictors[i];
}
}
if (importer != null)
{
importer.assetBundleVariant = "bytes";
importer.assetBundleName = name;
}
else
Debug.Log("importer是空的");
} }
下篇连接
http://www.cnblogs.com/lzy575566/p/7895291.html
通过代码设置资源名字,为打包AssetBundle做准备,以及新打包系统的更多相关文章
- 前段时间说了AssetBundle打包,先设置AssetLabels,再执行打包,但是这样有个弊端就是所有设置了AssetLabels的资源都会打包,这次说说不设置AssetLabels,该如何打包AssetBundle
BuildPipeline.BuildAssetBundles() 这个函数,有多个重载,一个不用AssetBundleBuild数组,一个需要,如果设置了AssetLabels,那么这时候是不需要的 ...
- Unity手游之路<十一>资源打包Assetbundle
http://blog.csdn.net/janeky/article/details/17652021 在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制 ...
- 资源打包Assetbundle .
在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制成预设Prefab,打包成场景.今天我们来一起学习官方推荐的Assetbundle,它是Unity(Pro ...
- 实力封装:Unity打包AssetBundle(一)
说明:这是一系列循序渐进的教程,今天先介绍最简单的AssetBundle打包方式. 这是一个由在Unity中需要加载模型而引发出来的一系列坑,为了填坑花了不少时间,如果有需要在Unity中自定义菜单, ...
- Unity最新版打包AssetBundle和加载的方法
一.设置assetBundleName二.构建AssetBundle包三.上传AssetBundle到服务器四.把AssetBundle放到本地五.操作AssetBundle六.完整例子七.Asset ...
- 实力封装:Unity打包AssetBundle(大结局)
→→前情提要:让用户选择要打包的文件←← 大结局:更多选择 Unity打包AssetBundle从入门到放弃系列终于要迎来大结局了[小哥哥表示实在写不动了o(╥﹏╥)o]... 经过上一次的教程,其实 ...
- 实力封装:Unity打包AssetBundle(番外篇)
前情提要:第二种打包方式. 自定义AssetBundle包扩展名 在之前的教程中,我们已经多次提到过扩展名了,并且也已经说明了如何设置自定义的AssetBundle扩展名.至于为什么还要把它单独拿出来 ...
- 实力封装:Unity打包AssetBundle(二)
→前情提要:Unity最基本的AssetBundle打包方式. 第二种打包方式 Unity提供的BuildAssetBundles API还有一个重载形式,看下面↓↓ public static As ...
- Unity5.x shader打包AssetBundle总结
最近比较忙,好久没有更新博客了,新项目切换到unity5.x后使用了新的打包机制,在打包shader的时候遇到了一些问题,这里来记录一下吧. 在上一个项目中,我们使用unity4.7,对于shader ...
随机推荐
- <LeetCode OJ> 155. Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- CentOs上搭建nginx
目录 CentOs上搭建nginx 1. 在root环境下安装nginx 1.1 常用工具安装 1.2 关闭iptables规则 1.3 关闭SELinux 1.4 安装C/C++环境和PCRE库 1 ...
- java.lang.UnsupportedOperationException解决方法!!!
在项目中对List进行操作时报错java.lang.UnsupportedOperationException,后来发现操作的List是由数组转换而成的,通过看源码发现问题,并写测试程序如下. 代码块 ...
- 计算机图形学(二)输出图元_6_OpenGL曲线函数_2_中点画圆算法
中点画圆算法 如同光栅画线算法,我们在每一个步中以单位间隔取样并确定离指定圆近期的像素位置.对于给定半径r和屏幕中心(xc,yc),能够先使用算法计算圆心在坐标原点(0, 0)的圆的像素 ...
- 在Ubuntu 16.04下安装 virtualbox 5.2
sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian xenial contrib" ...
- macOS 安装安卓模拟器 并用charles抓包
mac上面安装安卓模拟器并能使用charles抓包软件调研 一.Genymotion 1.先下载Virtua Box虚拟机 https://www.virtualbox.org/wiki/Downlo ...
- Swift迎来了1.0 GM 版(2014.09.09)
2014年6月2日,swift开发团队将swift语言公之于众.而2014年9月9日迎来了swift的第二个里程碑,swift1.0版本号(GM),这意味着无论你的应用有一部分功能是用swift写的, ...
- AR9331出现connect-debounce failed,port 1 disabled解决方法备忘
基于AR9331的路由器,自己画的pcb板子,居然出现这个错误,百度下,貌似有不少人遇见过这个错误,可是在改动板子前我的固件用的是没问题的.USB完美使用 改动过板子后出现这个问题! hub 1-0: ...
- PHPUnit_Framework_Assert单元测试
先发下简书的干货: 教你一步一步写一个phpunit testcase:https://www.jianshu.com/p/ba6829a6f3ec 程序地址 https://github.com/y ...
- Linux 技巧:让进程在后台运行的可靠方法
原文链接:http://www.ibm.com/developerworks/cn/linux/l-cn-nohup/ 想让进程在断开连接后依然保持运行?如果该进程已经开始运行了该如何补救? 如果有大 ...