void SetPackingTag(List <string> keys) { int index = 0; TextureImporter t = null; EditorApplication.update = delegate() { Item item = guid2Pics[keys[index]]; string file = item.filePath; file = FindRefrence.GetRelativeAssetsPath(file); bool isCancel = EditorUtility.DisplayCancelableProgressBar ("设置packing tag", file, (float)index / (float)keys.Count); t = AssetImporter.GetAtPath(file) as TextureImporter; if (t != null && (item.CurTag != item.CreateTag)) { //非Texture模式 t.spritePackingTag = item.CreateTag; t.SaveAndReimport(); } index++; if (isCancel || index >= keys.Count) { EditorUtility.ClearProgressBar(); EditorApplication.update = null; index = 0; Debug.Log("匹配结束"); //清空当前的tag,让它自己再读一遍 this.Repaint(); } }; }
void ReadAllImageFiles() { List <string> picExt = new List <string>() { ".png", ".jpg" }; string path = EditorUtility.OpenFolderPanel("选择要检索的文件夹", Application.dataPath + "/JJYDeZhou/BuildResource/Atlas", ""); string[] allPics = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories) .Where(s => picExt.Contains(Path.GetExtension(s).ToLower())).ToArray(); for (int i = 0; i < allPics.Length; i++) { string guid = AssetDatabase.AssetPathToGUID(FindRefrence.GetRelativeAssetsPath(allPics[i])); if (guid2Pics.ContainsKey(guid)) { Debug.LogError(guid + " allPics[i]:" + allPics[i]); } else { Item temp = new Item(); temp.guid = guid; temp.filePath = allPics[i]; if (guid2Pics.ContainsKey(temp.guid)) { guid2Pics[temp.guid] = temp; } else { guid2Pics.Add(temp.guid, temp); } } } this.Repaint(); }
void OnGUI() { List <string> keys = new List <string>(guid2Pics.Keys); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("读取引用文件")) { LoadRefrenceFile(); } if (GUILayout.Button("生成引用关系")) { BuildRefrence(); } if (GUILayout.Button("保存引用文件")) { SaveRefrence(); } if (GUILayout.Button("设置packing tag")) { SetPackingTag(keys); } if (GUILayout.Button("移动到文件夹")) { MoveToFolders(keys); } EditorGUILayout.EndHorizontal(); #if UNITY_IPHONE EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("读取所有图片")) { ReadAllImageFiles(); } if (GUILayout.Button("修改图片,并生成MD5名字")) { MoveAndRename(keys); } EditorGUILayout.EndHorizontal(); #endif EditorGUILayout.LabelField("注意:请以文件夹为单位进行选择!!!文件夹名即为包名!!!"); scrollValue = EditorGUILayout.BeginScrollView(scrollValue); int startIndex = 0; for (int i = pageCount * pageNum; i < Mathf.Min((pageCount + 1) * pageNum, keys.Count); i++) { Item temp = guid2Pics[keys[i]]; startIndex++; EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(startIndex.ToString()); FileInfo f = new FileInfo(temp.filePath); if (GUILayout.Button(f.Name, GUILayout.Width(300f))) { Debug.Log(f.Name, AssetDatabase.LoadAssetAtPath <Object>(FindRefrence.GetRelativeAssetsPath(temp.filePath))); } EditorGUILayout.LabelField(temp.refCount + ""); EditorGUILayout.LabelField("CurTag: " + temp.CurTag); EditorGUILayout.LabelField("SetTag: " + temp.CreateTag); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); int count = keys.Count; string[] s = new string[count]; int[] ints = new int[count]; for (int i = 0; i < count / pageNum; i++) { s[i] = i.ToString(); ints[i] = i; } pageCount = EditorGUILayout.IntPopup("CurPage", pageCount, s, ints, GUILayout.Width(200f)); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }
void BuildRefrence() { List <string> picExt = new List <string>() { ".png", ".jpg" }; string path = EditorUtility.OpenFolderPanel("选择要检索的文件夹", Application.dataPath + "/JJYDeZhou/BuildResource/Atlas", ""); string[] allPics = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories) .Where(s => picExt.Contains(Path.GetExtension(s).ToLower())).ToArray(); for (int i = 0; i < allPics.Length; i++) { string guid = AssetDatabase.AssetPathToGUID(FindRefrence.GetRelativeAssetsPath(allPics[i])); if (guid2Pics.ContainsKey(guid)) { Debug.LogError(guid + " allPics[i]:" + allPics[i]); } else { Item temp = new Item(); temp.guid = guid; temp.filePath = allPics[i]; if (guid2Pics.ContainsKey(temp.guid)) { guid2Pics[temp.guid] = temp; } else { guid2Pics.Add(temp.guid, temp); } } } List <string> withoutExtensions = new List <string>() { ".prefab", ".unity", ".mat", ".asset" }; string[] files = Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray(); int startIndex = 0; EditorApplication.update = delegate() { string file = files[startIndex]; bool isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", file, (float)startIndex / (float)files.Length); foreach (string guid in guid2Pics.Keys) { if (Regex.IsMatch(File.ReadAllText(file), guid)) { if (guid2Pics.ContainsKey(guid)) { guid2Pics[guid].refCount++; } else { guid2Pics[guid].refCount = 1; } guid2Pics[guid].refFiles.Add(file); } } startIndex++; if (isCancel || startIndex >= files.Length) { EditorUtility.ClearProgressBar(); EditorApplication.update = null; startIndex = 0; Debug.Log("匹配结束"); this.Repaint(); } }; }