unity批量修改AssetBundleName与Variant
批量修改指定路径下的资源的AssetBundleName与Variant。
脚本代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
/// <summary>
/// AlterAssetBundle类为修改批量修改AssetBundle的Name与Variant的编辑器窗口
/// </summary>
public class AlterAssetBundle : EditorWindow
{ [MenuItem("AssetsManager/批量修改AssetBundle")]
static void AddWindow()
{
//创建窗口
AlterAssetBundle window = (AlterAssetBundle)EditorWindow.GetWindow(typeof(AlterAssetBundle), false, "批量修改AssetBundle");
window.Show(); } //输入文字的内容
private string Path = "Assets/Resources/", AssetBundleName="", Variant="";
private bool IsThisName = true; void OnGUI()
{
GUIStyle text_style = new GUIStyle();
text_style.fontSize = ;
text_style.alignment = TextAnchor.MiddleCenter; EditorGUILayout.BeginHorizontal();
GUILayout.Label("默认使用源文件名", GUILayout.MinWidth());
IsThisName = EditorGUILayout.Toggle(IsThisName);
EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal();
GUILayout.Label("AssetBundleName:", GUILayout.MinWidth());
if(IsThisName)
GUILayout.Label("源文件名.unity3d", GUILayout.MinWidth());
else
AssetBundleName = EditorGUILayout.TextField(AssetBundleName.ToLower());
EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal();
GUILayout.Label("Variant:", GUILayout.MinWidth());
Variant = EditorGUILayout.TextField(Variant.ToLower());
EditorGUILayout.EndHorizontal(); GUILayout.Label("\n"); EditorGUILayout.BeginHorizontal();
GUILayout.Label("文件夹路径", GUILayout.MinWidth());
if (GUILayout.Button("浏览", GUILayout.MinWidth())) { OpenFolder(); }
Path = EditorGUILayout.TextField(Path);
EditorGUILayout.EndHorizontal();
if (GUILayout.Button("修改该文件夹下的AssetName及Variant")) { SetSettings(); }
if (GUILayout.Button("清除所有未被引用的AssetName及Variant")) {
AssetDatabase.RemoveUnusedAssetBundleNames();
}
if (GUILayout.Button("清空所有AssetName及Variant"))
{
ClearAssetBundlesName();
}
}
/// <summary>
/// 此函数用来打开文件夹修改路径
/// </summary>
void OpenFolder()
{
string m_path = EditorUtility.OpenFolderPanel("选择文件夹", "", "");
if (!m_path.Contains(Application.dataPath))
{
Debug.LogError("路径应在当前工程目录下");
return;
}
if (m_path.Length != )
{
int firstindex = m_path.IndexOf("Assets");
Path = m_path.Substring(firstindex) + "/";
EditorUtility.FocusProjectWindow();
}
}
/// <summary>
/// 此函数用来修改AssetBundleName与Variant
/// </summary>
void SetSettings()
{
if (Directory.Exists(Path))
{
DirectoryInfo direction = new DirectoryInfo(Path);
FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories); for (int i = ; i < files.Length; i++)
{
if (files[i].Name.EndsWith(".meta"))
{
continue;
}
AssetImporter ai = AssetImporter.GetAtPath(files[i].FullName.Substring(files[i].FullName.IndexOf("Assets")));
if(IsThisName)
ai.SetAssetBundleNameAndVariant(files[i].Name.Replace(".","_")+".unity3d", Variant);
else
ai.SetAssetBundleNameAndVariant(AssetBundleName, Variant);
}
AssetDatabase.Refresh();
}
} /// <summary>
/// 清除之前设置过的AssetBundleName,避免产生不必要的资源也打包
/// 工程中只要设置了AssetBundleName的,都会进行打包
/// </summary>
static void ClearAssetBundlesName()
{
int length = AssetDatabase.GetAllAssetBundleNames().Length;
string[] oldAssetBundleNames = new string[length];
for (int i = ; i < length; i++)
{
oldAssetBundleNames[i] = AssetDatabase.GetAllAssetBundleNames()[i];
} for (int j = ; j < oldAssetBundleNames.Length; j++)
{
AssetDatabase.RemoveAssetBundleName(oldAssetBundleNames[j], true);
}
}
void OnInspectorUpdate()
{
this.Repaint();//窗口的重绘
}
}
AlterAssetBundle
unity批量修改AssetBundleName与Variant的更多相关文章
- [Unity工具]批量修改字体
效果图: using System.IO; using System.Text; using UnityEditor; using UnityEngine; using UnityEngine.UI; ...
- Unity3D Editor模式下批量修改prefab
最经遇到一个需要批量修改已经做好的prefab的问题,查了一些资料最终实现了但是还是不够完美,通过学习也发现unity的编辑器功能还是非常强大的.废话不多说直接上代码: [ExecuteInEditM ...
- Excel VBA批量修改文件夹下的文件名
今天,有同事提出想批量修改文件名,规则比较简单,在第五位后加“-”即可, 上网没找到相关工具,就自己做了个excel,用宏代码修改. 代码如下: Private Sub CommandButton1_ ...
- mac linux rename命令行批量修改文件名
我的mac使用命令行批量修改名字时发现居然没有rename的指令: zsh: command not found: rename 所以使用HomeBrew先安装一下: ➜ ~ brew install ...
- MYSQL批量修改表前缀与表名sql语句
修改表名 ALTER TABLE 原表名 RENAME TO 新表名; 一句SQL语句只能修改一张表 show tables; 1. SELECT CONCAT( 'ALTER TABLE ', ta ...
- 使用powershell批量修改文本为utf8
根据上一篇powershell生成pro的方法,增加一个批量修改文本文件为utf8格式的方法 $incPath = dir -filter "*.c" -Recurse $temp ...
- nodejs 批量修改、删除
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAQhCAIAAABDaAVHAAAgAElEQVR4nOydeXxU5aH359733vd9b/ ...
- iOS --- DIY文件名批量修改
批量修改文件名: // 1.创建文件管理 NSFileManager *filemanager =[NSFileManager defaultManager]; // 2. 获得所有文件夹路径 NSS ...
- ansible非root用户批量修改root密码
前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...
随机推荐
- DATASNAP数据序列之FIREDAC的TFDJSONDataSets
DATASNAP数据序列之FIREDAC的TFDJSONDataSets DELPHI XE5开始增加了新的数据引擎——FIREDAC,它是跨平台的数据引擎,WINDOWS.LINUX.MAC.APP ...
- django模板解析 循环列表中 切片和求长度
{% for subrow in subdic.content|slice:":5" %} {% endfor %} {% if "{{subdic.content|le ...
- 为什么重写equals方法时,要求必须重写hashCode方法?
1 equals方法 Object类中默认的实现方式是 : return this == obj .那就是说,只有this 和 obj引用同一个对象,才会返回true. 而我们往往需要用equ ...
- zabbix agent被动模式配置
zabbix agent检测分为主动(agent active)和被动(agent)两种形式,主动与被动的说法均是相对于agent来讨论的.简单说明一下主动与被动的区别如下: 主动:agent请求se ...
- AndroidStudio短信验证功能收不到验证码
http://mob.com/第三方接口获取地址: 登陆过后点我的后台即可上传,管理应用.需注意的是,即使验证不通过,只要整合了短信验证的Jar包,每天都有20条免费验证短信.现在的mob.com只支 ...
- 如何安装Android SDK Emulator
1 下载并安装JDK,可以到官方网站寻找自己的对应版本下载 http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u1-downlo ...
- NodeJS中的循环陷阱
Node.js的异步机制由事件和回调函数实现,一開始接触可能会感觉违反常规,但习惯以后就会发现还是非常easy的. 然而这之中事实上暗藏不少陷阱.一个非常easy遇到的问题就是回到循环的回调函数. e ...
- Asp.net Mvc使用PagedList分页
git:https://github.com/troygoode/PagedList 1. Nuget 安装package watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...
- Php函数之end
Php函数之end end()函数 (PHP 4, PHP 5, PHP 7) end - 将数组的内部指针指向最后一个单元 说明 mixed end ( array &$array ) en ...
- 初探J2EE
还记得在技术交流会上八期给我们讲的J2EE,当时就是云里来屋里去.留在自己脑子中的仅仅有两个字"规范",其他的真是一无全部. 可是如今学了后,又在脑子里留下了两个字"规范 ...