// Start is called before the first frame update void Start() { Debug.LogError("LoadSceneParameters是一个结构体,创建一个LoadScene参数"); LoadSceneParameters loadSceneParameters = new LoadSceneParameters(LoadSceneMode.Single); LoadSceneParameters loadSceneParameters2 = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.None); }
public static void LoadLevelAdditiveInPlayMode(string path) { LoadSceneParameters parameters = new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive }; EditorSceneManager.LoadSceneInPlayMode(path, parameters); }
public static AsyncOperation LoadLevelAdditiveAsyncInPlayMode(string path) { LoadSceneParameters parameters = new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive }; return(EditorSceneManager.LoadSceneAsyncInPlayMode(path, parameters)); }
//------------------------------------------------------------------------------------------------------------- public static AsyncOperation LoadSceneAsync(int sSceneBuildIndex, LoadSceneParameters sParameters, string sSceneIntermission = null, STSTransitionData sDatas = null) { LoadSceneMode tLoadSceneMode = sParameters.loadSceneMode; string tSceneName = SceneManager.GetSceneByBuildIndex(sSceneBuildIndex).name; INTERNAL_LoadScene(tSceneName, tLoadSceneMode, sSceneIntermission, sDatas); return(null); }
void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { var parameters = new LoadSceneParameters(LoadSceneMode.Additive); SceneManager.LoadScene(loadLevel); Debug.Log("COLISIONO"); } }
private void Start() { //Load the scene to place in a local physics scene. LoadSceneParameters param = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D); Scene scene = SceneManager.LoadScene(physicsSceneName, param); //Get the scene's physics scene. physicsScene = scene.GetPhysicsScene(); }
static void BeforeSceneLoad() { if (!sceneLoaded) { var sceneParams = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.None); GameManager.Instance.SetAsyncEssentialsScene(SceneManager.LoadScene("AsyncEssentials", sceneParams)); sceneLoaded = true; } }
public override void Update() { #if UNITY_EDITOR if (IsDone) { return; } if (Status == EStatus.None) { Status = EStatus.Loading; } // 1. 加载资源对象 if (Status == EStatus.Loading) { LoadSceneParameters loadSceneParameters = new LoadSceneParameters(); loadSceneParameters.loadSceneMode = SceneMode; _asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters); if (_asyncOp != null) { _asyncOp.allowSceneActivation = true; _asyncOp.priority = _priority; Status = EStatus.Checking; } else { Status = EStatus.Fail; LastError = $"Failed to load scene : {MainAssetInfo.AssetPath}"; YooLogger.Error(LastError); InvokeCompletion(); } } // 2. 检测加载结果 if (Status == EStatus.Checking) { if (_asyncOp.isDone) { SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); if (SceneObject.IsValid() && _activateOnLoad) { SceneManager.SetActiveScene(SceneObject); } Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail; if (Status == EStatus.Fail) { LastError = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}"; YooLogger.Error(LastError); } InvokeCompletion(); } } #endif }
public static IEnumerator LoadSimulationScene(SimulationSceneLoadConfig config, SimulationSceneLoadContext context, ISceneContext sceneContext) { // Load Scene var sceneName = NameForScene(config.SceneType); var options = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D); SceneManager.LoadScene(sceneName, options); var scene = SceneManager.GetSceneByName(sceneName); context.PhysicsScene = scene.GetPhysicsScene(); context.Scene = scene; // We need to wait two frames before the scene and its GameObjects // are fully loaded yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame()); // Find setup script in the new scene var prevActiveScene = SceneManager.GetActiveScene(); SceneManager.SetActiveScene(scene); SimulationSceneSetup sceneSetup = null; var rootObjects = scene.GetRootGameObjects(); for (int i = 0; i < rootObjects.Length; i++) { sceneSetup = rootObjects[i].GetComponent <SimulationSceneSetup>(); if (sceneSetup != null) { break; } } // Create the structures sceneSetup.BuildScene(config.SceneDescription, sceneContext); SceneManager.SetActiveScene(prevActiveScene); yield return(new WaitForFixedUpdate()); SceneManager.SetActiveScene(scene); // Spawn Creatures var spawnOptions = new SimulationSpawnConfig( config.CreatureDesign, config.CreatureSpawnCount, context.PhysicsScene, sceneContext, config.LegacyOptions, config.SceneDescription ); var creatures = sceneSetup.SpawnBatch(spawnOptions); SceneManager.SetActiveScene(prevActiveScene); context.Creatures = creatures; }
private void OnTriggerStay2D(Collider2D collision) { if (isEnter && collision.GetComponent <PlayerController>() != null) { playerGameObj = collision.gameObject; var parameters = new LoadSceneParameters(LoadSceneMode.Single); SceneManager.sceneLoaded += OnSceneLoaded; SceneManager.LoadScene(DestinationSceneName); } }
void LoadSceneAdditivelyAndSetActive(int buildIndex) { var parameters = new LoadSceneParameters(); parameters.loadSceneMode = LoadSceneMode.Additive; SceneManager.LoadScene(buildIndex, parameters); SceneManager.sceneLoaded += SetActiveScene; }
public static void LoadPreviousScene(LoadSceneParameters parameters) { if (history.Count > 0) { SceneManager.LoadScene(history.Pop(), parameters); } else { SceneManager.LoadScene(0, parameters); } }
public IEnumerator LoadSceneAsync(string scenePath, bool isAdditive) { scenePath = FormatScenePath(scenePath); LoadSceneParameters param = new LoadSceneParameters(isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single); AsyncOperation operation = EditorSceneManager.LoadSceneAsyncInPlayMode(scenePath, param); while (!operation.isDone) { yield return(null); } }
/// <summary> /// Shortcut to load the Scene asynchronously in the background. /// </summary> /// <param name="parameters">Struct that collects the various parameters into a single place except for the name and index.</param> /// <returns>Use the AsyncOperation to determine if the operation has completed.</returns> public AsyncOperation LoadAsync(LoadSceneParameters parameters) { if (sceneIndex >= 0) { return(LoadAsyncFromBuildIndex(parameters)); } else { return(LoadAsyncFromPath(parameters)); } }
public static Scene LoadSceneInPlayMode(string path, LoadSceneParameters parameters) { AsyncOperation op = LoadSceneInPlayModeInternal(path, parameters, true); if (op != null) { return(GetSceneAt(sceneCount - 1)); } return(new Scene()); }
public void Setup() { GameManager.InitializeTestingEnvironment(true, true, true, false, false); loadSceneParameters = new LoadSceneParameters(LoadSceneMode.Single, LocalPhysicsMode.None); Object asteroidsScene = ((GameObject)Resources.Load("TestsReferences")).GetComponent <TestsReferences>().asteroidsScene; asteroidsScenePath = AssetDatabase.GetAssetPath(asteroidsScene); cameraPrefab = ((GameObject)Resources.Load("TestsReferences", typeof(GameObject))).GetComponent <TestsReferences>().cameraPrefab; }
private void Update() { foreach (var entity in GetEntities <LoadScene, OnEnableEvent>()) { var parameters = new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D); var scenes = entity.Item1.scenes; foreach (var scene in scenes) { SceneManager.LoadScene(scene, parameters); } } }
public void Setup() { loadSceneParameters = new LoadSceneParameters(LoadSceneMode.Single, LocalPhysicsMode.None); Object asteroidsScene = ((GameObject)Resources.Load("TestsReferences")).GetComponent <TestsReferences>().asteroidsScene; asteroidsScenePath = AssetDatabase.GetAssetPath(asteroidsScene); gameManagerPrefab = ((GameObject)Resources.Load("TestsReferences", typeof(GameObject))).GetComponent <TestsReferences>().gameManagerPrefab; asteroidPrefab = ((GameObject)Resources.Load("TestsReferences", typeof(GameObject))).GetComponent <TestsReferences>().asteroidPrefab; cameraPrefab = ((GameObject)Resources.Load("TestsReferences", typeof(GameObject))).GetComponent <TestsReferences>().cameraPrefab; }
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 new bool Update() { if (m_Request != null) { CRequest.SetProgress(request, m_Request.progress); if (!allowSceneActivation && LoaderType.Typeof_ABScene.Equals(request.assetType) && m_Request.progress >= 0.9f)//加载场景的时候如果allowSceneActivation = false 只能通过progress判断完成 { return(false); } else { return(!m_Request.isDone); } } string assetName = request.assetName; string assetBundleName = request.assetBundleName; if (LoaderType.Typeof_ABScene.Equals(request.assetType)) //加载场景 { var levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName); if (levelPaths.Length == 0) { CRequest.SetError(request, string.Format("There is no scene with name \"" + assetName + "\" in " + assetBundleName)); Debug.LogError(request.error); } else { LoadSceneParameters loadSceneParameters = new LoadSceneParameters(); loadSceneParameters.loadSceneMode = loadSceneMode; m_Request = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], loadSceneParameters); m_Request.allowSceneActivation = allowSceneActivation; CRequest.SetData(request, m_Request); CRequest.SetProgress(request, m_Request.progress); CacheManager.AddScene(request.assetName, request.assetBundleName);//缓存场景 if (!allowSceneActivation) { CacheManager.AddLoadingScene(request.assetName, m_Request); } } } else //加载资源 { StartSync(); m_isDone = true;//标记完成 return(false); } return(false); }
private AsyncOperation LoadSceneAsync(string name) { var loadParams = new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive, localPhysicsMode = LocalPhysicsMode.None }; #if UNITY_EDITOR var path = $"Assets/{name}.unity"; return(EditorSceneManager.LoadSceneAsyncInPlayMode(path, loadParams)); #else return(SceneManager.LoadSceneAsync(name, loadParams)); #endif // UNITY_EDITOR }
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 AssetBundleLoadLevelSimulationOperation(string assetBundleName, string levelName, bool isAdditive) { string[] levelPaths = UnityEditor.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; } LoadSceneParameters parms = new LoadSceneParameters(isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single); m_Operation = EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], parms); }
IEnumerator endScene(string scene, LoadSceneParameters loadSceneParameters) { asource.loop = false; shouldLoop = false; yield return(new WaitUntil(() => asource.isPlaying == false)); asource.clip = end; asource.loop = false; asource.Play(); yield return(new WaitUntil(() => asource.isPlaying == false)); Destroy(asource); SceneManager.LoadScene(scene, loadSceneParameters); }
protected override Scene OnLoad(string id, ISceneInfo info, ISceneLoadParameters parameters, IContext context) { LogSceneLoading(id, info, parameters); var options = new LoadSceneParameters(parameters.AddMode, parameters.PhysicsMode); Scene scene = SceneManager.LoadScene(info.Address, options); if (RegisterApplication) { OnRegisterApplication(scene, context); } LogSceneLoaded(id, info, parameters, scene); return(scene); }
public AssetBundleLoadSceneRequestSimulate(string assetBundleName, string sceneName, LoadSceneMode loadSceneMode) { m_assetBundleName = assetBundleName; m_sceneName = sceneName; m_loadSceneMode = loadSceneMode; string[] levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(m_assetBundleName, m_sceneName); if (levelPaths.Length == 0) { return; } LoadSceneParameters loadSceneParameters = new LoadSceneParameters(); loadSceneParameters.loadSceneMode = m_loadSceneMode; m_request = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], loadSceneParameters); }
/// <summary> /// 异步加载场景 /// </summary> /// <param name="abName"></param> /// <param name="sceneName"></param> /// <param name="loadCompleted"></param> /// <param name="loadSceneMode"></param> public static void LoadSceneAsync(string abName, string sceneName, Action <AsyncOperation> loadCompleted = null, LoadSceneMode loadSceneMode = LoadSceneMode.Single) { #if UNITY_EDITOR // 是否设置了使用assetbundle资源 if (AssetBundleFramework.DeveloperSetting.GetUseAssetBundleAsset()) { AssetBundleFramework.AssetBundleMgr.Instance.LoadBundle(abName, (succeed, bundleName) => { AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode); if (loadCompleted != null) { loadCompleted(operation); } }); } else { // 根据包名获取资源路径,因为后缀名可能不一样所以获取的是数组 string[] paths = AssetDatabase.GetAssetPathsFromAssetBundle(abName); if (paths.Length == 0) { Debug.LogError("AB包路径有误:" + abName); if (loadCompleted != null) { loadCompleted(null); } return; } LoadSceneParameters param = new LoadSceneParameters(loadSceneMode); AsyncOperation operation = EditorSceneManager.LoadSceneAsyncInPlayMode(paths[0], param); if (loadCompleted != null) { loadCompleted(operation); } } #else AssetBundleFramework.AssetBundleMgr.Instance.LoadBundle(abName, (succeed, bundleName) => { AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode); if (loadCompleted != null) { loadCompleted(operation); } }); #endif }
protected IEnumerator LoadSceneWithDeferredSwitchWorlds(string scenePath) { // Load the scene asynchronously and defer the SwitchWorlds() call until // just before the Scene is activated, to guarantee that GameObject-to-Entity // conversion happens at a predictable time. LoadSceneParameters loadParameters = new LoadSceneParameters(LoadSceneMode.Single); var sceneLoadOp = SceneManager.LoadSceneAsync(scenePath, loadParameters); sceneLoadOp.allowSceneActivation = false; while (!sceneLoadOp.isDone) { if (sceneLoadOp.progress >= 0.9f) { SwitchWorlds(); sceneLoadOp.allowSceneActivation = true; } yield return(null); } }
public AsyncOperation LoadAsync(string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single, System.Action listener = null) { mListener = listener; var resSearchRule = ResSearchKeys.Allocate(sceneName); if (ResFactory.AssetBundleSceneResCreator.Match(resSearchRule)) { //加载的为场景 IRes res = ResFactory.AssetBundleSceneResCreator.Create(resSearchRule); #if UNITY_EDITOR if (FromUnityToDll.Setting.SimulationMode) { string path = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundle((res as AssetBundleSceneRes).AssetBundleName)[0]; if (!path.IsNullOrEmpty()) { LoadSceneParameters sceneParameters = new LoadSceneParameters(); sceneParameters.loadSceneMode = loadSceneMode; tempDepends.Clear(); return(UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(path, sceneParameters)); } } else { DoLoadAsync(); tempDepends.Clear(); return(SceneManager.LoadSceneAsync(sceneName, loadSceneMode)); } #else DoLoadAsync(); tempDepends.Clear(); return(SceneManager.LoadSceneAsync(sceneName, loadSceneMode)); #endif } else { Log.E("场景名称错误!请检查名称是否正确或资源是否被标记!AssetName:" + sceneName); } return(null); }
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; }