using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
[ContextMenu("TextHave")]
public void GetUITextHave()
{
int length = GetComponentsInChildren<UILabel>(true).Length;
//true代表隐藏的物体也会被遍历
string path;
Transform temp;
for (int i = 0; i < length; i++)
{
temp = GetComponentsInChildren<UILabel>(true)[i].transform;
path = temp.name + "/";
while (temp.parent != null)
{
temp = temp.parent;
path += temp.name + "/";
// Debug.Log(1);
}
Debug.Log(GetComponentsInChildren<UILabel>(true)[i].text + " " + path);
}
}
}
unity遍历场景对象下所有对象的脚本,并打印路径
最新推荐文章于 2024-03-18 11:11:07 发布