/*
|
|
检查allBg图片引用
|
|
*/
|
|
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using System.IO;
|
|
using System.Collections;
|
|
|
|
namespace CheckAllBgUseInCodeNameSpace {
|
|
public class CheckAllBgUseInCode
|
|
{
|
|
private static string luaPath = @"H:\Tomorrow\develop\code\u3d\Lua\game";
|
|
private static string luaPath2 = @"H:\Tomorrow\develop\code\u3d\Lua\newgameui";
|
|
private static string allBgPath = @"H:\Tomorrow\develop\code\u3d\Assets\LuaFramework\AssetBundleRes\icon\allBg";
|
|
private static string[] check_result_list;
|
|
private static ArrayList mid_check_result_array = new ArrayList();
|
|
private static ArrayList end_check_result_array = new ArrayList();
|
|
|
|
[MenuItem("Tools/检查allBg的代码引用")]
|
|
public static void SelectFile()
|
|
{
|
|
//获取指定路径下面的所有资源文件
|
|
if (Directory.Exists(allBgPath))
|
|
{
|
|
CheckPathFileWord();
|
|
}
|
|
}
|
|
|
|
//要处理的目录
|
|
static void CheckPathFileWord()
|
|
{
|
|
DirectoryInfo pngDirection = new DirectoryInfo(allBgPath);
|
|
FileInfo[] pngFiles = pngDirection.GetFiles("*.png", SearchOption.AllDirectories);
|
|
int startIndex = 0;
|
|
string[] luaFiles = {};
|
|
string[] luaFiles2 = {};
|
|
mid_check_result_array = new ArrayList();
|
|
end_check_result_array = new ArrayList();
|
|
luaFiles = Directory.Exists(luaPath)?Directory.GetFiles(luaPath, "*.lua", SearchOption.AllDirectories):luaFiles;
|
|
//还有一个路径也要加入筛选
|
|
luaFiles2 = Directory.Exists(luaPath2)?Directory.GetFiles(luaPath2, "*.lua", SearchOption.AllDirectories):luaFiles;
|
|
|
|
EditorApplication.update = delegate ()
|
|
{
|
|
int allLen = luaFiles.Length + luaFiles2.Length;
|
|
string filePath = "";
|
|
if (startIndex <= luaFiles.Length - 1){
|
|
filePath = luaFiles.Length>0?GetRelativeAssetsPath(luaFiles[startIndex]):"检索路径不存在(@#!%*&)";
|
|
}
|
|
else{
|
|
filePath = luaFiles2.Length>0?GetRelativeAssetsPath(luaFiles2[startIndex - luaFiles.Length]):"检索路径不存在(@#!%*&)";
|
|
}
|
|
if (!filePath.Contains("路径不存在(@#!%*&)")) SetArabicSupToLua( filePath, pngFiles);
|
|
/*------------------------------*/
|
|
bool isCancel = EditorUtility.DisplayCancelableProgressBar(string.Format("资源检查中({0}/{1})", startIndex, allLen), filePath, (float)startIndex / (float)allLen);
|
|
startIndex++;
|
|
if (startIndex >= allLen)
|
|
{
|
|
// AssetDatabase.Refresh();
|
|
// AssetDatabase.SaveAssets();
|
|
EditorUtility.ClearProgressBar();
|
|
EditorApplication.update = null;
|
|
startIndex = 0;
|
|
string tempFileName;
|
|
for (int i = 0; i < pngFiles.Length; i++)
|
|
{
|
|
tempFileName = pngFiles[i].Name.Replace(".png","");
|
|
if (!mid_check_result_array.Contains(tempFileName)) {
|
|
end_check_result_array.Add(tempFileName);
|
|
}
|
|
}
|
|
// 保存数据
|
|
tempFileName = "";
|
|
foreach (object obj in end_check_result_array)
|
|
{
|
|
tempFileName = tempFileName + obj.ToString() + "\n";
|
|
}
|
|
string confighFilePath = Application.streamingAssetsPath + "/CheckAllBgUseInCode.txt";
|
|
File.WriteAllText(confighFilePath, tempFileName);
|
|
EditorUtility.DisplayDialog("处理完成", "allBg资源检查结束" , "Ok");
|
|
System.Diagnostics.Process.Start("explorer.exe", Application.streamingAssetsPath.Replace("/", "\\"));
|
|
System.Diagnostics.Process.Start("explorer.exe", confighFilePath.Replace("/", "\\"));
|
|
}
|
|
else if (isCancel) {
|
|
Debug.Log( "处理中止" );
|
|
EditorUtility.ClearProgressBar();
|
|
EditorApplication.update = null;
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
static private string GetRelativeAssetsPath(string path)
|
|
{
|
|
return Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath), "").Replace('\\', '/');
|
|
}
|
|
|
|
static void SetArabicSupToLua(string path, FileInfo[] pngFiles)
|
|
{
|
|
using (StreamReader reader = new StreamReader(path))
|
|
{
|
|
string dataStr = reader.ReadToEnd();
|
|
string tempFileName;
|
|
for (int i = 0; i < pngFiles.Length; i++)
|
|
{
|
|
tempFileName = pngFiles[i].Name.Replace(".png","");
|
|
if (dataStr.Contains(tempFileName)) {
|
|
if (!mid_check_result_array.Contains(tempFileName)) {
|
|
mid_check_result_array.Add(tempFileName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|