//用於獲取全部Hierarchy中的物體,包括被禁用的物體 private List<GameObject> GetAllSceneObjectsWithInactive() { var allTransforms = Resources.FindObjectsOfTypeAll(typeof(Transform)); var previousSelection = Selection.objects; Selection.objects = allTransforms.Cast<Transform>() .Where(x => x != null) .Select(x => x.gameObject) //若是你只想獲取全部在Hierarchy中被禁用的物體,反註釋下面代碼 //.Where(x => x != null && !x.activeInHierarchy) .Cast<UnityEngine.Object>().ToArray(); var selectedTransforms = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab); Selection.objects = previousSelection; return selectedTransforms.Select(tr => tr.gameObject).ToList(); }