Windows 的文件系统对文件名大小写是不区分的,小写文件名 和 大写文件名 代表的是同一个文件。
今天在打包 Assetbundle 的时候,发现打包出来的图集 缺了很多图片,测试了一下才发现是 Packing Tag 设置,有些图片是大写的 Packing Tag,有些是小写的。
如果小写的图片后打包,就会覆盖掉 大写的,大写 Packing Tag的图集就丢了。
如果项目刚开始做,我还是建议让代码自动设置图片的 Packing Tag。参照之前写的代码。
Unity3d 导入图片 自动修改Texture Type为Sprite (2D and UI) 及设置 Packing Tag为文件夹名
那么对于老项目,总的想个办法去把这些 Packing Tag设置错误的问题找出来并修改。
我写了个代码来进行这项工作。
转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
/************************** * 文件名:FindDifferentCasePackingTag.cs; * 文件描述:查找相同字符但是大小写不同的PackingTag; * 创建日期:2016/05/30; * Author:ThisisGame; * Page:https://github.com/ThisisGame/FindDifferentCasePackingTag ***************************/ using UnityEngine; using System.Collections; using UnityEditor; using System.Collections.Generic; namespace ThisisGame { public class FindDifferentCasePackingTag { [MenuItem("Assets/FindSameLowerUpperPackingTag")] public static void FindErrorPackingTag() { //PackingTags List<string> packingTags = new List<string>(); //PackingTag -- 文件列表 Dictionary<string, List<string>> imagePackingTags = new Dictionary<string, List<string>>(); UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets); for (int index = 0; index < arr.Length; index++) { string filePath = AssetDatabase.GetAssetPath(arr[index]); //Debug.Log(filePath); Sprite sprite = Resources.LoadAssetAtPath<Sprite>(filePath); if (sprite == null) continue; TextureImporter ti = AssetImporter.GetAtPath(filePath) as TextureImporter; if (ti.spritePackingTag.Trim() != string.Empty) { if (!imagePackingTags.ContainsKey(ti.spritePackingTag)) { imagePackingTags.Add(ti.spritePackingTag, new List<string>()); } imagePackingTags[ti.spritePackingTag].Add(filePath); } } //找出存在大小写字母的PackingTag foreach (var info in imagePackingTags) { packingTags.Add(info.Key); } for (int i = 0; i < packingTags.Count; i++) { if (packingTags[i] == string.Empty) continue; for (int j = 0; j < packingTags.Count; j++) { if (packingTags[j] == string.Empty) continue; if (packingTags[j] != packingTags[i] && packingTags[j].ToLower() == packingTags[i].ToLower()) { List<string> listA = imagePackingTags[packingTags[i]]; List<string> listB = imagePackingTags[packingTags[j]]; for (int indexA = 0; indexA < listA.Count; indexA++) { Debug.Log(packingTags[i] + " : " + listA[indexA]); } for (int indexB = 0; indexB < listB.Count; indexB++) { Debug.LogError(packingTags[j] + " : " + listB[indexB]); } } } packingTags[i] = string.Empty; } } } }
使用方式,在图片总目录上右键点击 FindDifferentCasePackingTag
使用结果
代码下载
https://github.com/ThisisGame/FindDifferentCasePackingTag