// Start is called before the first frame update public void Start() { if (Application.isEditor) { #if UNITY_EDITOR if (EditorApplication.isPlayingOrWillChangePlaymode) { for (int j = 0; j < scenes.Length; j++) { LoadSceneParameters parameters = new LoadSceneParameters(); parameters.loadSceneMode = LoadSceneMode.Additive; SceneManager.UnloadSceneAsync(scenes[j]); EditorSceneManager.LoadSceneInPlayMode(scenes[j].ScenePath, parameters); } } else { for (int j = 0; j < scenes.Length; j++) { EditorSceneManager.OpenScene(scenes[j].ScenePath, OpenSceneMode.Additive); } } #endif } else { for (int j = 0; j < scenes.Length; j++) { SceneManager.LoadScene(scenes[j], LoadSceneMode.Additive); } } }
public static void LoadScenesInPlayMode(IReadOnlyList <string> scenePaths) { Assert.IsNotNull(scenePaths, "scenePaths != null"); Assert.IsTrue(scenePaths.Count > 0, "scenePaths.Length > 0"); var loadFirstAsSingle = true; for (var i = 0; i < SceneManager.sceneCount; i++) { var scene = SceneManager.GetSceneAt(i); if (scene.buildIndex != 0) { loadFirstAsSingle = false; break; } } for (var i = 0; i < scenePaths.Count; i++) { var path = scenePaths[i]; var loadSceneParameters = new LoadSceneParameters( loadFirstAsSingle && i == 0 ? LoadSceneMode.Single : LoadSceneMode.Additive); EditorSceneManager.LoadSceneInPlayMode(path, loadSceneParameters); } }
void LoadEnvScene() { for (int i = 0; i < SceneManager.sceneCount; i++) { var s = SceneManager.GetSceneAt(i); if (s.name == _environmentScene) { return; } } var loadedLevel = SceneManager.GetSceneByName(_environmentScene); if (!loadedLevel.isLoaded) { #if UNITY_EDITOR var lsp = new LoadSceneParameters() { loadSceneMode = LoadSceneMode.Additive, localPhysicsMode = LocalPhysicsMode.Physics3D }; EditorSceneManager.LoadSceneInPlayMode("Assets/Crest/Crest-Examples/PirateCove/Scenes/SubScenes/" + _environmentScene + ".unity", lsp); #else SceneManager.LoadScene(_environmentScene, LoadSceneMode.Additive); #endif } }
public void LoadScene(string scenePath, bool isAdditive) { scenePath = FormatScenePath(scenePath); LoadSceneParameters param = new LoadSceneParameters(isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single); EditorSceneManager.LoadSceneInPlayMode(scenePath, param); }
/// <summary> /// 同步加载场景 /// </summary> /// <param name="abName"></param> /// <param name="sceneName"></param> /// <param name="loadSceneMode"></param> /// <returns></returns> public static bool LoadSceneSync(string abName, string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single) { #if UNITY_EDITOR // 是否设置了使用assetbundle资源 if (AssetBundleFramework.DeveloperSetting.GetUseAssetBundleAsset()) { bool result = AssetBundleFramework.AssetBundleMgr.Instance.LoadBundleSync(abName) != null; SceneManager.LoadScene(sceneName, loadSceneMode); return(result); } else { // 根据包名获取资源路径,因为后缀名可能不一样所以获取的是数组 string[] paths = AssetDatabase.GetAssetPathsFromAssetBundle(abName); if (paths.Length == 0) { Debug.LogError("AB包路径有误:" + abName); return(false); } LoadSceneParameters param = new LoadSceneParameters(loadSceneMode); EditorSceneManager.LoadSceneInPlayMode(paths[0], param); return(true); } #else bool result = AssetBundleFramework.AssetBundleMgr.Instance.LoadBundleSync(abName) != null; SceneManager.LoadScene(sceneName, loadSceneMode); return(result); #endif }
public IEnumerator HarvestTest() { // load the test scene EditorSceneManager.LoadSceneInPlayMode ( "Assets/Resources/Scenes/Test_Scene.unity", new LoadSceneParameters(LoadSceneMode.Single, LocalPhysicsMode.Physics2D) ); yield return(TestUtilities.AssertSceneLoaded("Assets/Resources/Scenes/Test_Scene.unity")); Inventory inventory = Object.FindObjectOfType <Inventory>(); NodeGrid grid = Object.FindObjectOfType <NodeGrid>(); LoadingOrder loadingOrder = Object.FindObjectOfType <LoadingOrder>(); ItemType itemType = Resources.Load("SO/Potato") as ItemType; // wait till grid is loaded while (!grid.LoadedSection) { yield return(null); } // wait till all data is loaded while (!loadingOrder.LoadedAll) { yield return(null); } if (itemType == null) { Debug.LogError("There is no ItemType scriptable object at path: SO/Potato"); } // get the node we are going to plant on Node nodeToPlant = grid.GetNodeFromXY(0, 0); // plant the prefab bool succesfulPlanting = false; nodeToPlant.Interactable.OnInteract(ToolTypes.Hoe); nodeToPlant.Interactable.OnInteract(ToolTypes.Other, prefab, () => succesfulPlanting = true); Assert.IsTrue(succesfulPlanting); // get the single plant we made in this scene Plantable plant = Object.FindObjectOfType <Plantable>(); // Harvest the plant plant.Grow(completeGrowth); plant.OnHarvest(ToolTypes.Sickle, null); // check if the items dropped WorldItem[] worldItems = Object.FindObjectsOfType <WorldItem>(); Assert.IsTrue(worldItems.Length >= 2 && worldItems.Length <= 5); yield return(null); // plant object should be destroyed Assert.IsTrue(plant == null); }
public IEnumerator _03_CameraExistsInScene() { EditorSceneManager.LoadSceneInPlayMode(asteroidsScenePath, loadSceneParameters); yield return(null); Assert.IsTrue(Object.FindObjectOfType <Camera>().name == "Camera"); }
public IEnumerator _03_GameManagerExistsInScene() { EditorSceneManager.LoadSceneInPlayMode(asteroidsScenePath, loadSceneParameters); yield return(null); Assert.NotNull(Object.FindObjectOfType <GameManager>()); }
public static void LoadLevelAdditiveInPlayMode(string path) { LoadSceneParameters parameters = new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive }; EditorSceneManager.LoadSceneInPlayMode(path, parameters); }
public void LoadScene(string sceneName, LoadSceneMode mode) { Log.Trace("[ilib-abloader] EditorContainer {0}, LoadScene {1}. mode{2}", m_Name, sceneName, mode); var paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(m_Name, sceneName); if (paths.Length == 0) { return; } LoadSceneParameters parameters = new LoadSceneParameters(mode); EditorSceneManager.LoadSceneInPlayMode(paths[0], parameters); }
public IEnumerator UnitySetUp() { const string mainScenePath = "Assets/SampleNoLevels.Tests/MainSceneNoLevelsForTesting.unity"; FileAssert.Exists(mainScenePath); loadedScene = EditorSceneManager.LoadSceneInPlayMode(mainScenePath, new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D)); Assert.True(loadedScene.IsValid()); yield return(null); Assert.True(SceneManager.SetActiveScene(loadedScene)); }
public IEnumerator _05_PauseMenuChangesGameManagerGameState() { EditorSceneManager.LoadSceneInPlayMode(asteroidsScenePath, loadSceneParameters); yield return(null); InGameMenuController menuController = GameObject.Find("InGameMenu").GetComponent <InGameMenuController>(); menuController.ChangeMenuState(true); Assert.IsTrue(GameManager.IsPaused); Assert.IsTrue(Time.timeScale == 0.0f); menuController.ChangeMenuState(false); Assert.IsFalse(GameManager.IsPaused); Assert.IsTrue(Time.timeScale == 1.0f); }
public static void EditScene(params SubScene[] scenes) { foreach (var subScene in scenes) { if (CanEditScene(subScene)) { Scene scene; if (Application.isPlaying) scene = EditorSceneManager.LoadSceneInPlayMode(subScene.EditableScenePath, new LoadSceneParameters(LoadSceneMode.Additive)); else scene = EditorSceneManager.OpenScene(subScene.EditableScenePath, OpenSceneMode.Additive); scene.isSubScene = true; } } }
public IEnumerator SetUpTest() { _cloudPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(Prefabs.Sprays.Cloud); Assert.IsNotNull(_cloudPrefab); _cowPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(Prefabs.Characters.Cow); Assert.IsNotNull(_cowPrefab); _pressurePlatePrefab = AssetDatabase.LoadAssetAtPath <GameObject>(Prefabs.Triggers.PressurePlate); Assert.IsNotNull(_pressurePlatePrefab); _zombiePrefab = AssetDatabase.LoadAssetAtPath <GameObject>(Prefabs.Characters.Zombie); Assert.IsNotNull(_zombiePrefab); yield return(new EnterPlayMode()); EditorSceneManager.LoadSceneInPlayMode("Tests/EditMode/UnitTestScene", new LoadSceneParameters(LoadSceneMode.Single)); Time.timeScale = 10.0f; }
IEnumerator LoadSceneInternal(string name) { #if UNITY_EDITOR if (name.Contains(".unity")) { // UnityEditor.EditorApplication.LoadLevelInPlayMode(name); var parameter = new LoadSceneParameters(LoadSceneMode.Single); EditorSceneManager.LoadSceneInPlayMode(name, parameter); yield return(WaitFor(new SceneLoaded(Path.GetFileNameWithoutExtension(name)))); yield break; } #endif SceneManager.LoadScene(name); yield return(WaitFor(new SceneLoaded(name))); }
public IEnumerator _06_InGameScoreCounterChangesWhenScoreChanges() { EditorSceneManager.LoadSceneInPlayMode(asteroidsScenePath, loadSceneParameters); yield return(null); Assert.NotNull(GameObject.Find("InGameMenu")); Canvas canvas = GameObject.Find("InGameMenu").GetComponent <Canvas>(); Assert.NotNull(canvas.transform.GetChild(1)); Text[] numbers = canvas.transform.GetChild(1).GetComponentsInChildren <Text>(); Assert.IsTrue(numbers.Length == 7); GameManager.AddToScore(0); yield return(new WaitForSeconds(0.5f)); Assert.IsTrue(numbers[0].text == "0" && numbers[1].text == "0" && numbers[2].text == "0" && numbers[3].text == "1" && numbers[4].text == "0" && numbers[5].text == "0" && numbers[6].text == "0"); }
public void Init() { for (int i = 0; i < GameDatabase.Instance.episodes.Length; ++i) { var ep = GameDatabase.Instance.episodes[i]; Button b = Instantiate(ButtonPrefab); Text t = b.GetComponentInChildren <Text>(); t.text = $"Episode {i + 1}"; var i1 = i; b.onClick.AddListener(() => { UIAudioPlayer.PlayPositive(); OpenEpisode(i1); }); b.transform.SetParent(ButtonListPlace); m_EpisodeButtons.Add(b); m_LevelButtons.Add(new List <Button>()); for (int j = 0; j < ep.scenes.Length; ++j) { Button levelB = Instantiate(ButtonPrefab); t = levelB.GetComponentInChildren <Text>(); var j1 = j; levelB.onClick.AddListener(() => { #if UNITY_EDITOR EditorSceneManager.LoadSceneInPlayMode(ep.scenes[j1], new LoadSceneParameters()); #else SceneManager.LoadScene(ep.scenes[j1]); #endif Time.timeScale = 1; }); t.text = $"Level {j + 1}"; levelB.transform.SetParent(ButtonListPlace); m_LevelButtons[i].Add(levelB); } } }
private static void LoadActiveScenes() { if (activeScenes == null) { return; } LoadSceneParameters _parameter = new LoadSceneParameters(); _parameter.loadSceneMode = LoadSceneMode.Additive; string _coreSceneName = LoadSettings().CoreScenePath; for (int _i = 0; _i < activeScenes.Length; _i++) { if (activeScenes[_i] != _coreSceneName) { EditorSceneManager.LoadSceneInPlayMode(activeScenes[_i], _parameter); } } }
public IEnumerator SetUpTest() { yield return(new EnterPlayMode()); var scene = EditorSceneManager.LoadSceneInPlayMode( "Tests/EditMode/UnitTestScene", new LoadSceneParameters(LoadSceneMode.Single)); while (!scene.isLoaded) { Debug.Log("Waiting for scene to load"); yield return(null); } _controlledCureSprayPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(Prefabs.Sprays.ControlledCureSpray); Assert.IsNotNull(_controlledCureSprayPrefab); _controlledZombieSprayPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(Prefabs.Sprays.ControlledZombieSpray); Assert.IsNotNull(_controlledZombieSprayPrefab); Time.timeScale = 10.0f; }
protected override void LoadInternal() { #if UNITY_EDITOR if (!EditorApplication.isPlaying) { var mode = _mode == LoadSceneMode.Single ? OpenSceneMode.Single : OpenSceneMode.Additive; var realPath = PathUtility.RelativeDataPathToRelativeProjectPath(_scenePath) + ".unity"; Scene = EditorSceneManager.OpenScene(realPath, mode); return; } var param = new LoadSceneParameters { loadSceneMode = _mode }; EditorSceneManager.LoadSceneInPlayMode(_path, param); #else SceneManager.LoadScene(_scenePath, _mode); #endif Scene = SceneManager.GetSceneByPath(_scenePath); IsDone = true; }
public Scene GetScene() { for (int i = 0; i < SceneManager.sceneCount; i++) { if (SceneManager.GetSceneAt(i).name == name) { return(SceneManager.GetSceneAt(i)); } } if (Application.isPlaying) { if (File.Exists(GetScenePath())) { EditorSceneManager.LoadSceneInPlayMode(GetScenePath(), new LoadSceneParameters(LoadSceneMode.Additive)); } else { Debug.Log("Creating temporary scene for data " + name + "."); SceneManager.CreateScene(name); } } else { Scene active = EditorSceneManager.GetActiveScene(); if (File.Exists(GetScenePath())) { EditorSceneManager.OpenScene(GetScenePath(), OpenSceneMode.Additive); } else { Debug.Log("Recreating scene for data " + name + "."); EditorSceneManager.SaveScene(EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive), GetScenePath()); } EditorSceneManager.SetActiveScene(SceneManager.GetSceneByName(name)); Lightmapping.bakedGI = false; Lightmapping.realtimeGI = false; EditorSceneManager.SetActiveScene(active); } return(SceneManager.GetSceneByName(name)); }
private static void OnPlayModeChanged(PlayModeStateChange playMode) { if (playMode == PlayModeStateChange.EnteredPlayMode) { var data = GameObject.FindObjectOfType <PlayFromSceneData>(); if (data == null) { return; } EditorSceneManager.LoadSceneInPlayMode(data.scenePath, new LoadSceneParameters(LoadSceneMode.Single)); } if (playMode == PlayModeStateChange.EnteredEditMode) { var data = GameObject.FindObjectOfType <PlayFromSceneData>(); if (data == null) { return; } GameObject.DestroyImmediate(data.gameObject); } }
public override void OnEnter() { //加载unity场景 var unityScene = string.Empty; foreach (var node in m_app.CurrScenes) { if (string.IsNullOrEmpty(node.scene.UnityScene)) { continue; } unityScene = node.scene.UnityScene; } if (m_app.EnterScenesList.Count > 0) { foreach (var node in m_app.EnterScenesList) { if (string.IsNullOrEmpty(node.scene.UnityScene)) { continue; } unityScene = node.scene.UnityScene; } } if (!string.IsNullOrEmpty(unityScene) && unityScene != m_app.CurrUnityScene) { #if UNITY_EDITOR EditorSceneManager.LoadSceneInPlayMode($"Assets/XGameKitSamples/XGameScene/{unityScene}.unity", new LoadSceneParameters(LoadSceneMode.Single)); #else m_loadOperation = SceneManager.LoadSceneAsync(unityScene); #endif m_app.SetCurrUnityScene(unityScene); } else { m_loadOperation = null; } }
public void Load(LoadDoneDelegate loadDone) { #if UNITY_EDITOR if (AbMgr.instance.loadInEditor) { if (_assetInfo.type.Equals(".unity")) { EditorSceneManager.LoadSceneInPlayMode(_assetInfo.assetPath, new LoadSceneParameters(LoadSceneMode.Additive)); loadDone(_assetInfo.assetName); return; } else { object obj = AssetDatabase.LoadAssetAtPath <Object>(_assetInfo.assetPath); loadDone(obj); return; } } #endif if (AssetLoaderPool.TryGetValue(_assetInfo, out var assetLoader)) { if (assetLoader.Asset != null) { loadDone(assetLoader.Asset); } } else { assetLoader = new AssetLoader(_assetInfo); AssetLoaderPool.Add(_assetInfo, assetLoader); assetLoader.Start(); } _assetLoader = assetLoader; _loadDone = loadDone; assetLoader.AddLoaderUser(this); }
public virtual IEnumerator UnitySetUp() { string mainScenePath = testingScenePath; FileAssert.Exists(mainScenePath); loadedScene = EditorSceneManager.LoadSceneInPlayMode(mainScenePath, new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D)); Assert.True(loadedScene.IsValid()); yield return(null); Assert.True(SceneManager.SetActiveScene(loadedScene)); if (Main.instance == null) { Assert.Fail("Class Main.cs did not initialize."); } if (Main.instance.ignoreLoadingGameProgress == false) { Assert.Fail( $"Class {nameof(Main)}.cs loaded game progress. This should not be enabled during testing.\n" + $"Fix this by setting '{nameof(Main.ignoreLoadingGameProgress)}' to 'true' in {mainScenePath}"); } }
public void OpenScene(LoadSceneMode loadMode = LoadSceneMode.Single) { EditorSceneManager.LoadSceneInPlayMode(this.AssetPath, new LoadSceneParameters(loadMode)); }
public Scene GetScene() { for (int i = 0; i < SceneManager.sceneCount; i++) { Scene scene = SceneManager.GetSceneAt(i); if (scene.name == name) { if (!scene.isLoaded) { if (Application.isPlaying) { EditorSceneManager.LoadSceneInPlayMode(scene.path, new LoadSceneParameters(LoadSceneMode.Additive)); } else { EditorSceneManager.OpenScene(scene.path, OpenSceneMode.Additive); } } return(scene); } } if (Application.isPlaying) { if (VerifyScene()) { EditorSceneManager.LoadSceneInPlayMode(GetScenePath(), new LoadSceneParameters(LoadSceneMode.Additive)); } else { Debug.Log("Creating temporary scene for data " + name + "."); SceneManager.CreateScene(name); } } else { Scene active = EditorSceneManager.GetActiveScene(); Lightmapping.bakedGI = false; Lightmapping.realtimeGI = false; if (VerifyScene()) { EditorSceneManager.OpenScene(GetScenePath(), OpenSceneMode.Additive); } else { Debug.Log("Recreating scene for data " + name + " in folder " + GetScenePath() + "."); EditorSceneManager.SaveScene(EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive), GetScenePath()); } EditorSceneManager.SetActiveScene(SceneManager.GetSceneByName(name)); Lightmapping.bakedGI = false; Lightmapping.realtimeGI = false; EditorSceneManager.SetActiveScene(active); } return(SceneManager.GetSceneByName(name)); bool VerifyScene() { string[] assets = AssetDatabase.FindAssets("t:Scene", new string[1] { GetDirectoryPath() }); if (assets.Length == 0) { return(false); } string path = AssetDatabase.GUIDToAssetPath(assets.First()); string id = path.Substring(path.LastIndexOf("/") + 1); id = id.Substring(0, id.LastIndexOf(".")); return(name == id); } }
/// <summary> /// Load a particular Scene Entry /// </summary> /// <param name="entry">The Entry to load</param> private void LoadEntryAtRuntime(SceneEntry entry) { // Don't load if (entry.loadMethod == LoadMethod.DontLoad) { return; } // Already loaded, try editor first var existingScene = SceneManager.GetSceneByPath(entry.scene.editorPath); // Try runtime path if (!existingScene.IsValid()) { existingScene = SceneManager.GetSceneByPath(entry.scene.runtimePath); } #if UNITY_EDITOR // Could be we just created the scene because it's baked if (!existingScene.IsValid()) { existingScene = SceneManager.GetSceneByName(entry.scene.runtimePath); } if (Application.isEditor && entry.loadMethod == LoadMethod.Baked) { // If we've already processed this, return early if (_bakedScenesLoading.Contains(entry) || _bakedScenesMerged.Contains(entry)) { return; } // We're loading this entry, don't allow this to be re-entrant _bakedScenesLoading.Add(entry); if (!existingScene.IsValid()) { // This allows us to load the level even in playmode #if UNITY_2018_3_OR_NEWER EditorSceneManager.LoadSceneInPlayMode(entry.scene.editorPath, new LoadSceneParameters(LoadSceneMode.Additive)); #else EditorApplication.LoadLevelAdditiveInPlayMode(entry.scene.editorPath); #endif } // Loading a scene can take multiple frames so we have to wait. // Baking scenes can only take place when they're all loaded due to cross-scene referencing if (_waitingToBake != null) { StopCoroutine(_waitingToBake); } _waitingToBake = StartCoroutine(CoWaitAndBake()); return; } #endif // If it's already loaded, return early if (existingScene.IsValid()) { return; } if (entry.loadMethod == LoadMethod.AdditiveAsync) { AmsDebug.Log(this, "Loading {0} Asynchronously from {1}", entry.scene.name, gameObject.scene.name); entry.asyncOp = SceneManager.LoadSceneAsync(entry.scene.runtimePath, LoadSceneMode.Additive); return; } if (entry.loadMethod == LoadMethod.Additive) { AmsDebug.Log(this, "Loading {0} from {1}", entry.scene.name, gameObject.scene.name); SceneManager.LoadScene(entry.scene.runtimePath, LoadSceneMode.Additive); return; } }