通过代码设置资源名字,为打包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 ...
随机推荐
- SlidingMenu+Fragment实现当前最流行的侧滑
1 http://www.krislq.com/2013/03/android_case_slidingmenu_fragment/ 2 https://github.com/jfeinstein10 ...
- JS 手势长按代码
同时支持长按和点击事件,无依赖版 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- cxf + spring + maven 开发webservice
1.maven 配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://ww ...
- Spigot 算法之中的一个 计算调和级数的和
我是首先在[1] 注意到 Spigot-Algorithm的,这个算法公布的相当早.见[2]. [1] 给出几个令人惊异的程序.仅仅用非常少的代码就能够计算e,pi,log(2)等常数. 当中 ...
- linux 中vim学习与总结
平常使用vim总是忘记快捷键,在这里做一个总结一下比较常用的快捷把,省的每次都要去查. h : 向左移动一个字符(←) j : 向上移动一个字符(↑) k : (↓) l : (→) ctrl+f : ...
- 微服务网关哪家强?一文看懂Zuul, Nginx, Spring Cloud, Linkerd性能差异
导语:API Gateway是实现微服务重要的组件之一.面对诸多的开源API Gateway,如何进行选择也是架构师需要关注的焦点.本文作者对几个较大的开源API Gateway进行了压力测试,对 ...
- 01 Memcached 安装与介绍
一:Memcached 介绍 ()官网网址:www.mamcached.org () 主要功能是:高性能,分布式的内存对象缓存系统. ()Nosql不仅仅是关系型数据库,显著特点key value ...
- 从零开始学android -- 简易的socket通信
先来介绍下socket,网上摘抄点资料,免得自己打字了 网络中进程之间如何通信? 本地的进程间通信(IPC)有很多种方式,但可以总结为下面4类: 1.消息传递(管道.FIFO.消息队列) 2.同步(互 ...
- Python 内建的filter()函数用于过滤序列。
例如,在一个list中,删掉偶数,只保留奇数,可以这么写: def is_odd(n): return n % 2 == 1 list(filter(is_odd, [1, 2, 4, 5, 6, 9 ...
- lumen手记:自定义Validate表单验证
版权声明:本文为博主原创文章,未经博主允许不得转载. 今天开始跳lumen的表单验证Validate类的坑,确实好坑!!! 首先,lumen的表单验证返回是无状态的json格式api,这... 所有开 ...