private static void RemoveBrokenEntityReferences(UnityEngine.SceneManagement.Scene scene) { if (!scene.isLoaded || !scene.IsValid()) { return; } using (var pooledToDelete = ListPool <EntityReference> .GetDisposable()) using (var pooledRoots = ListPool <GameObject> .GetDisposable()) { var toDelete = pooledToDelete.List; var roots = pooledRoots.List; scene.GetRootGameObjects(roots); foreach (var root in roots) { using (var pooledReferences = ListPool <EntityReference> .GetDisposable()) { var references = pooledReferences.List; root.GetComponentsInChildren(true, references); toDelete.AddRange(references.Where(r => r.Guid == Guid.Empty)); } } Delete(toDelete); } }
public static void LoadDynamicChildInScene(UnityEngine.SceneManagement.Scene scene) { var gos = scene.GetRootGameObjects(); if (gos != null) { for (int i = 0; i < gos.Length; ++i) { var go = gos[i]; if (go) { var pars = go.GetComponentsInChildren <DynamicPrefab>(false); if (pars != null) { for (int j = 0; j < pars.Length; ++j) { var par = pars[j]; if (par) { par.LoadDynamicChild(); } } } } } } }
private static GameObject _CreateUIRoot() { bool bNeedLoad = true; UnityEngine.SceneManagement.Scene currScene = EditorSceneManager.GetActiveScene(); if (currScene != null && currScene.path == ms_strUIEditorScenePath) { bNeedLoad = false; } if (bNeedLoad) { UnityEngine.SceneManagement.Scene scene = EditorSceneManager.OpenScene(ms_strUIEditorScenePath); GameObject[] arrObjs = scene.GetRootGameObjects(); for (int i = 0; i < arrObjs.Length; ++i) { GameObject.DestroyImmediate(arrObjs[i], true); arrObjs[i] = null; } arrObjs = null; } GameObject objRoot = GameObject.Find("UIRoot(Clone)"); if (objRoot == null) { Object objRootTemplate = Resources.Load("Engine/Prefab/UIRoot"); objRoot = Object.Instantiate(objRootTemplate) as GameObject; } return(objRoot); }
/// <summary> /// Returns the <see cref="TinyContainer"/> configured for the scene of the MonoBehaviour. Falls back to the global instance. /// </summary> public static TinyContainer ForSceneOf(MonoBehaviour monoBehaviour) { Scene scene = monoBehaviour.gameObject.scene; if (_sceneContainers.TryGetValue(scene, out TinyContainer container) && container != monoBehaviour) { return(container); } _temporarySceneGameObjects.Clear(); scene.GetRootGameObjects(_temporarySceneGameObjects); foreach (GameObject go in _temporarySceneGameObjects) { if (go.TryGetComponent(out TinyContainerScene sceneContainer) == false) { continue; } if (sceneContainer.Container == monoBehaviour) { continue; } sceneContainer.BootstrapOnDemand(); return(sceneContainer.Container); } return(Global); }
private static void AddCollider(string path) { UnityEngine.SceneManagement.Scene scene = EditorSceneManager.OpenScene(path); RenderSettings.skybox = null; RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Trilight; AudioListener audioListener = GameObject.FindObjectOfType <AudioListener>(); if (audioListener) { GameObject.DestroyImmediate(audioListener); } //Debug.Log(scene.name); GameObject[] gs = scene.GetRootGameObjects(); foreach (GameObject g in gs) { Transform[] ts = g.GetComponentsInChildren <Transform>(); foreach (Transform t in ts) { Collider collider = t.GetComponent <Collider>(); if (collider == null && t.GetComponent <MeshRenderer>() != null) { t.gameObject.AddComponent <MeshCollider>(); } } } EditorSceneManager.SaveScene(scene); AssetDatabase.Refresh(); }
public void OnProcessScene(UnityEngine.SceneManagement.Scene scene) { // In addition to the build process, OnProcessScene is also called on the current scene // when entering playmode in the Editor, but without OnPreprocessBuild. // Since we only want to generate a link.xml when building with the IL2CPP scripting // backend, we need to check for both conditions. if (buildingPlayer && isIL2CPPBuild()) { foreach (var root in scene.GetRootGameObjects()) { foreach (var rs in root.GetComponentsInChildren <RemoteSettings>()) { DriveableProperty dp = rs.driveableProperty; AddTypesToHash(dp.fields, types); } } // OnPostprocessBuild is called after assemblies are already stripped // so we need to write the link.xml file immediately after the last scene // is processed. if (scene.path == lastActiveScene) { WriteLinkXml(types); types = null; // I can't tell the lifecycle of this class, so set this to false just in case. buildingPlayer = false; } } }
public static T FindObjectInScene <T>(string name = null) where T : MonoBehaviour { UnityEngine.SceneManagement.Scene activeScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); GameObject[] rootObjects = activeScene.GetRootGameObjects(); GameObject[] allObjects = Resources.FindObjectsOfTypeAll <GameObject>(); List <GameObject> objectsInScene = new List <GameObject>(); for (int i = 0; i < rootObjects.Length; i++) { objectsInScene.Add(rootObjects[i]); } for (int i = 0; i < allObjects.Length; i++) { if (allObjects[i].transform.root) { for (int i2 = 0; i2 < rootObjects.Length; i2++) { if (allObjects[i].transform.root == rootObjects[i2].transform && allObjects[i] != rootObjects[i2] && allObjects[i].GetComponent(typeof(T))) { if (name == null || name == allObjects[i].name) { return(allObjects[i].GetComponent <T>()); } } } } } return(null); }
public void OnProcessScene(UnityEngine.SceneManagement.Scene scene, BuildReport report) { foreach (GameObject rootGameObject in scene.GetRootGameObjects()) { foreach (var note in rootGameObject.GetComponentsInChildren <InspectorNote>()) { DestroyImmediate(note); } } }
public void OnProcessScene(UnityEngine.SceneManagement.Scene scene, BuildReport report) { bool isLWRP = GraphicsSettings.renderPipelineAsset is UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset; var rootObjects = scene.GetRootGameObjects(); foreach (var rootObj in rootObjects) { ProcessGameObject(rootObj, isLWRP); } }
public override bool TryParseIndex(string path, RangeInt cursor, out IWatchContext ctx) { if (ParserUtils.TryParseScopeSequenceRange(path, ref cursor, ParserUtils.DelemiterQuote, out var nameRangeIn, out var nameRangeOut)) { string name = path.Substring(nameRangeIn); foreach (var go in Scene.GetRootGameObjects()) { if (go.name == name) { GameObject go2 = go; ctx = new GameObjectContext(this, $"[\"{name}\"]", go, ContextFieldInfo.MakeOperator($"[\"{name}\"]")); //ctx = new PropertyPathContext<GameObject, GameObject>(this, this, $"[\"{name}\"]", ref go2, null, ContextFieldInfo.MakeOperator($"[\"{name}\"]")); //ctx = new PropertyBagContext<GameObject>(this, $"[\"{name}\"]", ref go2, ContextFieldInfo.MakeOperator($"[\"{name}\"]")); return(true); } } } ctx = default; return(false); }
public static void TraverseScenes( UnityEngine.SceneManagement.Scene scene , System.Action <UnityEngine.SceneManagement.Scene, GameObject, int> action ) { var rootGos = scene.GetRootGameObjects(); foreach (var rootGo in rootGos) { TraverseGameObjects(scene, rootGo, action, 1); } }
public static void BuildAndroidApk() { CSObjectWrapEditor.Generator.ClearAll(); AssetDatabase.Refresh(); //gen xlua CSObjectWrapEditor.Generator.GenAll(); AssetDatabase.Refresh(); //设置场景的场景的参数 string launchScenePath = "Assets/Game/Scenes/main.unity"; UnityEngine.SceneManagement.Scene activeScene = EditorSceneManager.OpenScene(launchScenePath); if (activeScene != null) { EditorSceneManager.SetActiveScene(activeScene); foreach (var item in activeScene.GetRootGameObjects()) { if (item.name.Equals("GameMode")) { GameMode gameMode = item.GetComponent <GameMode>(); gameMode.ConfigJsonData["ResourceUpdateType"] = (int)ResourceUpdateType.Update; string configPath = AssetDatabase.GetAssetPath(gameMode.ConfigAsset); File.WriteAllText(configPath, gameMode.ConfigJsonData.ToJson()); AssetDatabase.Refresh(); EditorUtility.SetDirty(gameMode); EditorSceneManager.SaveOpenScenes(); AssetDatabase.Refresh(); break; } } } //android keystore string path = Path.GetDirectoryName(Application.dataPath); string keyStorePath = Path.Combine(path, "tools/user.keystore"); PlayerSettings.Android.keystoreName = keyStorePath; PlayerSettings.Android.keystorePass = "******"; PlayerSettings.Android.keyaliasName = "********"; PlayerSettings.Android.keyaliasPass = "******"; //build apk BuildPlayerOptions playerOptions = new BuildPlayerOptions(); playerOptions.scenes = EditorBuildSettingsScene.GetActiveSceneList(EditorBuildSettings.scenes); // playerOptions.scenes = new string[] { "Assets/Core/Scenes/SampleScene.unity" }; playerOptions.target = BuildTarget.Android; playerOptions.locationPathName = "build/Android/mini.apk"; BuildPipeline.BuildPlayer(playerOptions); Debug.Log("build sccuess!"); }
private static void TrackOnSceneLoaded(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode) { if (s_SceneNames.TryGetValue(scene.name, out var loadedBundle)) { RetainBundleInternal(loadedBundle, 1); scene.GetRootGameObjects(s_SceneRootObjectCache); for (int i = 0; i < s_SceneRootObjectCache.Count; i++) { TrackIndepenantInternal(loadedBundle, s_SceneRootObjectCache[i]); } s_SceneRootObjectCache.Clear(); } }
public static GameObject FindRootGameObject(string name) { UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); GameObject[] roots = scene.GetRootGameObjects(); for (int i = 0; i < roots.Length; i++) { if (roots[i].name == name) { return(roots[i]); } } return(null); }
private void LoadUnityScratchPadScene() { if ((!m_Scene.isLoaded || !m_Scene.IsValid()) && !Bridge.EditorApplication.IsQuitting) { m_Scene = GetOrGenerateScratchPad(); } // Make sure the scratch pad is clean if we somehow have saved gameObjects. foreach (var obj in m_Scene.GetRootGameObjects()) { Object.DestroyImmediate(obj); } }
public void onSceneLoaded(UnityEngine.SceneManagement.Scene arg0, UnityEngine.SceneManagement.LoadSceneMode arg1) { currentMapBase = new GameObject("mapRoot"); GameObject[] rootObjs = arg0.GetRootGameObjects(); foreach (GameObject roots in rootObjs) { roots.transform.SetParent(currentMapBase.transform, true); } onMapInit.Invoke(currentMapBase, currentAvailMapLoad); }
static public T[] SearchScene <T>(UnityEngine.SceneManagement.Scene scene, bool searchInActiveGameObjects) where T : Component { var gos = scene.GetRootGameObjects(); var list = new FastList <T>(); foreach (var go in gos) { list.AddRange(SearchParent <T>(go, searchInActiveGameObjects)); } return(list.ToArray()); }
public static GameObject[] GetStaticGameObjectsForExport(UnityEngine.SceneManagement.Scene scene) { var gameObjects = new List <GameObject>(); var roots = scene.GetRootGameObjects(); foreach (var root in roots) { gameObjects.AddRange(GetGameObjectsForExport(root, true)); } return(gameObjects.ToArray()); }
private void OnDisable() { GameRulesWindow.OnIssuesUpdated -= UpdateMiniToolbar; #if UNITY_2018_3_OR_NEWER ItemManager.ResetItemDatabaseLookup(); var rootGameObjects = (GameObject[])previewScene.GetRootGameObjects().Clone(); foreach (var go in rootGameObjects) { UnityEngine.Object.DestroyImmediate(go); } #endif }
private static void ScanScene(UnityEngine.SceneManagement.Scene scene) { NGSpotlightWindow.DeleteKey(scene.path); if (scene.isLoaded == true) { scene.GetRootGameObjects(ScenesImporter.roots); for (int j = 0; j < ScenesImporter.roots.Count; j++) { ScenesImporter.BrowseGameObject(scene.path, ScenesImporter.roots[j]); } } }
public static List <T> GetComponentsInScene <T>(UnityEngine.SceneManagement.Scene scene, bool includeInactive) where T : Component { var res = new List <T>(); var rootObjects = scene.GetRootGameObjects(); for (var i = 0; i < rootObjects.Length; i++) { var rootObject = rootObjects[i]; var components = rootObject.GetComponentsInChildren <T>(includeInactive); res.AddRange(components); } return(res); }
public static T GetTopObject <T>(string name) { UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); GameObject[] rootObjs = scene.GetRootGameObjects(); for (int i = 0; i < rootObjs.Length; i++) { GameObject obj = rootObjs[i]; if (obj.name == name) { return(obj.GetComponent <T>()); } } return(default(T)); }
void IProcessSceneWithReport.OnProcessScene(UnityEngine.SceneManagement.Scene scene, BuildReport report) { var rootGameObjects = scene.GetRootGameObjects(); for (int i = 0; i < rootGameObjects.Length; i++) { var gameObject = rootGameObjects[i]; var sceneComponents = gameObject.GetComponents <Component>(); ProcessComponents(sceneComponents); var childComponents = gameObject.GetComponentsInChildren <Component>(true); ProcessComponents(childComponents); } }
/// <summary> /// 设置场景激活状态 /// </summary> /// <param name="sceneName"></param> /// <param name="isActive"></param> public static void SetSceneActive(string sceneName, bool isActive) { int currentLoadedSceneCount = UnityEngine.SceneManagement.SceneManager.sceneCount; for (int i = 0; i < currentLoadedSceneCount; ++i) { UnityEngine.SceneManagement.Scene loadedScene = UnityEngine.SceneManagement.SceneManager.GetSceneAt(i); if (loadedScene.name == sceneName) { GameObject[] sceneRootObjects = loadedScene.GetRootGameObjects(); SetGameObjectsActive(sceneRootObjects, isActive); break; } } }
void AddMixerToAudioSourcesOnSceneLoad(UnityEngine.SceneManagement.Scene scene, UnityEngine.SceneManagement.LoadSceneMode mode) { if (!autoAddMixerOnSceneLoad) { return; } foreach (var rootGO in scene.GetRootGameObjects()) { var emptyMixerSources = rootGO.GetComponentsInChildren <AudioSource>(true).Where(x => x != null && x.outputAudioMixerGroup == null).ToList(); foreach (AudioSource source in emptyMixerSources) { source.outputAudioMixerGroup = audioMixer.outputAudioMixerGroup; } } }
public static void CheckValidEventRefs(UnityEngine.SceneManagement.Scene scene) { foreach (var gameObject in scene.GetRootGameObjects()) { MonoBehaviour[] allBehaviours = gameObject.GetComponentsInChildren <MonoBehaviour>(); foreach (MonoBehaviour behaviour in allBehaviours) { if (behaviour != null) { Type componentType = behaviour.GetType(); FieldInfo[] fields = componentType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (FieldInfo item in fields) { if (HasAttribute(item, typeof(EventRefAttribute))) { if (item.FieldType == typeof(string)) { string output = item.GetValue(behaviour) as string; if (!IsValidEventRef(output)) { Debug.LogWarningFormat("FMOD Studio: Unable to find FMOD Event \"{0}\" in scene \"{1}\" at path \"{2}\" \n- check the FMOD Studio event paths are set correctly in the Unity editor", output, scene.name, GetGameObjectPath(behaviour.transform)); } } else if (typeof(IEnumerable).IsAssignableFrom(item.FieldType)) { foreach (var listItem in (IEnumerable)item.GetValue(behaviour)) { if (listItem.GetType() == typeof(string)) { string listOutput = listItem as string; if (!IsValidEventRef(listOutput)) { Debug.LogWarningFormat("FMOD Studio: Unable to find FMOD Event \"{0}\" in scene \"{1}\" at path \"{2}\" \n- check the FMOD Studio event paths are set correctly in the Unity editor", listOutput, scene.name, GetGameObjectPath(behaviour.transform)); } } } } } } } } } }
public void OnProcessScene(UnityEngine.SceneManagement.Scene scene) { if (!sawManager) { if (scene.isLoaded) { foreach (var gameObject in scene.GetRootGameObjects()) { if (gameObject.GetComponentInChildren <PolyToolkitManager>() != null) { sawManager = true; break; } } } } }
static StackObject *GetRootGameObjects_11(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method); UnityEngine.SceneManagement.Scene instance_of_this_method = (UnityEngine.SceneManagement.Scene) typeof(UnityEngine.SceneManagement.Scene).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); var result_of_this_method = instance_of_this_method.GetRootGameObjects(); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method); __intp.Free(ptr_of_this_method); return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method)); }
private static SceneHierarchy PrepareSceneHierarchy(UnityScene scene, bool includeInactive) { var sceneGuid = Guid.NewGuid().ToString(); var res = new SceneHierarchy(sceneGuid, scene.name, MATRIX_IDENTITY); var rootGameObjects = scene.GetRootGameObjects(); for (int i = 0; i < rootGameObjects.Length; i++) { var rootObject = rootGameObjects[i]; if (!includeInactive && !rootObject.activeInHierarchy) { continue; } FillChildrenRecursive(rootObject.transform, res.Children); } return(res); }
public static GameObject getGameObjectByIndexPath(string path) { if (path == null) { return(null); } var ss = path.Split(';'); List <int> indexPath = new List <int>(); foreach (string s in ss) { try { indexPath.Add(int.Parse(s)); } catch (System.Exception) { Debug.LogError("Get GameObject By IndexPath Failed!."); return(null); } } UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); GameObject result = null; if (scene.isLoaded) { var allGameObjects = scene.GetRootGameObjects(); result = allGameObjects[indexPath[0]]; for (int i = 1; i < indexPath.Count; ++i) { if (indexPath[i] < 0 || indexPath[i] >= result.transform.childCount) { return(null); } result = result.transform.GetChild(indexPath[i]).gameObject; } } return(result); }