unity 查找root节点

来源:互联网 发布:泰国国王科技大学知乎 编辑:程序博客网 时间:2024/06/08 19:17

  但不能找到active false    

  foreach (GameObject obj in UnityEngine.Object.FindObjectsOfType(typeof(GameObject)))

        {
            if (obj.transform.parent == null)
            {
                Debug.LogError(obj.name);
            }

        } 


即使隐藏root节点gameObject也能进行查找的方法

GameObject[] pAllObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject));


 foreach (GameObject pObject in pAllObjects)
  {
     if (pObject.transform.parent != null)
     {
       continue;
      }

    if (pObject.hideFlags == HideFlags.NotEditable || pObject.hideFlags == HideFlags.HideAndDontSave)
      {
       continue;
      }

      if (Application.isEditor)
      {
       string sAssetPath = AssetDatabase.GetAssetPath(pObject.transform.root.gameObject);
        if (!string.IsNullOrEmpty(sAssetPath))
         {
            continue;
           }
      }

                Debug.Log(pObject.name);
      }

原创粉丝点击