批量修改指定路径下的资源的AssetBundleName与Variant。

脚本代码如下:

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System.IO;
  6. /// <summary>
  7. /// AlterAssetBundle类为修改批量修改AssetBundle的Name与Variant的编辑器窗口
  8. /// </summary>
  9. public class AlterAssetBundle : EditorWindow
  10. {
  11.  
  12. [MenuItem("AssetsManager/批量修改AssetBundle")]
  13. static void AddWindow()
  14. {
  15. //创建窗口
  16. AlterAssetBundle window = (AlterAssetBundle)EditorWindow.GetWindow(typeof(AlterAssetBundle), false, "批量修改AssetBundle");
  17. window.Show();
  18.  
  19. }
  20.  
  21. //输入文字的内容
  22. private string Path = "Assets/Resources/", AssetBundleName="", Variant="";
  23. private bool IsThisName = true;
  24.  
  25. void OnGUI()
  26. {
  27. GUIStyle text_style = new GUIStyle();
  28. text_style.fontSize = ;
  29. text_style.alignment = TextAnchor.MiddleCenter;
  30.  
  31. EditorGUILayout.BeginHorizontal();
  32. GUILayout.Label("默认使用源文件名", GUILayout.MinWidth());
  33. IsThisName = EditorGUILayout.Toggle(IsThisName);
  34. EditorGUILayout.EndHorizontal();
  35.  
  36. EditorGUILayout.BeginHorizontal();
  37. GUILayout.Label("AssetBundleName:", GUILayout.MinWidth());
  38. if(IsThisName)
  39. GUILayout.Label("源文件名.unity3d", GUILayout.MinWidth());
  40. else
  41. AssetBundleName = EditorGUILayout.TextField(AssetBundleName.ToLower());
  42. EditorGUILayout.EndHorizontal();
  43.  
  44. EditorGUILayout.BeginHorizontal();
  45. GUILayout.Label("Variant:", GUILayout.MinWidth());
  46. Variant = EditorGUILayout.TextField(Variant.ToLower());
  47. EditorGUILayout.EndHorizontal();
  48.  
  49. GUILayout.Label("\n");
  50.  
  51. EditorGUILayout.BeginHorizontal();
  52. GUILayout.Label("文件夹路径", GUILayout.MinWidth());
  53. if (GUILayout.Button("浏览", GUILayout.MinWidth())) { OpenFolder(); }
  54. Path = EditorGUILayout.TextField(Path);
  55. EditorGUILayout.EndHorizontal();
  56. if (GUILayout.Button("修改该文件夹下的AssetName及Variant")) { SetSettings(); }
  57. if (GUILayout.Button("清除所有未被引用的AssetName及Variant")) {
  58. AssetDatabase.RemoveUnusedAssetBundleNames();
  59. }
  60. if (GUILayout.Button("清空所有AssetName及Variant"))
  61. {
  62. ClearAssetBundlesName();
  63. }
  64. }
  65. /// <summary>
  66. /// 此函数用来打开文件夹修改路径
  67. /// </summary>
  68. void OpenFolder()
  69. {
  70. string m_path = EditorUtility.OpenFolderPanel("选择文件夹", "", "");
  71. if (!m_path.Contains(Application.dataPath))
  72. {
  73. Debug.LogError("路径应在当前工程目录下");
  74. return;
  75. }
  76. if (m_path.Length != )
  77. {
  78. int firstindex = m_path.IndexOf("Assets");
  79. Path = m_path.Substring(firstindex) + "/";
  80. EditorUtility.FocusProjectWindow();
  81. }
  82. }
  83. /// <summary>
  84. /// 此函数用来修改AssetBundleName与Variant
  85. /// </summary>
  86. void SetSettings()
  87. {
  88. if (Directory.Exists(Path))
  89. {
  90. DirectoryInfo direction = new DirectoryInfo(Path);
  91. FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories);
  92.  
  93. for (int i = ; i < files.Length; i++)
  94. {
  95. if (files[i].Name.EndsWith(".meta"))
  96. {
  97. continue;
  98. }
  99. AssetImporter ai = AssetImporter.GetAtPath(files[i].FullName.Substring(files[i].FullName.IndexOf("Assets")));
  100. if(IsThisName)
  101. ai.SetAssetBundleNameAndVariant(files[i].Name.Replace(".","_")+".unity3d", Variant);
  102. else
  103. ai.SetAssetBundleNameAndVariant(AssetBundleName, Variant);
  104. }
  105. AssetDatabase.Refresh();
  106. }
  107. }
  108.  
  109. /// <summary>
  110. /// 清除之前设置过的AssetBundleName,避免产生不必要的资源也打包
  111. /// 工程中只要设置了AssetBundleName的,都会进行打包
  112. /// </summary>
  113. static void ClearAssetBundlesName()
  114. {
  115. int length = AssetDatabase.GetAllAssetBundleNames().Length;
  116. string[] oldAssetBundleNames = new string[length];
  117. for (int i = ; i < length; i++)
  118. {
  119. oldAssetBundleNames[i] = AssetDatabase.GetAllAssetBundleNames()[i];
  120. }
  121.  
  122. for (int j = ; j < oldAssetBundleNames.Length; j++)
  123. {
  124. AssetDatabase.RemoveAssetBundleName(oldAssetBundleNames[j], true);
  125. }
  126. }
  127. void OnInspectorUpdate()
  128. {
  129. this.Repaint();//窗口的重绘
  130. }
  131. }

AlterAssetBundle

unity批量修改AssetBundleName与Variant的更多相关文章

  1. [Unity工具]批量修改字体

    效果图: using System.IO; using System.Text; using UnityEditor; using UnityEngine; using UnityEngine.UI; ...

  2. Unity3D Editor模式下批量修改prefab

    最经遇到一个需要批量修改已经做好的prefab的问题,查了一些资料最终实现了但是还是不够完美,通过学习也发现unity的编辑器功能还是非常强大的.废话不多说直接上代码: [ExecuteInEditM ...

  3. Excel VBA批量修改文件夹下的文件名

    今天,有同事提出想批量修改文件名,规则比较简单,在第五位后加“-”即可, 上网没找到相关工具,就自己做了个excel,用宏代码修改. 代码如下: Private Sub CommandButton1_ ...

  4. mac linux rename命令行批量修改文件名

    我的mac使用命令行批量修改名字时发现居然没有rename的指令: zsh: command not found: rename 所以使用HomeBrew先安装一下: ➜ ~ brew install ...

  5. MYSQL批量修改表前缀与表名sql语句

    修改表名 ALTER TABLE 原表名 RENAME TO 新表名; 一句SQL语句只能修改一张表 show tables; 1. SELECT CONCAT( 'ALTER TABLE ', ta ...

  6. 使用powershell批量修改文本为utf8

    根据上一篇powershell生成pro的方法,增加一个批量修改文本文件为utf8格式的方法 $incPath = dir -filter "*.c" -Recurse $temp ...

  7. nodejs 批量修改、删除

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAQhCAIAAABDaAVHAAAgAElEQVR4nOydeXxU5aH359733vd9b/ ...

  8. iOS --- DIY文件名批量修改

    批量修改文件名: // 1.创建文件管理 NSFileManager *filemanager =[NSFileManager defaultManager]; // 2. 获得所有文件夹路径 NSS ...

  9. ansible非root用户批量修改root密码

    前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...

随机推荐

  1. IE8下 input标签内padding失效

    在做网页兼容时 发现在ie8下的input内用padding失效 为了达到居中文字的效果 使用line-height可以解决问题

  2. Oracle ORA-01033: 错误解决办法

    转自 Oracle ORA-01033: 错误解决办法

  3. java随机生成汉字

    public static void main(String[] args) { String str = null; int hs, ls; Random random = new Random() ...

  4. 手把手教你AndroidStudio多渠道打包

    最近不断有朋友向我咨询AndroidStudio多渠道的打包方法,今天整理一下之前积累的打包套路,写一篇文章,手把手的教给大家.        说到多渠道,这里不得不提一下友盟统计,友盟统计是大家日常 ...

  5. win10 创建安卓模拟器及启动的方法

    一打开 安卓 studio 然后点击AVD manager 创建一个模拟器 二 通过命令行快速启动模拟器 D:\Android\sdk\tools\emulator.exe -netdelay non ...

  6. Java的身份证号码工具类

    /** * Copyright (C) 2009-2010 Yichuan, Fuchun All rights reserved. * Licensed to the Apache Software ...

  7. HTML5游戏实战(1):50行代码实现正面跑酷游戏

    前段时间看到一个"熊来了"的HTML5跑酷游戏,它是一个典型的正面2D跑酷游戏,这里借用它来介绍一下用Gamebuilder+CanTK开发正面跑酷游戏的基本方法. CanTK(C ...

  8. [GraphQL] Query a GraphQL API with graphql-request

    To query a GraphQL API, all you need to do is send an HTTP request that includes the query operation ...

  9. 使用theHarvester 进行邮箱和子域名的收集

    下载地址:https://github.com/laramies/theHarvester 先要安装python的 reqeusts 库 安装pip install reqeustsmail -d b ...

  10. Cache和Buffer的区别(转载)

    1. Cache:缓存区,是高速缓存,是位于CPU和主内存之间的容量较小但速度很快的存储器,因为CPU的速度远远高于主内存的速度,CPU从内存中读取数据需等待很长的时间,而  Cache保存着CPU刚 ...