标签:root gets soft oftype ++ rem form obj cts
private GameObject[] getDontDestroyOnLoadGameObjects(){
var allGameObjects=new List<GameObject>();
allGameObjects.AddRange(FindObjectsOfType<GameObject>());
//移除所有场景包含的对象
for(var i=0;i<SceneManager.sceneCount;i++){
var scene=SceneManager.GetSceneAt(i);
var objs=scene.GetRootGameObjects();
for(var j=0;j<objs.Length;j++){
allGameObjects.Remove(objs[j]);
}
}
//移除父级不为null的对象
int k=allGameObjects.Count;
while(--k>=0){
if(allGameObjects[k].transform.parent!=null){
allGameObjects.RemoveAt(k);
}
}
return allGameObjects.ToArray();
}
unity 获取DontDestroyOnLoad的游戏对象
标签:root gets soft oftype ++ rem form obj cts
原文地址:https://www.cnblogs.com/kingBook/p/11000701.html