public static AsyncOperation LoadSceneOnEditor(string guid, bool bAsync, bool bAdditive) { string scenePath = AssetDatabase.GUIDToAssetPath(guid); if (bAsync) { if (bAdditive) { return(EditorApplication.LoadLevelAdditiveAsyncInPlayMode(scenePath)); } else { return(EditorApplication.LoadLevelAsyncInPlayMode(scenePath)); } } else { if (bAdditive) { EditorApplication.LoadLevelAdditiveInPlayMode(scenePath); } else { EditorApplication.LoadLevelInPlayMode(scenePath); } return(null); } }
// Load level from the given assetBundle. static public AssetBundleLoadOperation LoadLevelAsync (string assetBundleName, string levelName, bool isAdditive) { AssetBundleLoadOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { string[] levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName); if (levelPaths.Length == 0) { ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist // from that there right scene does not exist in the asset bundle... Debug.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName); return null; } if (isAdditive) EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]); else EditorApplication.LoadLevelInPlayMode(levelPaths[0]); operation = new AssetBundleLoadLevelSimulationOperation(); } else #endif { LoadAssetBundle (assetBundleName); operation = new AssetBundleLoadLevelOperation (assetBundleName, levelName, isAdditive); m_InProgressOperations.Add (operation); } return operation; }
// Load level from the given assetBundle. public AssetBundleLoadOperation LoadLevelAsync(string a_assetBundleName, string a_levelName, bool a_isAdditive, bool a_allowSceneActivation) { AssetBundleLoadOperation operation = null; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { var levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(a_assetBundleName, a_levelName); if (levelPaths.Length == 0) { ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist // from that there right scene does not exist in the asset bundle... Debug.LogError("There is no scene with name \"" + a_levelName + "\" in " + a_assetBundleName); return(null); } if (a_isAdditive) { EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]); } else { EditorApplication.LoadLevelInPlayMode(levelPaths[0]); } operation = new AssetBundleLoadLevelSimulationOperation(); } else #endif { var key = AssetToKey(a_assetBundleName, a_levelName); AssetBundleLoadOperation inProgressOperation; if (m_inProgressOperationsByName.TryGetValue(key, out inProgressOperation)) { var loadLevelOperation = inProgressOperation as AssetBundleLoadLevelOperation; if (loadLevelOperation != null) { return(loadLevelOperation); } } LoadAssetBundle(a_assetBundleName); operation = new AssetBundleLoadLevelOperation(a_assetBundleName, a_levelName, a_isAdditive, a_allowSceneActivation); m_inProgressOperationsByName.Add(key, operation); m_inProgressOperations.Add(new KeyValuePair <string, AssetBundleLoadOperation>(key, operation)); } return(operation); }
/// <summary> /// 场景名字大小写敏感,坑~ /// </summary> /// <param name="scenePath"></param> /// <param name="mode"></param> public void LoadScene(string scenePath, LoadSceneMode mode = LoadSceneMode.Single) { #if UNITY_EDITOR if (AssetBundleUtility.SimulateAssetBundleInEditor) { string path = Path.Combine(AssetBundleUtility.AssetBundleResourcesPath, scenePath) + ".unity"; if (mode == LoadSceneMode.Single) { EditorApplication.LoadLevelInPlayMode(path); } else { EditorApplication.LoadLevelAdditiveInPlayMode(path); } return; } #endif LoadAssetBundleWithDependencies(scenePath + AssetBundleUtility.AssetBundleExtension); SceneManager.LoadScene(Path.GetFileName(scenePath), mode); }
//加载场景包 // raw interfaces public string LoadSceneBundle(string assetPath) { assetPath = NormalizePath(assetPath); #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { if (assetPath.EndsWith("navmesh.unity")) { EditorApplication.LoadLevelAdditiveInPlayMode(assetPath); return(null); } return(Path.GetFileNameWithoutExtension(assetPath)); } #endif string abPath = GetAssetBundlePath(assetPath); AssetBundle ab = abLoader.Load(abPath); return(ab.GetAllScenePaths()[0]); }
// Load level from the given assetBundle. static public void LoadLevel(string assetBundleName, string levelName, bool isAdditive) { #if UNITY_EDITOR if (SimulateAssetBundleInEditor == LoadMode.AssetBundleName) { //GetAssetPathsFromAssetBundleAndAssetName接口对大小写敏感 assetBundleName = assetBundleName.ToLower(); levelName = levelName.ToLower(); string[] levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName); if (levelPaths.Length == 0) { ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist // from that there right scene does not exist in the asset bundle... Debug.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName); } if (isAdditive) EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]); else EditorApplication.LoadLevelInPlayMode(levelPaths[0]); } else #endif { AssetBundle assetbundle = LoadAssetBundleImmediately(assetBundleName); string m_DownloadingError; LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(assetbundle.name, out m_DownloadingError); if (bundle != null) { if (isAdditive) SceneManager.LoadScene(levelName,LoadSceneMode.Additive); else SceneManager.LoadScene(levelName,LoadSceneMode.Single); } } }
public void LoadScene(string assetBundleName, string levelName, bool isAdditive, LoadSceneCallback callback, object[] param) { AssetBundleLoadLevelOperation operation = null; #if UNITY_EDITOR if (AssetLoader2.m_SimulateAssetBundleInEditor) { string[] levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName); if (levelPaths.Length == 0) { ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist // from that there right scene does not exist in the asset bundle... Debug.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName); callback(false, param); return; } if (isAdditive) { EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]); } else { EditorApplication.LoadLevelInPlayMode(levelPaths[0]); } } else #endif { LoadAssetBundle(assetBundleName); operation = new AssetBundleLoadLevelOperation(assetBundleName, levelName, isAdditive, callback, param); operation.callback = callback; operation.loader = this; m_InProgressOperations.Add(operation); } }
/// <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 EditorApplication.LoadLevelAdditiveInPlayMode(entry.scene.editorPath); } // 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; } }