| | |
| | | |
| | | foreach (Text item in transArr14) |
| | | { |
| | | if (item.font == fromChangeFont) |
| | | { |
| | | bool change = true; |
| | | if (item.rectTransform.rect.height <= 2)
|
| | | {
|
| | | change = false; |
| | | } |
| | | //else if (item.resizeTextForBestFit && item.resizeTextMaxSize > 24)
|
| | | //{ |
| | | // item.fontSize = 24; |
| | | // item.resizeTextMaxSize = 24; |
| | | //} |
| | | //else if (item.fontSize > 16 && item.fontSize <= 24)
|
| | | //{
|
| | | // item.fontSize = item.fontSize - 1; |
| | | //}
|
| | | else if (item.fontSize > 24)
|
| | | {
|
| | | item.fontSize = 24; |
| | | }
|
| | | else
|
| | | {
|
| | | change = false;
|
| | | }
|
| | | if (change)
|
| | | { |
| | | EditorUtility.SetDirty(_prefab); |
| | | Debug.LogFormat("界面 {0} 字体大小修改成功", file); |
| | | i++; |
| | | }
|
| | | bool change = false; |
| | | if (item.text == "0")
|
| | | {
|
| | | item.text = ""; |
| | | change = true; |
| | | } |
| | | |
| | | if (change)
|
| | | { |
| | | EditorUtility.SetDirty(_prefab); |
| | | Debug.LogFormat("界面 {0} 字体大小修改成功", file); |
| | | i++; |
| | | }
|
| | | |
| | | } |
| | | |
New file |
| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEditor; |
| | | using System.IO; |
| | | using UnityEngine.UI; |
| | | using Snxxz.UI; |
| | | using System.Reflection;
|
| | |
|
| | | // 导出文本规格,如长宽,字体,字号,颜色,描边,阴影,行间距
|
| | | public class ExportPrefabsWordFormat : EditorWindow { |
| | | |
| | | private static string topFilePath=Application.dataPath + "/ResourcesOut/UI"; |
| | | |
| | | |
| | | [MenuItem("策划工具/批量导出预制体文本格式", false)] |
| | | private static void Export() |
| | | { |
| | | |
| | | string writePath = "exportFontSize.txt"; |
| | | if (File.Exists(writePath)) |
| | | { |
| | | File.Delete(writePath); |
| | | } |
| | | FileStream fs = new FileStream(writePath,FileMode.Create);//如不存在,则创建新的文本文档
|
| | | string writeline1 = string.Format("路径\t索引\t名字\t宽\t高\tanchorMinX\tanchorMinY\tanchorMaxX\tanchorMaxY\tanchoredPositionX\tanchoredPositionY\tpivotX\tpivotY\tlocalScaleX\tlocalScaleY\t字大小\t对齐\t行宽\t横溢出\t竖溢出\t自适应\t自适应最小\t自适应最大\r\n");
|
| | | byte[] data1 = System.Text.Encoding.UTF8.GetBytes(writeline1);
|
| | | fs.Write(data1, 0, data1.Length); |
| | | |
| | | topFilePath = Application.dataPath + "/ResourcesOut/UI"; |
| | | |
| | | 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) |
| | | { |
| | |
|
| | | var test1 = item as TextImage;
|
| | | if (test1 != null)
|
| | | {
|
| | | i++;
|
| | | continue;
|
| | | }
|
| | | var test2 = item as OffsetImage2;
|
| | | if (test2 != null)
|
| | | {
|
| | | i++;
|
| | | continue;
|
| | | }
|
| | |
|
| | | RectTransform rectTransform = item.GetComponent<RectTransform>();
|
| | | string writeline = string.Format($"{file}\t{i}\t{item.name}\t{rectTransform.sizeDelta.x}\t{rectTransform.sizeDelta.y}\t{rectTransform.anchorMin.x}\t{rectTransform.anchorMin.y}\t{rectTransform.anchorMax.x}\t{rectTransform.anchorMax.y}\t{rectTransform.anchoredPosition.x}\t{rectTransform.anchoredPosition.y}\t{rectTransform.pivot.x}\t{rectTransform.pivot.y}\t{rectTransform.localScale.x}\t{rectTransform.localScale.y}\t{item.fontSize}\t{item.alignment}\t{item.lineSpacing}\t{item.horizontalOverflow}\t{item.verticalOverflow}\t{item.resizeTextForBestFit}\t{item.resizeTextMinSize}\t{item.resizeTextMaxSize}\r\n"); |
| | | 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();//关闭 |
| | | |
| | | |
| | | } |
| | | }; |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: e2e3a157b12c9d244b7cec5f0a516ff6 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEditor; |
| | | using System.IO; |
| | | using UnityEngine.UI; |
| | | using Snxxz.UI; |
| | | using System.Text; |
| | | using System.Linq;
|
| | | using System;
|
| | |
|
| | | //批量导入文本格式
|
| | | public class ImportPrefabsWordFormat : EditorWindow
|
| | | { |
| | | |
| | | |
| | | [MenuItem("策划工具/==批量导入预制体文本格式==", false)] |
| | | private static void Export() |
| | | { |
| | | |
| | | string writePath = "importFontSize.txt"; |
| | | if (!File.Exists(writePath)) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | string[] lines = File.ReadAllLines(writePath, Encoding.UTF8); |
| | | //按文件分组 |
| | | Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>(); |
| | | for (int i = 0; i < lines.Length; i++) |
| | | {
|
| | | string[] info = lines[i].Split('\t');
|
| | | string file = info[0];
|
| | | if (!dic.ContainsKey(file))
|
| | | {
|
| | | dic.Add(file, new List<string>());
|
| | | }
|
| | | dic[file].Add(lines[i]);
|
| | | } |
| | | |
| | | var fileList = dic.Keys.ToList(); |
| | | |
| | | int startIndex = 0; |
| | | int changeCnt = 0; |
| | | EditorApplication.update = delegate () { |
| | | if (startIndex >= fileList.Count) |
| | | { |
| | | Debug.LogFormat("文本格式批量修改成功-- 检索{0}行,共替换{1}行", startIndex, changeCnt); |
| | | EditorUtility.ClearProgressBar(); |
| | | EditorApplication.update = null; |
| | | startIndex = 0; |
| | | AssetDatabase.SaveAssets(); |
| | | AssetDatabase.Refresh(); |
| | | return; |
| | | } |
| | | var file = fileList[startIndex]; |
| | | var singleFilelines = dic[fileList[startIndex]]; |
| | | startIndex++; |
| | | |
| | | bool isCancel = EditorUtility.DisplayCancelableProgressBar("导入预制体文本格式-" + fileList.Count, file, (float)startIndex /fileList.Count); |
| | | GameObject _prefab = AssetDatabase.LoadAssetAtPath<GameObject>(file); |
| | | if (_prefab == null) |
| | | { |
| | | Debug.LogFormat("没有此文件 {0} - {1}", startIndex, file); |
| | | return; |
| | | } |
| | | foreach (var line in singleFilelines)
|
| | | { |
| | | string[] info = line.Split('\t'); |
| | | |
| | | int index = int.Parse(info[1]); |
| | | string name = info[2]; |
| | | |
| | | Text[] transArr = _prefab.GetComponentsInChildren<Text>(true); |
| | | |
| | | if (index >= transArr.Length)
|
| | | { |
| | | Debug.LogFormat("第{0}个替换失败{1} 此文件文本越界", startIndex, file); |
| | | break; |
| | | } |
| | | Text item = transArr[index]; |
| | | if (item.name == name) |
| | | {
|
| | |
|
| | | RectTransform rectTransform = item.GetComponent<RectTransform>();
|
| | |
|
| | | rectTransform.sizeDelta = new Vector2(float.Parse(info[3]), float.Parse(info[4]));
|
| | | rectTransform.anchorMin = new Vector2(float.Parse(info[5]), float.Parse(info[6]));
|
| | | rectTransform.anchorMax = new Vector2(float.Parse(info[7]), float.Parse(info[8]));
|
| | | rectTransform.anchoredPosition = new Vector2(float.Parse(info[9]), float.Parse(info[10]));
|
| | | rectTransform.pivot = new Vector2(float.Parse(info[11]), float.Parse(info[12]));
|
| | | rectTransform.localScale = new Vector3(float.Parse(info[13]), float.Parse(info[14]), rectTransform.localScale.z);
|
| | | item.fontSize = int.Parse(info[15]);
|
| | | item.alignment = (TextAnchor)Enum.Parse(typeof(TextAnchor), info[16]);
|
| | | item.lineSpacing = float.Parse(info[17]);
|
| | | item.horizontalOverflow = (HorizontalWrapMode)Enum.Parse(typeof(HorizontalWrapMode), info[18]);
|
| | | item.verticalOverflow = (VerticalWrapMode)Enum.Parse(typeof(VerticalWrapMode), info[19]);
|
| | | item.resizeTextForBestFit = bool.Parse(info[20]);
|
| | | item.resizeTextMinSize = int.Parse(info[21]);
|
| | | item.resizeTextMaxSize = int.Parse(info[22]);
|
| | |
|
| | | EditorUtility.SetDirty(_prefab);
|
| | | |
| | | changeCnt++; |
| | | } |
| | | else |
| | | { |
| | | Debug.LogErrorFormat("异常:第{0}行替换失败{1},{2}", startIndex, file, name); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | if (isCancel || startIndex >= lines.Length)
|
| | | { |
| | | Debug.LogFormat("文字批量修改成功-- 检索{0}行,共替换{1}行", lines.Length, changeCnt); |
| | | EditorUtility.ClearProgressBar(); |
| | | EditorApplication.update = null; |
| | | startIndex = 0; |
| | | AssetDatabase.SaveAssets(); |
| | | AssetDatabase.Refresh(); |
| | | } |
| | | };
|
| | |
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | | } |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: cef04c22ca2f69345ab203cdb6318ab9 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | | defaultReferences: [] |
| | | executionOrder: 0 |
| | | icon: {instanceID: 0} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
| | |
| | | m_GameObject: {fileID: 5623745769563117488} |
| | | m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} |
| | | m_LocalPosition: {x: 0, y: 0, z: 0} |
| | | m_LocalScale: {x: 0.9995004, y: 0.9995004, z: 0.9995004} |
| | | m_LocalScale: {x: 1, y: 1, z: 1} |
| | | m_Children: [] |
| | | m_Father: {fileID: 1381617878036687758} |
| | | m_RootOrder: 0 |
| | | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
| | | m_AnchorMin: {x: 0.5, y: 0.5} |
| | | m_AnchorMax: {x: 0.5, y: 0.5} |
| | | m_AnchoredPosition: {x: -0.2000122, y: 21.199966} |
| | | m_SizeDelta: {x: 47.1, y: 141} |
| | | m_AnchoredPosition: {x: -0.2, y: 21} |
| | | m_SizeDelta: {x: 50, y: 141} |
| | | m_Pivot: {x: 0.5, y: 0.5} |
| | | --- !u!222 &5801197155939083364 |
| | | CanvasRenderer: |
| | |
| | | m_PersistentCalls: |
| | | m_Calls: [] |
| | | m_FontData: |
| | | m_Font: {fileID: 12800000, guid: 8dc6445b1c0b84d4fbf1147740d43a4e, type: 3} |
| | | m_FontSize: 27 |
| | | m_Font: {fileID: 12800000, guid: 7cd825c6867461a4090871836190730f, type: 3} |
| | | m_FontSize: 25 |
| | | m_FontStyle: 0 |
| | | m_BestFit: 0 |
| | | m_MinSize: 10 |
| | | m_MaxSize: 40 |
| | | m_BestFit: 1 |
| | | m_MinSize: 2 |
| | | m_MaxSize: 25 |
| | | m_Alignment: 4 |
| | | m_AlignByGeometry: 0 |
| | | m_RichText: 0 |
| | | m_HorizontalOverflow: 0 |
| | | m_VerticalOverflow: 1 |
| | | m_LineSpacing: 0.8 |
| | | m_Text: "\u5F53\u524D\u6807\u9898" |
| | | m_LineSpacing: 1 |
| | | m_Text: fddfs sfsd |
| | | m_IsKey: 0 |
| | | m_KeyName: |
| | | m_ColorType: 0 |