AssetBundle自动标签、打包
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
/// <summary>
/// asset bundle 编辑
/// </summary>
public class AssetBundleEditor
{
#region 自动做标记
[MenuItem("Asset Bundle/Set Lable")]
public static void SetAssetBundleLable()
{
//移除所有没有使用的AB名
AssetDatabase.RemoveUnusedAssetBundleNames();
//资源总路径
string assetDriectory = "E:/Work/Jobs/Empty/EmptyProject/Assets/Res";
//遍历所有文件夹
DirectoryInfo directoryInfo = new DirectoryInfo(assetDriectory);
DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();
foreach (DirectoryInfo info in directoryInfos)
{
string sceneDirectory = assetDriectory + "/" + info.Name;
DirectoryInfo sceneDirectoryInfo = new DirectoryInfo(sceneDirectory);
if (sceneDirectoryInfo == null)
{
Debug.LogError(sceneDirectory + "不存在");
return;
}
else
{
Dictionary<string,string> namePath = new Dictionary<string, string>();
int index = sceneDirectory.LastIndexOf("/");
string sceneName = sceneDirectory.Substring(index + 1);
OnSceneFileSystemInfo(sceneDirectoryInfo, sceneName, namePath);
WirteConfig(sceneName, namePath);
}
}
AssetDatabase.Refresh();
Debug.Log("名字设置完成");
}
/// <summary>
/// 写入路径的配置文件
/// </summary>
/// <param name="sceneDic"></param>
/// <param name="namePathDic"></param>
private static void WirteConfig(string sceneName, Dictionary<string, string> namePathDic)
{
string path = PathUtil.GetAssetBundleOutPath() + "/" + sceneName + "Record.txt";
using (FileStream fs = new FileStream(path,FileMode.OpenOrCreate,FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine(namePathDic.Count);
foreach (KeyValuePair<string, string> pair in namePathDic)
{
sw.WriteLine(pair.Key + " " + pair.Value);
}
}
}
}
/// <summary>
/// 遍历资源文件夹里的场景文件
/// </summary>
/// <param name="info">场景文件夹</param>
/// <param name="sceneName">场景文件夹名</param>
private static void OnSceneFileSystemInfo(FileSystemInfo info, string sceneName, Dictionary<string, string> namePath)
{
if (!info.Exists)
{
Debug.LogError(info.FullName + "不存在");
return;
}
DirectoryInfo directoryInfo = info as DirectoryInfo;
FileSystemInfo[] fileSystemInfos = directoryInfo.GetFileSystemInfos();
foreach (FileSystemInfo systemInfo in fileSystemInfos)
{
FileInfo fileInfo = systemInfo as FileInfo;
if (fileInfo == null)
{
//如果强转失败,则表示这是个文件夹,不是文件,继续遍历
OnSceneFileSystemInfo(systemInfo, sceneName, namePath);
}
else
{
//设置文件的label
SetLabels(fileInfo, sceneName, namePath);
}
}
}
/// <summary>
/// 修改文件的AB名
/// </summary>
/// <param name="fileInfo">修改的文件</param>
/// <param name="sceneName">场景名</param>
private static void SetLabels(FileInfo fileInfo, string sceneName, Dictionary<string, string> namePath)
{
if (fileInfo.Extension == ".meta") return;
string bundleName = GetBundleName(fileInfo, sceneName);
int index = fileInfo.FullName.IndexOf("Assets");
string assetPath = fileInfo.FullName.Substring(index);
//修改Label类
AssetImporter assetImporter = AssetImporter.GetAtPath(assetPath);
assetImporter.assetBundleName = bundleName.ToLower();
assetImporter.assetBundleVariant = fileInfo.Extension == ".unity" ? "u3d" : "assetbundle";
string folderName = bundleName.Contains("/") ? bundleName.Split('/')[1] : bundleName.Split('/')[0];
string bundlePath = assetImporter.assetBundleName + "." + assetImporter.assetBundleVariant;
//增加字典
if (!namePath.ContainsKey(bundleName))
namePath.Add(folderName, bundlePath);
}
/// <summary>
/// 获取要打包的资源名
/// </summary>
private static string GetBundleName(FileInfo fileInfo, string sceneName)
{
string winPath = fileInfo.FullName;
string unityPath = winPath.Replace(@"\", "/"); //字符转换
int index = unityPath.IndexOf(sceneName) + sceneName.Length;
string bundlePath = unityPath.Substring(index + 1);
if (bundlePath.Contains("/"))
{
string[] tmpStrings = bundlePath.Split('/');
return sceneName + "/" + tmpStrings[0];
}
else
{
//这个是场景
return sceneName;
}
}
#endregion
#region 打包
[MenuItem("Asset Bundle/Asset Bundle")]
public static void BuildAssetBundle()
{
string outPath = PathUtil.GetAssetBundleOutPath();
BuildPipeline.BuildAssetBundles(outPath, 0, BuildTarget.StandaloneWindows64);
}
#endregion
#region 删除打包好的AB资源
[MenuItem("Asset Bundle/Delet Asset Bundle")]
public static void DeletAssetBundle()
{
string outPath = PathUtil.GetAssetBundleOutPath();
Directory.Delete(outPath,true);
File.Delete(outPath + ".meta");
AssetDatabase.Refresh();
}
#endregion
}
AssetBundle自动标签、打包的更多相关文章
- JSP自定义标签/自定义标签打包
有这样一个业务需求: 当我们在编辑某个用户时,需要设置该用户的角色,在转到编辑页面时,就需要自动勾选上该用户已经选择的角色,如下图: 当我们点击编辑时,会查询用户详细信息,以及角色集合传到编辑页面. ...
- Wix 安装部署(一)同MSBuild 自动生成打包文件
因为项目需要,最近在研究Wix打包部署,园子里也有一些关于wix的博客,方方面面,讲的点各不同.我自己也在测试过程中,写下过程,以供参考.最新版本WiX Toolset v3.7,如何安装的就不说了, ...
- Ant自动编译打包&发布 android项目
Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我们自动编译打包了. ...
- Wix 安装部署(一)同MSBuild 自动生成打包文件 转
原文地址:http://www.cnblogs.com/stoneniqiu/p/3355086.html 因为项目需要,最近在研究Wix打包部署,园子里也有一些关于wix的博客,方方面面,讲的点各不 ...
- Android-Ant自动编译打包android项目 -- 2 ----签名与渠道包
上篇介绍了怎么使用ant自动编译打包现有的android项目,这篇将继续介绍如果如何在ant打包应用的时候加入签名信息以及自动打包渠道包. 1. 加入签名信息: 在项目的根目录下建一个ant.prop ...
- Android - Ant自动编译打包android项目 -- 1(转)
1. 背景: Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其当要将应用打包发布到各个渠道时,用Eclipse手动打包各种渠道包就有点不切实际了,这时候我们用到Ant帮我 ...
- 设置 Nuget 本地源、在线私有源、自动构建打包
设置 Nuget 本地源.在线私有源.自动构建打包 本文演示如果在项目中生成 Nuget 包,并添加 Nuget 本地源,不用发布到 Nuget 服务器.再附带使用在线私有源的简单方法,以及提交代码自 ...
- Andorid进阶7—— Ant自动编译打包&发布 android项目
http://www.cnblogs.com/tt_mc/p/3891546.html Eclipse用起来虽然方便,但是编译打包android项目还是比较慢,尤其将应用打包发布到各个渠道时,用Ecl ...
- Ant自动编译打包android项目(转载)
1.1 Ant安装 ant的安装比较简单,下载ant压缩包 http://ant.apache.org (最新的为1.9.3版本),下载之后将其解压到某个目录(本人解压到E:\Progra ...
随机推荐
- Python实现一条基于POS算法的区块链
区块链中的共识算法 在比特币公链架构解析中,就曾提到过为了实现去中介化的设计,比特币设计了一套共识协议,并通过此协议来保证系统的稳定性和防攻击性. 并且我们知道,截止目前使用最广泛,也是最被大家接受的 ...
- 【洛谷p1258】小车问题
(……吓人,心有余悸) 小车问题[传送门] 洛谷算法标签:: (行吧它居然是个二分[解方程的我抖抖发瑟]) 作为一个写了一页演草纸才解出来的方程,显然我要好好写一写(希望不会半途而废) 思路: 先把其 ...
- Bipartite Segments CodeForces - 901C (区间二分图计数)
大意: 给定无向图, 无偶环, 每次询问求[l,r]区间内, 有多少子区间是二分图. 无偶环等价于奇环仙人掌森林, 可以直接tarjan求出所有环, 然后就可以预处理出每个点为右端点时的答案. 这样的 ...
- mac终端下连接阿里云服务器
通过ssh连接 ssh 用户名@地址 ssh root@xx.xxx.xxx.xx https://www.jianshu.com/p/f034817a7837 最后还是通过 FileZilla 连 ...
- java面试之谈
半个多月的找工作时间,不是在去面试路上,就是在面试中,经历了大概有近10家的面试,虽然很多家都是一回了无音讯,对自己收获还是有的,至少让自己认识到了自身基础不牢固和技术知识面的狭隘.之前从事的工作主要 ...
- bzoj-2038-莫队
2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 15784 Solved: 7164[Sub ...
- Leetcode 1004. 最大连续1的个数 III
1004. 最大连续1的个数 III 显示英文描述 我的提交返回竞赛 用户通过次数97 用户尝试次数143 通过次数102 提交次数299 题目难度Medium 给定一个由若干 0 和 1 组成 ...
- Oracle 11.2.0.4.0 Dataguard部署和日常维护(3)-Datauard监控篇
1. v$database 查看当前数据库的角色和保护模式 primary库查看 column NAME format a10 column PROTECTION_MODE format a2 ...
- [NOIP 2015TG D1T3] 斗地主
题目描述 牛牛最近迷上了一种叫斗地主的扑克游戏.斗地主是一种使用黑桃.红心.梅花.方片的A到K加上大小王的共54张牌来进行的扑克牌游戏.在斗地主中,牌的大小关系根据牌的数码表示如下:3<4< ...
- 码云git使用一(上传本地项目到码云git服务器上)
主要讲下如果将项目部署到码云git服务器上,然后使用studio导入git项目,修改本地代码后,并同步到码云git上面. 首先:我们在码云上注册账号并登陆.官网(https://git.oschina ...