using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System.IO;
using System.Text;
public class GetUIText : EditorWindow
{
[MenuItem("Assets/Tools/选中预设查找Text(换完汉字就删)", false, 100)]
static void SearchRefrence()
{
GetUIText window = (GetUIText)EditorWindow.GetWindow(typeof(GetUIText), false, "Searching", true);
window.Show();
}
private static GameObject searchObject;
private List<Text> result = new List<Text>();
private void OnGUI()
{
EditorGUILayout.BeginHorizontal();
// searchObject = EditorGUILayout.ObjectField(searchObject, typeof(Object), true, GUILayout.Width(200));
searchObject = Selection.activeGameObject;
EditorGUILayout.ObjectField(searchObject, typeof(GameObject), true, GUILayout.Width(200));
if (GUILayout.Button("Search", GUILayout.Width(100)))
{
result.Clear();
if (searchObject == null)
return;
GameObject pre = searchObject;
Text [] texts = pre.GetComponentsInChildren<Text>(true);
for (int n = 0; n < texts.Length; n++)
{
Text text = texts[n];
if (text && !result.Contains(text)&&!string.IsNullOrEmpty(text.text))
{
result.Add(text);
EditorUtility.DisplayCancelableProgressBar("Checking", text.name, n / texts.Length * 0.9f);
}
}
EditorUtility.DisplayCancelableProgressBar("Checking", null, 0.9f);
//result.Sort((l, r) => l.name.CompareTo(r.name));
EditorUtility.ClearProgressBar();
}
EditorGUILayout.EndHorizontal();
//显示结果
EditorGUILayout.BeginVertical();
for (int i = 0; i < result.Count; i++)
{
//EditorGUILayout.ObjectField(result[i], typeof(Object), true, GUILayout.Width(300));
EditorGUILayout.LabelField(result[i].name + "=="+result[i].text);
}
EditorGUILayout.EndHorizontal();
}
}
网友评论