少年修仙传客户端基础资源
hch
2020-09-07 e4226cd7efabf865d08740d200431b9a464d7474
0312 导入导出预制体文字
2个文件已修改
4个文件已添加
213 ■■■■■ 已修改文件
Assets/Editor/Logo/TheSecondWorld/LoginBackGround.png.meta 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Logo/xbqy/LoginBackGround.png.meta 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/ExportPrefabsWords.cs 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/ExportPrefabsWords.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/ImportPrefabsWords.cs 91 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/ImportPrefabsWords.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Logo/TheSecondWorld/LoginBackGround.png.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2b180054a3849a441b987938389a2326
guid: f241f3938cf5b2e469e262f979a52838
timeCreated: 1555914219
licenseType: Free
TextureImporter:
Assets/Editor/Logo/xbqy/LoginBackGround.png.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2b180054a3849a441b987938389a2326
guid: 841bc13d4b96eaf48b70d275eb62fbfd
timeCreated: 1555914219
licenseType: Free
TextureImporter:
Assets/Editor/Tool/ExportPrefabsWords.cs
New file
@@ -0,0 +1,94 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using UnityEngine.UI;
using Snxxz.UI;
public class ExportPrefabsWords : EditorWindow {
    private static string topFilePath=Application.dataPath + "/ResourcesOut/UI";
    [MenuItem("策划工具/批量导出预制体文字", false)]
    private static void Export()
    {
        string writePath = "export.txt";
        if (File.Exists(writePath))
        {
            File.Delete(writePath);
        }
        FileStream fs = new FileStream(writePath,FileMode.Create);//如不存在,则创建新的文本文档
        string[] filepaths1 = Directory.GetFiles(topFilePath, "*.prefab", SearchOption.AllDirectories);
        Debug.LogFormat("批量导出UI预制体文字路径{0}, {1}", topFilePath, filepaths1.Length);
        topFilePath = Application.dataPath + "/ResourcesOut/BuiltIn";
        string[] filepaths2 = Directory.GetFiles(topFilePath, "*.prefab", SearchOption.AllDirectories);
        Debug.LogFormat("批量导出BuiltIn预制体文字路径{0}, {1}", topFilePath, filepaths2.Length);
        string[] filepaths = new string[filepaths1.Length + filepaths2.Length];
        filepaths1.CopyTo(filepaths, 0);
        filepaths2.CopyTo(filepaths, filepaths1.Length);
        Debug.LogFormat("批量导出预制体总数:{0}", filepaths.Length);
        int startIndex = 0;
        int a = 0;
        int b = 0;
        int c = 0;
        int d = 0;
        int e = 0;
        EditorApplication.update = delegate () {
            string file = filepaths[startIndex];
            file = file.Substring(file.IndexOf("Assets"));
            bool isCancel = EditorUtility.DisplayCancelableProgressBar("导出预制体文字-"+filepaths.Length, file, (float)startIndex / (float)filepaths.Length);
            GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(file);
            Text[] transArr14 = _prefab.GetComponentsInChildren<Text>(true);
            a += transArr14.Length;
            RichText[] transArr11 = _prefab.GetComponentsInChildren<RichText>(true);
            b += transArr11.Length;
            TextImage[] transArr12 = _prefab.GetComponentsInChildren<TextImage>(true);
            c += transArr12.Length;
            OffsetImage2[] transArr13 = _prefab.GetComponentsInChildren<OffsetImage2>(true);
            d += transArr13.Length;
            TextEx[] transArr = _prefab.GetComponentsInChildren<TextEx>(true);
            e += transArr.Length;
            //Debug.LogFormat("{0}包含TextEx个数 {1}", file, transArr.Length);
            int i = 0;
            foreach (Text item in transArr14)
            {
                // /Debug.LogFormat("{0}包含文字 {1}-{2}", file, item.name, item.text);
                string temp = item.text.Replace("\r\n","").Replace("\r","").Replace("\n","");
                string writeline = string.Format("{0}\t{1}\t{2}\t{3}\r\n", file, i, item.name, temp);
                byte[] data = System.Text.Encoding.UTF8.GetBytes(writeline);
                fs.Write(data, 0, data.Length);
                i++;
            }
            startIndex++;
            if (isCancel || startIndex >= filepaths.Length) {
                Debug.LogFormat("Text:{0},RichText:{1},TextImage:{2},OffsetImage2:{3},TextEx:{4}", a,b,c,d,e);
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
                startIndex = 0;
                fs.Flush();
                fs.Close();//关闭
            }
        };
    }
}
Assets/Editor/Tool/ExportPrefabsWords.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4e8d2c973b8733f49b5b17169bc76c5f
timeCreated: 1596636734
licenseType: Free
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
Assets/Editor/Tool/ImportPrefabsWords.cs
New file
@@ -0,0 +1,91 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using UnityEngine.UI;
using Snxxz.UI;
using System.Text;
//批量导入文字到预制体的text中
//!!!需要注意预制体导入的index要和导出的一致,避免遇到同名时无法区分的问题
public class ImportPrefabsWords : EditorWindow {
    private static string topFilePath=Application.dataPath + "/ResourcesOut/UI";
    [MenuItem("策划工具/==批量导入预制体文字==", false)]
    private static void Export()
    {
        string writePath = "import.txt";
        if (!File.Exists(writePath))
        {
            return;
        }
        string[] lines = File.ReadAllLines(writePath, Encoding.UTF8);
        int startIndex = 0;
        EditorApplication.update = delegate () {
            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();
                }
                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","");
            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) {
                    EditorUtility.ClearProgressBar();
                    EditorApplication.update = null;
                    startIndex = 0;
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
                return;
            }
            Text[] transArr = _prefab.GetComponentsInChildren<Text>(true);
            Text item = transArr[index];
            if (item.name == name)
            {
                item.text = content;
                EditorUtility.SetDirty(_prefab);
            }else
            {
                Debug.LogErrorFormat("第{0}行替换失败{1},{2}", startIndex+1, file, name);
            }
            if (isCancel || startIndex >= lines.Length) {
                EditorUtility.ClearProgressBar();
                EditorApplication.update = null;
                startIndex = 0;
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        };
    }
}
Assets/Editor/Tool/ImportPrefabsWords.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f837d3020b5fa8a4a8c40af3b4656e94
timeCreated: 1596786058
licenseType: Free
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant: