| | |
| | | //!!!需要注意预制体导入的index要和导出的一致,避免遇到同名时无法区分的问题 |
| | | public class ImportPrefabsWords : EditorWindow { |
| | | |
| | | private static string topFilePath=Application.dataPath + "/ResourcesOut/UI"; |
| | | |
| | | |
| | | [MenuItem("策划工具/==批量导入预制体文字==", false)] |
| | | private static void Export() |
| | |
| | | int startIndex = 0; |
| | | int changeCnt = 0; |
| | | EditorApplication.update = delegate () { |
| | | if (startIndex >= lines.Length) |
| | | { |
| | | Debug.LogFormat("文字批量修改成功-- 检索{0}行,共替换{1}行", startIndex, changeCnt); |
| | | EditorUtility.ClearProgressBar(); |
| | | EditorApplication.update = null; |
| | | startIndex = 0; |
| | | AssetDatabase.SaveAssets(); |
| | | AssetDatabase.Refresh(); |
| | | return; |
| | | } |
| | | var lineStr = lines[startIndex]; |
| | | string[] info = lines[startIndex].Split('\t'); |
| | | startIndex++; |
| | | if (info.Length != 4) |
| | | { |
| | | if (startIndex >= lines.Length) { |
| | | |
| | | EditorUtility.ClearProgressBar(); |
| | | EditorApplication.update = null; |
| | | startIndex = 0; |
| | | AssetDatabase.SaveAssets(); |
| | | AssetDatabase.Refresh(); |
| | | } |
| | | Debug.LogFormat("异常:长度不对--执行到:第{0}行 {1}", startIndex, lineStr); |
| | | return; |
| | | } |
| | | string file = info[0]; |
| | | int index = int.Parse(info[1]); |
| | | string name = info[2]; |
| | | string content = info[3].Replace("\r\n","").Replace("\r","").Replace("\n",""); |
| | | string content = info[3].Replace("\r","").Replace("\n",""); |
| | | |
| | | bool isCancel = EditorUtility.DisplayCancelableProgressBar("导入预制体文字-"+lines.Length, file, (float)startIndex / (float)lines.Length); |
| | | GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(file); |
| | | if (_prefab == null) |
| | | { |
| | | if (isCancel || startIndex >= lines.Length) { |
| | | if (isCancel) { |
| | | |
| | | EditorUtility.ClearProgressBar(); |
| | | EditorApplication.update = null; |
| | |
| | | AssetDatabase.SaveAssets(); |
| | | AssetDatabase.Refresh(); |
| | | } |
| | | Debug.LogFormat("异常:预制体异常--执行到:第{0}行 {1}", startIndex, lineStr); |
| | | return; |
| | | } |
| | | Text[] transArr = _prefab.GetComponentsInChildren<Text>(true); |
| | |
| | | Text item = transArr[index]; |
| | | if (item.name == name) |
| | | { |
| | | if (item.text != content) |
| | | var curText = item.text.Replace("\r", "").Replace("\n", ""); |
| | | if (curText != content) |
| | | { |
| | | item.text = content; |
| | | item.fontSize = item.fontSize - 2; |
| | | EditorUtility.SetDirty(_prefab); |
| | | changeCnt++; |
| | | //Debug.LogFormat("字体批量文件--{0} , {1}", file, index); |
| | |
| | | } |
| | | else |
| | | { |
| | | Debug.LogErrorFormat("第{0}行替换失败{1},{2}", startIndex+1, file, name); |
| | | Debug.LogErrorFormat("异常:第{0}行替换失败{1},{2}", startIndex, file, name); |
| | | } |
| | | |
| | | |
| | | if (isCancel || startIndex >= lines.Length) { |
| | | |
| | | if (isCancel || startIndex >= lines.Length) |
| | | { |
| | | Debug.LogFormat("文字批量修改成功-- 检索{0}行,共替换{1}行", startIndex, changeCnt); |
| | | EditorUtility.ClearProgressBar(); |
| | | EditorApplication.update = null; |
| | | startIndex = 0; |
| | | AssetDatabase.SaveAssets(); |
| | | AssetDatabase.Refresh(); |
| | | Debug.LogFormat("字体批量修改成功--{0}", changeCnt); |
| | | } |
| | | }; |
| | | |