核心代码就是  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. PHP面试题及答案解析(4)—PHP核心技术

    1.写出一个能创建多级目录的PHP函数. <?php /** * 创建多级目录 * @param $path string 要创建的目录 * @param $mode int 创建目录的模式,在 ...

  2. CSS 温故而知新 断句失败

    设置了一定的宽度和高度.但无论是下面哪句都无效. word-break: break-word; word-wrap: break-word; 原因竟然是因为 /* white-space: nowr ...

  3. 使用React的static方法实现同构以及同构的常见问题

    代码地址请在github查看,假设有新内容.我会定时更新.也欢迎您star,issue,共同进步 1.我们服务端渲染数据从何而来 1.1 怎样写出同构的组件 服务端生成HTML结构有时候并不完好.有时 ...

  4. iOS 提交应用到appStore报错ITMS-90xxx

    1.ITMS-90535 解决办法:全局文件搜索info.plist 删除掉报错的第三方中的info.plist,再重新打包,注意不要删除自己项目中的info.plist

  5. C分配struct变量一个不理解的地方

  6. 怎样查看Eclipse是32位还是64位?

    怎样查看Eclipse是32位还是64位? 1.去Eclipse的安装文件夹,找到eclipse.ini 2.打开这个文件.寻找:launcher.library,我的机器上,在第二行 3.查看&qu ...

  7. PHP性能:序——谈ab(Apache Bench)压力测试工具

    PHP性能:序——谈ab(Apache Bench)压力测试工具 ab(Apache  Bench)是啥? ab是Apache自带的一个压力测试软件,可以通过ab命令和选项对某个URL进行压力测试.a ...

  8. Currency Exchange - poj 1860

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22111   Accepted: 7986 Description Seve ...

  9. 【JMeter4.0学习(一)】之FTP性能测试脚本开发,并实现上传下载功能

    参考:<Jmeter常用脚本开发之FTP请求>感谢作者:rosa2015 一.首先,搭建FTP服务器,参考地址:<[FTP]之windows8.1上搭建FTP服务器方法> 二. ...

  10. Windows找出占用端口的进程

    第一步:找出监听指定端口的进程号: C:\> netstat -ao | findstr 443  TCP    0.0.0.0:443            Sean-NotePC:0     ...