但不能找到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);
}
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);
}