由于要上线苹果,发现苹果上字号不能太多
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;
using static UnityEditor.EditorGUILayout;
public class SelectTextTools: EditorWindow
{
static string path = "Assets/Art/pgbundle/UI";//路径按需修改
static List<GameObject> GetObject = new List<GameObject>();
static Dictionary<int, List<Text>> TextZiHao = new Dictionary<int, List<Text>>();
[MenuItem("UITools/查找字号")]
static void SeleceNullImage()
{
GetObject.Clear();
TextZiHao.Clear();
string[] ids = AssetDatabase.FindAssets("t:Prefab", new string[] { path });
for (int i = 0; i < ids.Length; i++)
{
string tempPath = AssetDatabase.GUIDToAssetPath(ids[i]);
if (!string.IsNullOrEmpty(tempPath))
{
Transform transform = AssetDatabase.LoadAssetAtPath(tempPath, typeof(Transform)) as Transform;
if (transform != null)
{
SetObject(transform.gameObject);
}
}
}
GetWindow<SelectTextTools>("Text字号");
}
private static void SetObject(GameObject gameObject)
{
var temp = gameObject.GetComponent<Text>();
if (temp != null)
{
GetObject.Add(gameObject);
if(!TextZiHao.ContainsKey(temp.fontSize))
{
TextZiHao.Add(temp.fontSize, new List<Text>());
}
TextZiHao[temp.fontSize].Add(temp);
}
for (int i = 0; i < gameObject.transform.childCount; i++)
{
SetObject(gameObject.transform.GetChild(i).gameObject);
}
}
Vector2 scrollViewPos031;
int idx = 0;
private void OnGUI()
{
scrollViewPos031 = BeginScrollView(scrollViewPos031);
foreach (var item in TextZiHao)
{
BeginHorizontal();
if(GUILayout.Button("字号:" + item.Key + " 数量:" + item.Value.Count, GUILayout.Width(200)))
{
idx = item.Key;
}
if (idx == item.Key)
{
EndHorizontal();
for (int i = 0; i < item.Value.Count; i++)
{
BeginHorizontal();
ObjectField(GetParent(item.Value[i].transform), typeof(GameObject), true, GUILayout.Width(400));
ObjectField(item.Value[i], typeof(Text), true, GUILayout.Width(400));
EndHorizontal();
}
}
else
EndHorizontal();
}
EndScrollView();
}
private GameObject GetParent(Transform transform)
{
if (transform.parent != null)
return GetParent(transform.parent);
return transform.gameObject;
}
}