Returns all the root game objects in the scene.
private IEnumerator AnalyzeBundleScene(UnityEngine.SceneManagement.Scene scene) { yield return(new WaitForEndOfFrame()); UnityEngine.SceneManagement.Scene defaultScene = SceneManager.GetActiveScene(); SceneManager.SetActiveScene(scene); BundleSceneInfo info = m_BundleSceneInfos.Peek(); if (info.sceneName != scene.name) { Debug.LogError("What's scene? " + scene.path); yield break; } AssetBundleFilesAnalyze.AnalyzeObjectReference(info.fileInfo, RenderSettings.skybox); GameObject[] gos = scene.GetRootGameObjects(); foreach (var go in gos) { AssetBundleFilesAnalyze.AnalyzeObjectComponent(info.fileInfo, go); } AssetBundleFilesAnalyze.AnalyzeObjectsCompleted(info.fileInfo); SceneManager.SetActiveScene(defaultScene); info.ab.Unload(true); info.ab = null; SceneManager.UnloadScene(scene); }
private void setupGameUI(Scene scene, SceneMode mode) { string title = this.getLevelName(": "); foreach (GO go in scene.GetRootGameObjects()) { UiText[] txts = go.GetComponentsInChildren <UiText>(); foreach (UiText txt in txts) { this.issueEvent <MinionCountIface>( (x, y) => x.GetText(out this.minionCountTxt), txt.gameObject); if (this.minionCountTxt == null) { /* Not the minion count text, therefore(?) the title */ txt.text = title; } else if (this.minionCount == 0) { /* No minions in this level, just hide the display */ UnityEngine.Transform txtT = this.minionCountTxt.transform; GO txtParent = txtT.parent.gameObject; txtParent.SetActive(false); } else { /* This level has minions! Update the text */ this.updateMinionText(); } } } }
private static List <GameObject> GetDontDestroyOnLoadRoots() { List <GameObject> objs = new List <GameObject>(); if (Application.isPlaying) { GameObject temp = null; try { temp = new GameObject(); DontDestroyOnLoad(temp); UnityEngine.SceneManagement.Scene dontDestryScene = temp.scene; DestroyImmediate(temp); temp = null; if (dontDestryScene.IsValid()) { objs = dontDestryScene.GetRootGameObjects().ToList(); } } catch (System.Exception e) { Debug.LogException(e); return(null); } finally { if (temp != null) { DestroyImmediate(temp); } } } return(objs); }
/// <summary> /// 得到场景的大小 /// </summary> private void CheckSceneInfo(ref Vector3 minPos, ref Vector3 maxPos) { List <Collider> list = new List <Collider>(); GameObject[] ArrRoot = scene.GetRootGameObjects(); for (int i = 0; i < ArrRoot.Length; ++i) { if (ArrRoot[i].layer == LayerMask.NameToLayer("Floor")) { Collider[] arrCollider = ArrRoot[i].GetComponentsInChildren <Collider>(); for (int j = 0; j < arrCollider.Length; ++j) { list.Add(arrCollider[j]); } } } if (list.Count > 0) { Bounds groundBound = new Bounds(Vector3.zero, Vector3.zero); for (int i = 0; i < list.Count; i++) { groundBound.Encapsulate(list[i].bounds); } minPos = groundBound.min; maxPos = groundBound.max; } }
static private void HandleOneScene(string assetsPath) { UnityEngine.SceneManagement.Scene s = EditorSceneManager.OpenScene(assetsPath); GameObject goFrom = null; GameObject goTo = null; GameObject[] gos = s.GetRootGameObjects(); foreach (GameObject go in gos) { if (go.name == MonstersNodeName) { goFrom = go; } else if (go.name == ConfigsNodeName) { goTo = go; } } if (goFrom != null) { if (goTo != null) { GameObject.DestroyImmediate(goTo); } goTo = new GameObject(ConfigsNodeName); goTo.transform.localScale = Vector3.one; goTo.transform.localPosition = Vector3.zero; goTo.transform.localEulerAngles = Vector3.zero; TransferGo(goFrom, goTo); EditorSceneManager.SaveScene(s); } }
static int GetRootGameObjects(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 1) { UnityEngine.SceneManagement.Scene obj = (UnityEngine.SceneManagement.Scene)ToLua.CheckObject(L, 1, typeof(UnityEngine.SceneManagement.Scene)); UnityEngine.GameObject[] o = obj.GetRootGameObjects(); ToLua.Push(L, o); ToLua.SetBack(L, 1, obj); return(1); } else if (count == 2) { UnityEngine.SceneManagement.Scene obj = (UnityEngine.SceneManagement.Scene)ToLua.CheckObject(L, 1, typeof(UnityEngine.SceneManagement.Scene)); System.Collections.Generic.List <UnityEngine.GameObject> arg0 = (System.Collections.Generic.List <UnityEngine.GameObject>)ToLua.CheckObject(L, 2, typeof(System.Collections.Generic.List <UnityEngine.GameObject>)); obj.GetRootGameObjects(arg0); ToLua.SetBack(L, 1, obj); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.SceneManagement.Scene.GetRootGameObjects")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
// Find all assets void OnWizardOtherButton() { List <ParticleEmitter> results = new List <ParticleEmitter>(); for (int i = 0; i < EditorSceneManager.sceneCount; i++) { UnityEngine.SceneManagement.Scene scene = EditorSceneManager.GetSceneAt(i); GameObject[] roots = scene.GetRootGameObjects(); foreach (GameObject root in roots) { ParticleEmitter[] emitters = root.GetComponentsInChildren <ParticleEmitter>(true); results.AddRange(emitters); } } components = results.ToArray(); string[] prefabGUIDs = AssetDatabase.FindAssets("t:ParticleEmitter"); prefabs = new ParticleEmitter[prefabGUIDs.Length]; for (int i = 0; i < prefabGUIDs.Length; i++) { prefabs[i] = AssetDatabase.LoadAssetAtPath <GameObject>(AssetDatabase.GUIDToAssetPath(prefabGUIDs[i])).GetComponent <ParticleEmitter>(); } UpgradeAll(); }
private IEnumerator <float> LoadScene_Coroutine(string scene, Action callback) { //Unload other scene if (currentSceneScript != null) { currentSceneScript.OnSceneStop(); UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(currentScene); currentSceneScript = null; } AsyncOperation asyncOp = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(scene, UnityEngine.SceneManagement.LoadSceneMode.Additive); yield return(Timing.WaitUntilDone(asyncOp)); currentScene = UnityEngine.SceneManagement.SceneManager.GetSceneByName(scene); GameObject sceneGO = currentScene.GetRootGameObjects().Where((arg1) => arg1.GetComponentInChildren <BRScene>() != null).FirstOrDefault(); if (sceneGO != null) { currentSceneScript = sceneGO.GetComponentInChildren <BRScene>(); } else { Debug.LogException(new SceneManagerLoadException(scene, "Scene does not have a root object with a script extending BRScene...")); } callback?.Invoke(); }
/// <summary> /// 分析当前场景的数据信息 /// </summary> void AnalyzeCurrentScene() { string root_name = ED_SceneManagement.EditorSceneManager.GetActiveScene().name; EN_SceneManagement.Scene scene = ED_SceneManagement.EditorSceneManager.GetActiveScene(); GameObject[] gobjs = scene.GetRootGameObjects(); SceneGroupObjInfo scene_group_info = new SceneGroupObjInfo(scene.name); for (int j = 0; j < gobjs.Length; j++) { GameObject root_obj = gobjs[j]; Transform root_tran = root_obj.transform; GroupObjInfo group_obj_info = new GroupObjInfo(null, scene_group_info); for (int i = 0; i < root_tran.childCount; i++) { Transform child = root_tran.GetChild(i); if (child.gameObject.activeSelf) { AnalyzeGroup(group_obj_info, child); } } scene_group_info.Add_Group_Info(group_obj_info); } scene_group_obj_info = scene_group_info; }
public static List <T> GetAllComponents <T>(UScene scene, bool allowAtEditTime = false) { if (!Application.isPlaying && !allowAtEditTime) { throw new ArgumentException("Allow At EditTime arguments is false, please note that changes to components made at runtime will most likely be non-revertable, set the argument as true if you are sure of what you are doing and make a backup of you scene first !"); } List <T> list = new List <T>(); if (scene.isLoaded) { var roots = scene.GetRootGameObjects(); for (int y = 0; y < roots.Length; y++) { list.AddRange(roots[y].GetNestedComponents <T>()); } } else { Debug.LogError(MoeTools.String.Enclose(scene.name) + " must be loaded to be able to get its components"); } return(list); }
static private void HandleOneSceneBack(string assetsPath) { UnityEngine.SceneManagement.Scene s = EditorSceneManager.OpenScene(assetsPath); GameObject goFrom = null; GameObject goTo = null; GameObject[] gos = s.GetRootGameObjects(); foreach (GameObject go in gos) { if (go.name == MonstersNodeName) { goFrom = go; } else if (go.name == ConfigsNodeName) { goTo = go; } } if (goFrom != null) { BackGo(goFrom, goTo); EditorSceneManager.SaveScene(s); } }
public static void shaderToLightmap() { UnityEngine.SceneManagement.Scene s = EditorSceneManager.GetActiveScene(); GameObject[] objs = s.GetRootGameObjects(); for (int k = 0; k < objs.Length; k++) { GameObject go = objs[k]; MeshRenderer[] meshRds = go.GetComponentsInChildren <MeshRenderer>(); for (int i = 0; i < meshRds.Length; i++) { //检测MeshRenderer组件 changeToLightmapShader(meshRds[i]); } SkinnedMeshRenderer[] skinedMeshRds = go.GetComponentsInChildren <SkinnedMeshRenderer>(); for (int i = 0; i < skinedMeshRds.Length; i++) { //检测MeshRenderer组件 changeToLightmapShader(skinedMeshRds[i]); } } EditorSceneManager.SaveScene(s); foreach (KeyValuePair <GameObject, bool> item in _dic_is_static) { item.Key.isStatic = item.Value; } _dic_is_static.Clear(); }
public static void shaderToDiffuse() { _dic_is_static.Clear(); UnityEngine.SceneManagement.Scene s = EditorSceneManager.GetActiveScene(); GameObject[] objs = s.GetRootGameObjects(); for (int k = 0; k < objs.Length; k++) { GameObject go = objs[k]; if (go.name == "Scene") { SetAllChildrenStatic(go, false); MeshRenderer[] meshRds = go.GetComponentsInChildren <MeshRenderer>(); for (int i = 0; i < meshRds.Length; i++) { //检测MeshRenderer组件 changeToDiffuseShader(meshRds[i]); } SkinnedMeshRenderer[] skinedMeshRds = go.GetComponentsInChildren <SkinnedMeshRenderer>(); for (int i = 0; i < skinedMeshRds.Length; i++) { //检测MeshRenderer组件 changeToDiffuseShader(skinedMeshRds[i]); } } } EditorSceneManager.SaveScene(s); }
public void initSceneInteractiveObjects(UnityEngine.SceneManagement.Scene scene, GameObject[] rootObjects = null) { if (rootObjects == null) { rootObjects = scene.GetRootGameObjects(); } initInteractiveObjects(scene.name, rootObjects); }
private void InitialOneScene(UnityEngine.SceneManagement.Scene scene) { GameObject[] roots = scene.GetRootGameObjects(); int c1 = 0; int c2 = 0; int c3 = 0; int total = 0; for (int i = 0; i < roots.Length; i++) { GameObject obj = roots[i]; UnityEngine.Terrain t = obj.GetComponent <UnityEngine.Terrain>(); if (t == null) { Transform[] trans = obj.GetComponentsInChildren <Transform>(true); for (int j = 0; j < trans.Length; j++) { GameObject child = trans[j].gameObject; Vector2 pos = new Vector2(trans[j].position.x, trans[j].position.z); if (Math.Abs(pos.x) < 4000 && Math.Abs(pos.y) < 4000 && pos.magnitude > 1) { try { if (child.name.StartsWith("Prop") || child.name.ToLower().StartsWith("stone") || child.name.StartsWith("prop")) { if (child.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.SmallthingNear)) { smallMap.Insert(child, pos); c1++; } else { MidMap.Insert(child, pos); c2++; } } else { map.Insert(child, pos); c3++; } //child.SetActive(false); total++; } catch (Exception e) { _logger.ErrorFormat("culling insert error {0}", e.Message); } } } } } _logger.InfoFormat("culling insert t={4}, s={0},m={1},b={2} at scene {3}", c1, c2, c3, scene.name, total); }
public void OnProcessScene(UnityEngine.SceneManagement.Scene scene) { string path = EditorUserBuildSettings.GetBuildLocation(EditorUserBuildSettings.activeBuildTarget); int last_slash = path.LastIndexOf('/'); string pointCloudDirectory = path.Substring(0, last_slash + 1); foreach (var gameObject in scene.GetRootGameObjects()) { PlayableDirector director = gameObject.GetComponent <PlayableDirector>(); if (director != null) { if (director.playableAsset != null) { TimelineAsset timeline = (TimelineAsset)director.playableAsset; foreach (var track in timeline.GetOutputTracks()) { foreach (var clip in track.GetClips()) { if (clip.asset.GetType() == typeof(PointCloudClip)) { uint clip_start_frame = (uint)clip.clipIn * 30; uint clip_duration_in_frames = (uint)clip.duration * 30; uint clip_end_frame = clip_start_frame + clip_duration_in_frames; string[] files = new string[0]; PointCloudClip pcc = (PointCloudClip)clip.asset; if (Directory.Exists(pcc.template.PointCloudDirectory.Substring(1))) { files = Directory.GetFiles(pcc.template.PointCloudDirectory.Substring(1)); } foreach (var file in files) { Directory.CreateDirectory(pointCloudDirectory + pcc.template.PointCloudDirectory); int last_dot_in_filename = file.LastIndexOf('.'); int last_slash_in_filename = file.LastIndexOf('\\'); int no_length = last_dot_in_filename - last_slash_in_filename - 1; uint file_no = UInt32.Parse(file.Substring(last_slash_in_filename + 1, no_length)); if (file_no >= clip_start_frame && file_no <= clip_end_frame) { if (!File.Exists(pointCloudDirectory + '/' + file)) { File.Copy(file, pointCloudDirectory + '/' + file); } } } } } } } } } }
private void DoCount() { meshCount = 0; hasData = true; foreach (GameObject go in currentScene.GetRootGameObjects()) { CheckForMesh(go); } }
internal void DisablePickingNoUndo(Scene scene) { if (!scene.IsValid()) { return; } SceneVisibilityState.EnablePicking(scene); SceneVisibilityState.SetGameObjectsPickingDisabled(scene.GetRootGameObjects(), true, true); }
private void HideNoUndo(Scene scene) { if (!scene.IsValid()) { return; } SceneVisibilityState.ShowScene(scene); SceneVisibilityState.SetGameObjectsHidden(scene.GetRootGameObjects(), true, true); }
public static void EnumRootObject(EnumTransform cb, object param = null) { UnityEngine.SceneManagement.Scene s = SceneManager.GetActiveScene(); GameObject[] roots = s.GetRootGameObjects(); for (int i = 0, imax = roots.Length; i < imax; ++i) { Transform t = roots[i].transform; cb(t, param); } }
public static NetworkManagerSpecific GetLanManager() { GameObject temp = null; temp = new GameObject(); Object.DontDestroyOnLoad(temp); UnityEngine.SceneManagement.Scene dontDestroyOnLoad = temp.scene; GameObject[] g = dontDestroyOnLoad.GetRootGameObjects(); int position = 0; for (int i = 0; i < dontDestroyOnLoad.rootCount; i++) { if (g[i].name == "NetworkManagerController") { position = i; break; } } return(dontDestroyOnLoad.GetRootGameObjects()[position].GetComponent <NetworkManagerSpecific>()); }
/// <summary> /// Returns all root objects of the scene. List is empty if scene is not loaded /// </summary> /// <param name="sceneID"></param> /// <returns></returns> public List <GameObject> GetSceneRootObjects(string sceneID) { if (IsSceneLoaded(sceneID)) { UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetSceneByName(sceneID); return(new List <GameObject>(scene.GetRootGameObjects())); } else { return(new List <GameObject>()); } }
public void OnProcessScene(UnityEngine.SceneManagement.Scene scene, BuildReport report) { // Get all root objects in the scene. foreach (GameObject go in scene.GetRootGameObjects()) { // Get all MapObject components for each root object foreach (MapObject mapObject in go.GetComponentsInChildren <MapObject>()) { GameObject.DestroyImmediate(mapObject); // Remove it } } }
private void DestroyDontDestroy() { GameObject temp = new GameObject(); UnityEngine.Object.DontDestroyOnLoad(temp); UnityEngine.SceneManagement.Scene dontDestroyOnLoad = temp.scene; GameObject[] g = dontDestroyOnLoad.GetRootGameObjects(); for (int i = 0; i < dontDestroyOnLoad.rootCount; i++) { Destroy(g[i]); } }
private SceneBase GetSceneBase(UnityEngine.SceneManagement.Scene scene) { SceneBase uiSceneBase = null; foreach (GameObject obj in scene.GetRootGameObjects()) { uiSceneBase = obj.GetComponent <SceneBase>(); if (uiSceneBase != null) { return(uiSceneBase); } } foreach (GameObject obj in scene.GetRootGameObjects()) { uiSceneBase = obj.GetComponentInChildren <SceneBase>(); if (uiSceneBase != null) { return(uiSceneBase); } } return(null); }
private int GetAllChildCount(UnityEngine.SceneManagement.Scene scene) { int c = 0; GameObject[] roots = scene.GetRootGameObjects(); for (int i = 0; i < roots.Length; i++) { GameObject obj = roots[i]; c += obj.GetComponentsInChildren <Transform>(true).Length; } return(c); }
public bool IsPickingDisabled(Scene scene) { scene.GetRootGameObjects(m_RootBuffer); foreach (var rootGameObject in m_RootBuffer) { if (!SceneVisibilityState.IsHierarchyPickingDisabled(rootGameObject)) { return(false); } } return(true); }
public static bool GetComponentSingle <T>(this UnityEngine.SceneManagement.Scene s, out T component) { foreach (GameObject rootGameObject in s.GetRootGameObjects()) { component = rootGameObject.GetComponentInChildren <T>(); if (component != null) { return(true); } } component = default(T); return(false); }
public void TrackSceneLoaded(string sceneName) { if (!_enableTracking) { return; } UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); GameObject[] roots = scene.GetRootGameObjects(); for (int i = 0; i < roots.Length; i++) { TrackSyncRequest(roots[i], sceneName + ".unity"); } }
public void TrackSceneLoaded(string sceneName) { UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); if (scene == null) { return; } GameObject[] roots = scene.GetRootGameObjects(); for (int i = 0; i < roots.Length; i++) { TrackSyncRequest(roots[i], "[scene]: " + sceneName); } }
private void SwitchToCameraInScene(Scene scene) { foreach (Camera camera in Camera.allCameras) { camera.enabled = false; camera.gameObject.SetActive(false); } if (scene.isLoaded) { foreach (GameObject root in scene.GetRootGameObjects()) { Camera camera = root.GetComponent<Camera>(); if (camera != null) { camera.gameObject.SetActive(true); camera.enabled = true; } } } }
void SelectContext(Scene scene) { var rootObjects = scene.GetRootGameObjects(); var sceneContexts = rootObjects .SelectMany(x => x.GetComponentsInChildren<SceneContext>()).FirstOrDefault(); if (sceneContexts != null) { Selection.activeGameObject = sceneContexts.gameObject; } else { var decoratorContexts = rootObjects .SelectMany(x => x.GetComponentsInChildren<SceneDecoratorContext>()).FirstOrDefault(); if (decoratorContexts != null) { Selection.activeGameObject = decoratorContexts.gameObject; } } }
private void fetchSpritesFromScene(Scene scene) { scene.GetRootGameObjects().ForEach((rootObject) => { fetchSpriteWithScenePath(SpriteToolFormatter.ScenePath(scene), rootObject); }); }