unity3d:遍历查找,输出子物体在父物体下的路径

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/luoyikun/article/details/88029618
 [MenuItem("SaveTransInfo/GetUIChildPath #`")]
    static void GetUIChildPath()
    {
        GameObject obj = Selection.activeGameObject;


        Transform trans = obj.transform;
        listParName.Clear();
        FindParName(trans);

        string parPath = "";
        for (int i = listParName.Count - 1; i >= 0; i--)
        {
            parPath += listParName[i];
            if (i != 0)
            {
                parPath += "/";
            }
        }

        Debug.Log(parPath);
         TextEditor te = new TextEditor();
        te.content = new GUIContent(parPath);
        te.SelectAll();
        te.Copy();
    }

    static List<string> listParName = new List<string>();
    public static  bool FindParName(Transform trans)
    {
        
        if (trans == null)
        {
            return false;
        }
        if (trans.GetComponent<UGUIPanel>() == null)
        {
            listParName.Add(trans.name);
            FindParName(trans.parent);
            return false;
        }
        return true;

    }

输出挂载UGUIPanel的父物体下某个子物体路径

猜你喜欢

转载自blog.csdn.net/luoyikun/article/details/88029618