diff --git a/Assets/Scripts/Editor/LanguageTool/ArtFontWindow.cs b/Assets/Scripts/Editor/LanguageTool/ArtFontWindow.cs new file mode 100644 index 0000000000..a16b1ac259 --- /dev/null +++ b/Assets/Scripts/Editor/LanguageTool/ArtFontWindow.cs @@ -0,0 +1,374 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; +using System.IO; +using System.Linq; +using GameEditor.Core; +using GameEditor.GameEditor.PlayerBuilder; +using GameLogic; +using System.Diagnostics; +using ResUpdate; +using System.Threading; +using System; + +namespace GameEditor.FrameTool +{ + enum LanguageType { + ZH, + EN, + VI + }; + + public class ArtFontWindow : EditorWindow + { + + string m_ImportRootPath = Environment.CurrentDirectory + "\\Assets\\ManagedResources"; + + string m_ArtFontPath; + static string[] m_Files; + static LanguageType m_Language = LanguageType.EN; + static bool m_ChooseAll; + static bool[] m_Choose; + static string m_Bench; + Dictionary> m_Config; + Dictionary> m_ArtFontLists; + Dictionary m_ImportArt; + Dictionary m_UnImportArt; + + private void OnEnable() + { + m_ArtFontPath = EditorPrefs.GetString("m_ArtFontPath"); + m_ArtFontLists = new Dictionary>(); + m_ImportArt = new Dictionary(); + m_UnImportArt = new Dictionary(); + + m_Config = new Dictionary>(); + Dictionary en = new Dictionary(); + en.Add("path", "简中_英"); + en.Add("endStr", "_en"); + en.Add("dicStr", "part"); + en.Add("importDic", "ArtFont_en"); + m_Config.Add(LanguageType.EN, en); + Dictionary vi = new Dictionary(); + vi.Add("path", "简中_越南语"); + vi.Add("endStr", "_vi"); + vi.Add("dicStr", "202"); + vi.Add("importDic", "ArtFont_vi"); + m_Config.Add(LanguageType.VI, vi); + } + + // Add menu named "My Window" to the Window menu + [MenuItem("LanguageTool/ArtFont/导入资源工具")] + static void Init() + { + + // Get existing open window or if none, make a new one: + ArtFontWindow window = (ArtFontWindow)EditorWindow.GetWindow(typeof(ArtFontWindow)); + window.Show(); + window.InitWindow(); + + } + + void InitWindow() + { + InitSize(); + InitGames(); + } + + /// + /// 初始化大小 + /// + void InitSize() + { + //minSize = new Vector2(600, 400); + //maxSize = new Vector2(600, 650); + } + + + /// + /// 初始化游戏 + /// + void InitGames() + { + LoadDic(); + } + + void OnGUI() + { + + EditorGUILayout.BeginVertical(); + EditorGUILayout.Space(); + + EditorGUILayout.LabelField("本地化文件夹路径 svn://60.1.1.230/jieling/document/美术/本地化 对应的本地文件夹:", GUILayout.Width(600f)); + GUILayout.BeginHorizontal(); + //GUILayout.Label("源文件路径:", GUILayout.ExpandWidth(false)); + this.m_ArtFontPath = GUILayout.TextField(m_ArtFontPath, GUILayout.Width(450f)); + if (GUILayout.Button("选择文件夹", GUILayout.ExpandWidth(false))) + { + this.m_ArtFontPath = EditorUtility.OpenFolderPanel("Resource path", m_ArtFontPath, Application.dataPath); + EditorPrefs.SetString("m_ArtFontPath", m_ArtFontPath); + LoadDic(); + } + GUILayout.EndHorizontal(); + + EditorGUILayout.LabelField("请选择语言:"); + GUILayout.BeginHorizontal(); + //for (int i = 0; i < m_Config.Count; i++) + //{ + foreach(KeyValuePair> config in m_Config) + { + + if (EditorGUILayout.ToggleLeft(config.Value["path"], m_Language == config.Key)) + { + if (m_Language != config.Key) + { + m_Language = config.Key; + LoadDic(); + } + } + } + //} + GUILayout.EndHorizontal(); + + EditorGUILayout.LabelField("请选择文件夹:"); + if (m_Files != null && m_Files.Length != 0) + { + m_ChooseAll = EditorGUILayout.ToggleLeft("全部", m_ChooseAll); + GUILayout.BeginHorizontal(); + for (int i = 0; i < m_Files.Length; i++) + { + string fileName = Path.GetFileName(m_Files[i]); + m_Choose[i] = EditorGUILayout.ToggleLeft(fileName, m_Choose[i] && !m_ChooseAll); + + if (i % 4 == 3) + { + GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(); + } + } + GUILayout.EndHorizontal(); + } + else + { + EditorGUILayout.LabelField(" 未找到文件夹"); + } + + + if (GUILayout.Button("导入", GUILayout.Height(50))) + { + m_ArtFontLists[LanguageType.ZH] = GetAllArtFont(LanguageType.ZH); + if (m_ChooseAll) + { + for (int i = 0; i < m_Files.Length; i++) + { + string dirPath = m_Files[i]; + ImportDirectoryTex(dirPath); + } + } + else + { + + for (int i = 0; i < m_Choose.Length; i++) + { + if (m_Choose[i]) + { + string dirPath = m_Files[i]; + ImportDirectoryTex(dirPath); + } + } + } + + // 刷新导入的资源 + AssetDatabase.Refresh(); + // 检测导入资源的尺寸是否符合要求 + CheckImportFileSize(); + // + UnityEngine.Debug.LogWarning("导入成功的资源:" + m_ImportArt.Count); + foreach (KeyValuePair v in m_ImportArt) + { + UnityEngine.Debug.Log(String.Format("{0}->{1}", v.Key, v.Value)); + } + if(m_UnImportArt.Count > 0) + { + UnityEngine.Debug.LogError("导入失败的资源:"+ m_UnImportArt.Count); + foreach (KeyValuePair v in m_UnImportArt) + { + UnityEngine.Debug.LogError(String.Format("{0}, 失败原因:{1}", v.Key, v.Value)); + } + } + } + + + } + + // 加载本地化路径文件夹数据 + private void LoadDic() + { + string path = m_ArtFontPath + "/" + m_Config[m_Language]["path"]; + if (!string.IsNullOrEmpty(path) && Directory.Exists(path)) + { + string[] t_Files = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly); + List t_l_Files = t_Files.ToList(); + for (int i = 0; i < t_Files.Length; i++) + { + string fileName = Path.GetFileName(t_Files[i]); + if (!fileName.StartsWith(m_Config[m_Language]["dicStr"])) + { + t_l_Files.Remove(t_Files[i]); + } + } + m_Files = t_l_Files.ToArray(); + m_Choose = new bool[m_Files.Length]; + } + } + + // 按文件夹导入文件 + private void ImportDirectoryTex(string dirPath) + { + string[] t_Files = Directory.GetFiles(dirPath, "*", SearchOption.TopDirectoryOnly); + for (int i = 0; i < t_Files.Length; i++) + { + EditorUtility.DisplayProgressBar(dirPath, string.Format("({0}/{1}):{2}", i, t_Files.Length, t_Files[i]), (float)i / t_Files.Length); + ImportSingleTex(t_Files[i]); + } + EditorUtility.ClearProgressBar(); + } + + // 导入单个文件 + private void ImportSingleTex(string filePath) + { + + UnityEngine.Debug.Log(string.Format("import file: {0}", filePath)); + if (File.Exists(filePath)) + { + //CheckFileSize(filePath); + string o_Name = Path.GetFileName(filePath); + string fix_Name = CheckFileName(o_Name); + if (!fix_Name.Equals(o_Name)) + { + UnityEngine.Debug.LogWarning(string.Format("file name fixed: {0}->{1}", o_Name, fix_Name)); + } + string importPath = m_ImportRootPath + "/" + m_Config[m_Language]["importDic"] + "/" + fix_Name; + if (HasChineseArtFont(fix_Name)) + { + + if (File.Exists(importPath)) + { + File.Delete(importPath); + } + if(File.Exists(Path.ChangeExtension(importPath, ".png"))){ + + File.Delete(Path.ChangeExtension(importPath, ".png")); + } + if (File.Exists(Path.ChangeExtension(importPath, ".jpg"))) + { + File.Delete(Path.ChangeExtension(importPath, ".jpg")); + } + + File.Copy(filePath, importPath); + m_ImportArt.Add(filePath, importPath); + } + else + { + m_UnImportArt.Add(filePath, "未找到对应的中文路径"); + } + } + } + + // 判断在中文资源种是否存在 + private bool HasChineseArtFont(string fileName) + { + + foreach (string path in m_ArtFontLists[LanguageType.ZH]) + { + string zhName = Path.GetFileNameWithoutExtension(path); + zhName = zhName.Substring(0, zhName.Length-3); + string trName = Path.GetFileNameWithoutExtension(fileName); + trName = trName.Substring(0, trName.Length-3); + if (zhName.Equals(trName)) + { + return true; + } + } + return false; + } + + private List GetAllArtFont(LanguageType language) + { + string directoryName = ""; + if(language == LanguageType.ZH) + { + directoryName = "ArtFont"; + } + else if(language == LanguageType.EN) + { + directoryName = "ArtFont_en"; + } + else if (language == LanguageType.VI) + { + directoryName = "ArtFont_vi"; + } + string dirPath = Environment.CurrentDirectory + "\\Assets\\ManagedResources"; + List flist = new List(); + List dirs = new List(Directory.GetDirectories(dirPath, directoryName, SearchOption.AllDirectories)); + for (int i = 0; i < dirs.Count; i++) + { + string[] files = Directory.GetFiles(dirs[i]); + for (int j = 0; j < files.Length; j++) + { + flist.Add(files[j]); + } + } + return flist; + } + + // 检测导入文件的大小是否符合要求 + private void CheckImportFileSize() + { + int i = 0; + foreach(KeyValuePair v in m_ImportArt) + { + i++; + EditorUtility.DisplayProgressBar("修正导入资源的像素大小", string.Format("({0}/{1}):{2}", i, m_ImportArt.Count, v.Value), (float)i / m_ImportArt.Count); + CheckFileSize(v.Value); + } + EditorUtility.ClearProgressBar(); + AssetDatabase.Refresh(); + } + + // 检测文件大小是否符合要求 + private void CheckFileSize(string filePath) + { + if (File.Exists(filePath)) + { + filePath = filePath.Replace(Environment.CurrentDirectory+"\\", ""); + LJ_OptTools.TextureOptUtilities.RemoveBigTexPackageTag(filePath); + LJ_OptTools.TextureOptUtilities.ExtendTexture(filePath); + } + else + { + UnityEngine.Debug.LogError("检测文件像素大小失败,未找到文件:" + filePath); + } + } + + // 文件名检测返回正确的 + private string CheckFileName(string fileNameExt) + { + if (fileNameExt.EndsWith(".png.png")|| fileNameExt.EndsWith(".jpg.jpg")) + { + fileNameExt = fileNameExt.Substring(0, fileNameExt.Length - 3); + } + string fileName = Path.GetFileNameWithoutExtension(fileNameExt); + string ext = Path.GetExtension(fileNameExt); + if (fileName.EndsWith("_zh") || fileName.EndsWith("_en") || fileName.EndsWith("_vi")) + { + fileName = fileName.Substring(0, fileName.Length - 3); + } + + return fileName + m_Config[m_Language]["endStr"] + ext; + } + + } + +} diff --git a/Assets/Scripts/Editor/LanguageTool/ArtFontWindow.cs.meta b/Assets/Scripts/Editor/LanguageTool/ArtFontWindow.cs.meta new file mode 100644 index 0000000000..7f9c0578f4 --- /dev/null +++ b/Assets/Scripts/Editor/LanguageTool/ArtFontWindow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d5b84315dfd0aba49ba66358fc6a5b49 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: