核心代码就是  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做准备,以及新打包系统的更多相关文章

  1. 前段时间说了AssetBundle打包,先设置AssetLabels,再执行打包,但是这样有个弊端就是所有设置了AssetLabels的资源都会打包,这次说说不设置AssetLabels,该如何打包AssetBundle

    BuildPipeline.BuildAssetBundles() 这个函数,有多个重载,一个不用AssetBundleBuild数组,一个需要,如果设置了AssetLabels,那么这时候是不需要的 ...

  2. Unity手游之路<十一>资源打包Assetbundle

    http://blog.csdn.net/janeky/article/details/17652021 在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制 ...

  3. 资源打包Assetbundle .

    在手游的运营过程中,更新资源是比不可少的.资源管理第一步是资源打包.传统的打包可以将所有物件制成预设Prefab,打包成场景.今天我们来一起学习官方推荐的Assetbundle,它是Unity(Pro ...

  4. 实力封装:Unity打包AssetBundle(一)

    说明:这是一系列循序渐进的教程,今天先介绍最简单的AssetBundle打包方式. 这是一个由在Unity中需要加载模型而引发出来的一系列坑,为了填坑花了不少时间,如果有需要在Unity中自定义菜单, ...

  5. Unity最新版打包AssetBundle和加载的方法

    一.设置assetBundleName二.构建AssetBundle包三.上传AssetBundle到服务器四.把AssetBundle放到本地五.操作AssetBundle六.完整例子七.Asset ...

  6. 实力封装:Unity打包AssetBundle(大结局)

    →→前情提要:让用户选择要打包的文件←← 大结局:更多选择 Unity打包AssetBundle从入门到放弃系列终于要迎来大结局了[小哥哥表示实在写不动了o(╥﹏╥)o]... 经过上一次的教程,其实 ...

  7. 实力封装:Unity打包AssetBundle(番外篇)

    前情提要:第二种打包方式. 自定义AssetBundle包扩展名 在之前的教程中,我们已经多次提到过扩展名了,并且也已经说明了如何设置自定义的AssetBundle扩展名.至于为什么还要把它单独拿出来 ...

  8. 实力封装:Unity打包AssetBundle(二)

    →前情提要:Unity最基本的AssetBundle打包方式. 第二种打包方式 Unity提供的BuildAssetBundles API还有一个重载形式,看下面↓↓ public static As ...

  9. Unity5.x shader打包AssetBundle总结

    最近比较忙,好久没有更新博客了,新项目切换到unity5.x后使用了新的打包机制,在打包shader的时候遇到了一些问题,这里来记录一下吧. 在上一个项目中,我们使用unity4.7,对于shader ...

随机推荐

  1. MD5值转换(Hex 32位 <-> base64 24位)

    关于MD5值的原理本文不在介绍,本文主要介绍MD5值的两种编码的相互转换(32位和BASE64编码的24位),实际应用过程中经常会涉及到两种编码的相互转换.快熟使用工具tomeko.net. C#示例 ...

  2. Android源码在线查看网址

    1 http://www.grepcode.com/project/repository.grepcode.com/java/ext/com.google.android/android/

  3. ASP.NET中的配置文件

    ASP.NET中的配置文件 原创 2014年10月13日 08:15:27 1199   在机房收费系统的时候曾经应用过配置文件,当时也就那么一用对配置文件了解的不是很透彻,下面就来总结一下有关配置文 ...

  4. Https所涉及名词及相关后缀名解释

    HTTPS: HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版.即 ...

  5. C/C++ 内存管理总结

    C内存管理 存储时: 执行程序在存储时(没有调入到内存)分为代码区(text).数据区(data)和未初始化数据区(bss)3个部分. 1 代码区(text segment) 存放CPU执行的机器指令 ...

  6. bean对应mapper.xml字段

    在bean中set的时候最好写上这个,避免报空指针............... public void setImgAddress(String imgAddress) { this.imgAddr ...

  7. hdu 1811 Rank of Tetris(拓扑,并查集)

    题意:略 分析:排序先按rating,若相同,则按rp.考虑到每个人的rp均不同,所以rating相同的人必然可以排序.那么只需要考虑rating不同的集合了.  大小关系可以用有向边表示,而大小关系 ...

  8. 09 nginx Rewrite(重写)详细解析

    一:Rewrite(重写)详细解析 rewrite 重写 重写中用到的指令 if  (条件) {}  设定条件,再进行重写 set #设置变量 return #返回状态码 break #跳出rewri ...

  9. PHP自动加载功能原理解析

    前言 这篇文章是对PHP自动加载功能的一个总结,内容涉及PHP的自动加载功能.PHP的命名空间.PHP的PSR0与PSR4标准等内容. 一.PHP自动加载功能 PHP自动加载功能的由来 在PHP开发过 ...

  10. centos7.0 增加/usr分区的容量减少home分区的大小

    把/home内容备份,然后将/home文件系统所在的逻辑卷删除,扩大/root文件系统,新建/home:tar cvf /tmp/home.tar /home #备份/homeumount /home ...