Unity5自动命名Assetbundle并打包
http://www.shihuanjue.com/?p=57
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO; /// <summary>
/// 把Resource下的资源打包成.unity3d 到StreamingAssets目录下
/// </summary>
public class Builder : Editor
{
public static string sourcePath = Application.dataPath + "/Resources";
const string AssetBundlesOutputPath = "Assets/StreamingAssets"; [MenuItem("Tools/AssetBundle/Build")]
public static void BuildAssetBundle()
{
ClearAssetBundlesName (); Pack (sourcePath); string outputPath = Path.Combine (AssetBundlesOutputPath,Platform.GetPlatformFolder(EditorUserBuildSettings.activeBuildTarget));
if (!Directory.Exists (outputPath))
{
Directory.CreateDirectory(outputPath);
} //根据BuildSetting里面所激活的平台进行打包
BuildPipeline.BuildAssetBundles (outputPath,0,EditorUserBuildSettings.activeBuildTarget); AssetDatabase.Refresh (); Debug.Log ("打包完成"); } /// <summary>
/// 清除之前设置过的AssetBundleName,避免产生不必要的资源也打包
/// 之前说过,只要设置了AssetBundleName的,都会进行打包,不论在什么目录下
/// </summary>
static void ClearAssetBundlesName()
{
int length = AssetDatabase.GetAllAssetBundleNames ().Length;
Debug.Log (length);
string[] oldAssetBundleNames = new string[length];
for (int i = 0; i < length; i++)
{
oldAssetBundleNames[i] = AssetDatabase.GetAllAssetBundleNames()[i];
} for (int j = 0; j < oldAssetBundleNames.Length; j++)
{
AssetDatabase.RemoveAssetBundleName(oldAssetBundleNames[j],true);
}
length = AssetDatabase.GetAllAssetBundleNames ().Length;
Debug.Log (length);
} static void Pack(string source)
{
DirectoryInfo folder = new DirectoryInfo (source);
FileSystemInfo[] files = folder.GetFileSystemInfos ();
int length = files.Length;
for (int i = 0; i < length; i++) {
if(files[i] is DirectoryInfo)
{
Pack(files[i].FullName);
}
else
{
if(!files[i].Name.EndsWith(".meta"))
{
file (files[i].FullName);
}
}
}
} static void file(string source)
{
string _source = Replace (source);
string _assetPath = "Assets" + _source.Substring (Application.dataPath.Length);
string _assetPath2 = _source.Substring (Application.dataPath.Length + 1);
//Debug.Log (_assetPath); //在代码中给资源设置AssetBundleName
AssetImporter assetImporter = AssetImporter.GetAtPath (_assetPath);
string assetName = _assetPath2.Substring (_assetPath2.IndexOf("/") + 1);
assetName = assetName.Replace(Path.GetExtension(assetName),".unity3d");
//Debug.Log (assetName);
assetImporter.assetBundleName = assetName;
} static string Replace(string s)
{
return s.Replace("\\","/");
}
} public class Platform
{
public static string GetPlatformFolder(BuildTarget target)
{
switch (target)
{
case BuildTarget.Android:
return "Android";
case BuildTarget.iOS:
return "IOS";
case BuildTarget.WebPlayer:
return "WebPlayer";
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64:
return "Windows";
case BuildTarget.StandaloneOSXIntel:
case BuildTarget.StandaloneOSXIntel64:
case BuildTarget.StandaloneOSXUniversal:
return "OSX";
default:
return null;
}
}
}
Unity5自动命名Assetbundle并打包的更多相关文章
- Unity5.4新版AssetBundle资源打包
(1)新版本 唯一打包API Buildpipeline.BuildAssetBundle (2)在资源的Inpector界面最下方可设置该资源的assetbundleName, 每个assetbun ...
- Unity5.X 新版AssetBundle打包控制
一.什么是AssetBundle 估计很多人只知道Unity的模型之类的东西可以导出成一种叫做AssetBundle的文件,然后打包后可以在Unity程序运行的时候再加载出来用.那么AssetBund ...
- Unity5.x版本AssetBundle加载研究
之前说了 “Unity5.x版本AssetBundle打包研究”,没看过的请先看一下:http://www.shihuanjue.com/?p=57 再来看本文,有一定的连接性. 先梳理一下思路: 要 ...
- AssetBundle资源打包与加载
AssetBundle资源打包 1.AssetLabels资源标签 文件名:资源打包成AssetBundle后的文件名,类似于压缩包的名字 后缀:自定义 文件名和后缀名都是小写格式(大写会自动转为小 ...
- Unity5系列资源管理AssetBundle——更新实现
前面我们研究了AssetBundle的打包与加载,现在我们来了解下如何在项目中根据版本号更新内容. 最最重要的一点,细心的朋友应该看到了在加载AssetBundle的MrcAssetManager类中 ...
- 使用 maven 自动将源码打包并发布
1.maven-source-plugin 访问地址 在 pom.xml 中添加 下面的 内容,可以 使用 maven 生成 jar 的同时 生成 sources 包 <plugin> & ...
- Unity5.x版本AssetBundle打包研究
Unity5的AssetBundle打包机制和以前版本不太一样.简单的说就是,只要给你要打包的资源设置一个AssetBundleName ,Unity自身会对这些设置了名字的资源进行打包,如果一个资源 ...
- Unity5版本的AssetBundle打包方案之打包Scene场景
using UnityEngine; using System.Collections; using UnityEditor; /// <summary> /// 脚本位置:Editor文 ...
- Unity5系列资源管理AssetBundle——打包
资源管理是游戏开发的重要环节,Unity中使用AssetBundle可以非常方便地帮我们打包和更新游戏内容,在5系列中,AssetBundle更是方便好用,现在让我们先进行打包吧. 刚说了,5系列打包 ...
随机推荐
- jquery动态加载脚本
如果你使用的是jQuery,它里面有一个内置的方法可以用来加载单个JS文件.当你需要延迟加载一些js插件或其它类型的文件时,可以使用这个方法. 一.jQuery getScript()方法加载java ...
- 前端基础——CSS盒子模型
如今很多网页都是由很多个"盒子"拼接.嵌套而成,所以多少接触过网页设计的朋友一定都对CSS盒子模型有所了解. 为了更好的说明,先举个通俗的样例:在一个仓库中放了10个纸箱,每一个纸 ...
- [Phoenix] 二、数据类型
目前Phoenix支持24种简单数据类型和1个一维Array的复杂类型.以下是对支持数据类型的说明: 1. INTEGER 2. UNSIGNED_INT 3. BIGINT 4. UNSIGNED_ ...
- html5 file 上传图片
说明:开发环境 vs2012 mvc4项目,后台语言csharp 1.前端代码 <html xmlns="http://www.w3.org/1999/xhtml"> ...
- Mac终端基本指令,一些实用命令的收集.
基本命令1.列出文件ls 参数 目录名 例: 看看驱动目录下有什么:ls /System/Library/Extensions参数 -w 显示中文,-l 详细信息, -a 包括隐藏文件 ...
- SpringSecurityLDap
ldap,用于用户登录的权限管理, 可参考:http://www.cnblogs.com/icuit/archive/2010/06/10/1755575.html
- CORS 理解(不要那么多术语)
摘要 谈到跨域,不论前端还是后端,多少有点谈虎色变,面试中也常会问到这些问题,浏览器和服务器端到底怎么做才能跨域,他们都做了什么? 同源 vs 跨域 同源,字面意义是相同的源头,即同一个web服务器( ...
- NOIP2015_提高组Day2_3_运输计划
这题思路很简单: 先对每个询问求距离,对距离由大到小排序, 二分最小距离,验证是否可行,验证时用差分处理: #include<iostream> #include<cstring&g ...
- 编写按键驱动以及在framework层上报按键事件
平台信息:内核:linux3.10 系统:android6.0平台:RK3288 前言:本文主要实现的功能是在android系统中添加一个按键,在驱动层使用定时器,每隔1秒钟向上层发送按键实现,fra ...
- 很好的 DHCP协议与dhcpcd分析【转】
本文转载自:http://blog.csdn.net/gjsisi/article/details/18052369 第一部分 DHCP工作过程 DHCP的工作过程主要分为以下六个阶段: 发现 ...