public IEnumerator SetupBeforeTest() { var asyncLoad = SceneManager.LoadSceneAsync(testSceneDirectory + "/BaseScene", LoadSceneMode.Additive); yield return(asyncLoad); var scenarioManager = GameObject.FindObjectOfType <ScenarioManager>(); scenarioManager.useScheduler = true; scenarioManager.schedulingSource = SchedulingSource.CustomScheduling; scenarioManager.terminateOnCompletion = false; CarScenarioLogger.Instance.ClearMemoryLog(); #if UNITY_EDITOR var scenePaths = FindScenes(); var scene = new SceneReference(); foreach (var targetPath in scenePaths) { scene.ScenePath = targetPath; testScenes.Add(scene); } #endif CarScenarioLogger.Instance.ClearMemoryLog(); // Speed up the tests. QualitySettings.vSyncCount = 0; }
void ResolveScene(Entity sceneEntity, ref SceneReference scene, RequestSceneLoaded requestSceneLoaded, Hash128 artifactHash) { // Resolve first (Even if the file doesn't exist we want to stop continously trying to load the section) EntityManager.AddBuffer <ResolvedSectionEntity>(sceneEntity); #if UNITY_EDITOR && !USE_SUBSCENE_EDITORBUNDLES EntityManager.AddComponentData(sceneEntity, new ResolvedSceneHash { ArtifactHash = artifactHash }); UnityEditor.Experimental.AssetDatabaseExperimental.GetArtifactPaths(artifactHash, out var paths); var sceneHeaderPath = EntityScenesPaths.GetLoadPathFromArtifactPaths(paths, EntityScenesPaths.PathType.EntitiesHeader); #else var sceneHeaderPath = EntityScenesPaths.GetLoadPath(scene.SceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1); #endif if (!File.Exists(sceneHeaderPath)) { Debug.LogError($"Loading Entity Scene failed because the entity header file could not be found: {scene.SceneGUID}\n{sceneHeaderPath}"); return; } if (!BlobAssetReference <SceneMetaData> .TryRead(sceneHeaderPath, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef)) { Debug.LogError("Loading Entity Scene failed because the entity header file was an old version: " + scene.SceneGUID); return; } LogResolving("ResolveScene (success)", scene.SceneGUID); ref var sceneMetaData = ref sceneMetaDataRef.Value;
static void CacheInfo(SceneReference sceneReference) { if (sceneReference.ignore) { return; } string levelPath = AssetDatabase.GetAssetOrScenePath(sceneReference.levelScene); for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) { if (EditorBuildSettings.scenes[i].path == levelPath) { sceneReference.levelBuildIndex = i; } } string menuPath = AssetDatabase.GetAssetOrScenePath(sceneReference.menuScene); for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) { if (EditorBuildSettings.scenes[i].path == menuPath) { sceneReference.menuBuildIndex = i; } } }
static List <string> GetScenePathsFromSceneReferences(out SceneReference[] sceneReferences) { List <string> uniqueScenePaths = new List <string> (); sceneReferences = GetAllSceneReferences(); IgnoreNullScenes(sceneReferences); for (int i = 0; i < sceneReferences.Length; i++) { SceneReference sceneReference = sceneReferences[i]; if (sceneReference.ignore) { continue; } string path = AssetDatabase.GetAssetOrScenePath(sceneReference.menuScene); if (!uniqueScenePaths.Contains(path)) { uniqueScenePaths.Add(path); } path = AssetDatabase.GetAssetOrScenePath(sceneReference.levelScene); if (!uniqueScenePaths.Contains(path)) { uniqueScenePaths.Add(path); } } return(uniqueScenePaths); }
public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { SceneReference sceneRef = new SceneReference((string)info.GetValue("scenePath", typeof(string))); obj = sceneRef; return(obj); }
public void SetReferenceValue(PropertyName id, Object value) { var reference = FindReference(id); if (reference == null) { if (value == null) { return; } reference = new SceneReference(id.GetHashCode(), value); references.Add(reference); } #if UNITY_EDITOR if (value == null) { reference.TotalUses--; if (reference.TotalUses <= 0) { ClearReferenceValue(id); } return; } reference.TotalUses++; #endif reference.Object = value; }
void UpdateScenes(SceneReference _target) { var setups = EditorSceneManager.GetSceneManagerSetup(); var newList = new List <MultipleScenesData>(); foreach (var s in setups) { SceneAsset scn = AssetDatabase.LoadAssetAtPath <SceneAsset>(s.path); MultipleScenesData dataToAdd = null; foreach (var d in _target.linkingData.sceneDatas) { if (scn.name == d.SceneName) { dataToAdd = d; break; } } if (dataToAdd == null) { dataToAdd = new MultipleScenesData(); dataToAdd.sceneObject = scn; } newList.Add(dataToAdd); } Undo.RecordObject(_target.linkingData, "List Update"); _target.linkingData.sceneDatas = newList; EditorUtility.SetDirty(_target.linkingData); }
// // Scene Loading // private IEnumerator AwaitSceneLoadComplete(SceneReference sceneReference) { while (!SceneIsLoaded(sceneReference)) { yield return(null); } }
private async Task LoadSceneAsync(SceneID sceneID, GameObject parameterObject = null) { if (loading) { Debug.LogWarning("SceneLoader is already loading a scene. Ignoring LoadScene call."); return; } loading = true; SceneReference targetScene = ActiveSceneMap[sceneID]; await loadingScreen.Show(); if (parameterObject) { SceneManager.MoveGameObjectToScene(parameterObject, baseScene); } await UnloadPreviousScene(); await LoadNewScene(targetScene); await Awaiters.NextFrame; loading = false; await loadingScreen.Dismiss(); }
private IEnumerator UnloadContentScenes(ContentInfo contentInfo) { // unloading scenes that may have been preloaded List <Scene> scenesToUnload = new List <Scene>(); for (int i = 0; i < SceneManager.sceneCount; i++) { Scene scene = SceneManager.GetSceneAt(i); if (scene.path.StartsWith(contentInfo.SubmodulePath)) { scenesToUnload.Add(scene); } } foreach (Scene scene in scenesToUnload) { SceneReference sceneReference = SceneMap.GetSceneReference(scene.path); if (!string.IsNullOrEmpty(sceneReference.Guid)) { yield return(SceneNavigator.Instance.UnloadScene(sceneReference, true)); } } yield return(null); }
/// <summary> /// Adds a scenereference to lists of scenes to spawn a copy of it during the next scene in the OnUpdate() /// The position and offset is added to all entities in the scene /// </summary> /// <param name="sceneReference">A reference to the scene to spawn</param> /// <param name="isIndestructable">If true, there will be NO way to unload the scene</param> /// <param name="entities">The EntitiesQueryBuilder Entities</param> /// <param name="posGiven">The absolute new position of the sceneEntities</param> /// <param name="offsetGiven">The relative new position of the sceneEntities</param> /// <returns>A bool to mark the correct loading of the scene</returns> public static bool LoadSceneAsyncWithPositionAndOffset(SceneReference sceneReference, bool isIndestructable, EntityQueryBuilder entities, float2 posGiven, float2 offsetGiven) { try { entities.ForEach((DynamicBuffer <ScenesToLoad> scenesToLoad) => { scenesToLoad.Add(new ScenesToLoad { sceneReference = sceneReference, makeIndestrucktable = isIndestructable, setPos = true, setOffset = true, pos = posGiven, offset = offsetGiven }); }); return(true); } catch (Exception e) { Debug.Log(e.ToString()); return(false); } }
protected override void OnUpdate() { bool isReq = false; Entities.ForEach(( ref TargetGenInfo gen ) => { if (!gen.Initialized) { gen.Initialized = true; gen.GeneratedCnt = 0; isReq = true; return; } // isReq = gen.IsRequested; }); if (isReq) { int recycled = 0; Entities.ForEach((Entity entity, ref TargetInfo info) => { info.IsActive = true; info.Initialized = false; ++recycled; }); var env = World.TinyEnvironment(); SceneReference tarBase = env.GetConfigData <GameConfig>().TargetScn; for (int i = 0; i < 12 - recycled; i++) { SceneService.LoadSceneAsync(tarBase); } } }
public static IEnumerator WaitForSceneLoadedOrUnloaded(SceneReference sceneRef) { while (!IsSceneLoadedOrUnloaded(sceneRef)) { yield return(null); } }
public void LoadScene(SceneReference scene, LoadSceneMode loadSceneMode) { if (!SceneManager.GetSceneByName(scene).isLoaded) { SceneManager.LoadScene(scene, loadSceneMode); } }
public void LoadScene(SceneReference scene, LoadSceneMode sceneMode = LoadSceneMode.Single) { if (scene != null) { SceneManager.LoadScene(scene, sceneMode); } }
private async Task LoadNewScene(SceneReference scene) { await SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive); activeScene = SceneManager.GetSceneByPath(scene); SceneManager.SetActiveScene(activeScene.Value); }
protected override void OnUpdate() { bool btnOn = false; Entities.WithAll <BtnStartTag>().ForEach((Entity entity, ref PointerInteraction pointerInteraction) => { if (pointerInteraction.clicked) { Debug.LogAlways("btn ret click"); btnOn = true; } }); if (btnOn) { // 盤面生成. Entities.ForEach(( ref PuzzleGen gen ) => { gen.IsGenerate = true; }); // ポーズ解除. Entities.ForEach(( ref GameMngr mngr ) => { mngr.IsPause = false; }); // タイトルシーンアンロード. SceneReference panelBase = new SceneReference(); panelBase = World.TinyEnvironment().GetConfigData <PanelConfig>().TitleScn; SceneService.UnloadAllSceneInstances(panelBase); } }
/// <summary> /// Loads a scene that contains a manager asynchronously. /// </summary> /// <param name="scene">The scene to be loaded.</param> /// <typeparam name="TManager">The type of the manager to be fetched in the scene.</typeparam> /// <returns>A task to be awaited which represents the loading. Its value is the scene's manager. </returns> /// <exception cref="Exception">Thrown if the given <paramref name="scene"/> does not contain a manager of type /// <typeparamref name="TManager"/>.</exception> private async UniTask <TManager> LoadManagedSceneAsync <TManager>(SceneReference scene) where TManager : MonoBehaviour { _loading = true; await _transition.FadeInAsync(TransitionDuration); if (_scene != null) { await SceneManager.UnloadSceneAsync(_scene.Value); } await SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive); _scene = SceneManager.GetSceneByPath(scene); if (_scene == null) { throw new Exception($"Managed scene wasn't loaded ({typeof(TManager)})."); } SceneManager.SetActiveScene(_scene.Value); var manager = FindObjectOfType <TManager>(); await _transition.FadeOutAsync(TransitionDuration); _loading = false; return(manager); }
void CreateAndAddNewSceneReference(SceneAsset newSceneReferenceLevel) { if (newSceneReferenceLevel == null) { return; } SceneReference newSceneReference = CreateInstance <SceneReference> (); newSceneReference.levelScene = newSceneReferenceLevel; newSceneReference.menuScene = AssetDatabase.LoadAssetAtPath <SceneAsset> (((SceneMenu)target).gameObject.scene.path); string newSceneReferencePath = AssetDatabase.GenerateUniqueAssetPath(k_NewSceneReferencePath); AssetDatabase.CreateAsset(newSceneReference, newSceneReferencePath); string newLevelPath = AssetDatabase.GetAssetOrScenePath(newSceneReferenceLevel); Scene newLevelScene = EditorSceneManager.OpenScene(newLevelPath, OpenSceneMode.Additive); SceneCompletion sceneCompletion = FindObjectOfType <SceneCompletion> (); sceneCompletion.sceneReference = newSceneReference; EditorUtility.SetDirty(sceneCompletion); EditorSceneManager.SaveScene(newLevelScene); EditorSceneManager.CloseScene(newLevelScene, true); m_LevelsProp.arraySize++; m_LevelsProp.GetArrayElementAtIndex(m_LevelsProp.arraySize - 1).FindPropertyRelative("level").objectReferenceValue = newSceneReference; }
void OnEnable() { m_AccessDeniedClipProp = serializedObject.FindProperty("accessDeniedClip"); m_ScreenFaderProp = serializedObject.FindProperty("screenFader"); m_SceneMenuIconPrefabProp = serializedObject.FindProperty("sceneMenuIconPrefab"); m_ParentCanvasProp = serializedObject.FindProperty("parentRectTransform"); m_LevelsProp = serializedObject.FindProperty("levels"); m_ReorderableLevelsList = new ReorderableList(serializedObject, m_LevelsProp, true, true, false, true); m_ReorderableLevelsList.elementHeight = (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 7f; m_ReorderableLevelsList.drawElementCallback = (rect, index, active, focused) => { SerializedProperty levelInfoProp = m_ReorderableLevelsList.serializedProperty.GetArrayElementAtIndex(index); SerializedProperty levelProp = levelInfoProp.FindPropertyRelative("level"); SerializedProperty displayNameProp = levelInfoProp.FindPropertyRelative("displayName"); SerializedProperty totalStarsRequiredProp = levelInfoProp.FindPropertyRelative("totalStarsRequired"); SerializedProperty oneStarTimeProp = levelInfoProp.FindPropertyRelative("oneStarTime"); SerializedProperty twoStarTimeProp = levelInfoProp.FindPropertyRelative("twoStarTime"); SerializedProperty threeStarTimeProp = levelInfoProp.FindPropertyRelative("threeStarTime"); rect.height = EditorGUIUtility.singleLineHeight; string label = "Level"; SceneReference sceneReference = levelProp.objectReferenceValue as SceneReference; if (sceneReference != null) { if (sceneReference.levelScene != null) { label = sceneReference.levelScene.name; } else { label = levelProp.objectReferenceValue.name; } } EditorGUI.LabelField(rect, label); rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.indentLevel++; EditorGUI.PropertyField(rect, levelProp, k_LevelContent); rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(rect, displayNameProp, k_DisplayNameContent); rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(rect, totalStarsRequiredProp, k_TotalRequiredStarsContent); rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(rect, oneStarTimeProp, k_OneStarTimeContent); rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(rect, twoStarTimeProp, k_TwoStarTimeContent); rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; EditorGUI.PropertyField(rect, threeStarTimeProp, k_ThreeStarTimeContent); EditorGUI.indentLevel--; }; m_ReorderableLevelsList.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, k_LevelsContent); }; }
void ResolveScene(Entity sceneEntity, ref SceneReference scene, RequestSceneLoaded requestSceneLoaded, Hash128 artifactHash) { // Resolve first (Even if the file doesn't exist we want to stop continously trying to load the section) EntityManager.AddBuffer <ResolvedSectionEntity>(sceneEntity); EntityManager.AddComponentData(sceneEntity, new ResolvedSceneHash { ArtifactHash = artifactHash }); var sceneHeaderPath = EntityScenesPaths.GetLiveLinkCachePath(artifactHash, EntityScenesPaths.PathType.EntitiesHeader, -1); if (!File.Exists(sceneHeaderPath)) { Debug.LogError($"Loading Entity Scene failed because the entity header file could not be found: {scene.SceneGUID}\n{sceneHeaderPath}"); return; } if (!BlobAssetReference <SceneMetaData> .TryRead(sceneHeaderPath, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef)) { Debug.LogError("Loading Entity Scene failed because the entity header file was an old version: " + scene.SceneGUID); return; } LogResolving("ResolveScene (success)", scene.SceneGUID); ref var sceneMetaData = ref sceneMetaDataRef.Value;
public void AddReference(GameObject go, string guid) { var reference = new SceneReference(go, guid); instances.First(q => q.gameObject.scene == go.scene).sceneReferences.Add(reference); UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(go.scene); }
private IEnumerator RunSwitchRoomRoutine(SceneReference scene, bool fadeTransition = true) { IsTransitioning = true; // Fade screen if (fadeTransition) { yield return(RunFadeScreenRoutine(Profile.SceneTransitionTimeSeconds, 1f, 0f)); } // Hide current renderers ToggleSceneRenderers(_currentRoomScene.name, visible: false); _currentRoomScene = SceneManager.GetSceneByPath(scene); // Show new renderers ToggleSceneRenderers(_currentRoomScene.name, visible: true); // Move the player to the start position of that room Player.transform.position = _roomReferences[_currentRoomScene.name].GetEntryPointForPortal(LastPortalId); // Reveal new scene if (fadeTransition) { yield return(RunFadeScreenRoutine(Profile.SceneTransitionTimeSeconds, 0f, 0f)); } IsTransitioning = false; }
internal static string GetSceneInfoDisplayName(this SceneReference sceneReference) { if (sceneReference == null) { throw new ArgumentNullException(nameof(sceneReference)); } return(string.IsNullOrWhiteSpace(sceneReference.Title) ? $"[{sceneReference.ScenePath}]" : $"{sceneReference.Title} [{sceneReference.ScenePath}]"); }
public void DisplayLevel(SceneReference scene) { GUILayout.Label(new GUIContent("Scene name Path: " + scene)); if (GUILayout.Button("Load " + scene)) { UnityEngine.SceneManagement.SceneManager.LoadScene(scene); } }
public static IEnumerator LoadSceneAsync(SceneReference sceneRef, LoadSceneMode mode) { Debug.Assert(IsSceneUnloaded(sceneRef)); loadingScenes.Add(sceneRef.ScenePath); yield return(SceneManager.LoadSceneAsync(sceneRef.ScenePath, mode)); loadingScenes.Remove(sceneRef.ScenePath); }
public static IEnumerator UnloadSceneAsync(SceneReference sceneRef) { Debug.Assert(IsSceneLoaded(sceneRef)); unloadingScenes.Add(sceneRef.ScenePath); yield return(SceneManager.UnloadSceneAsync(sceneRef.ScenePath)); unloadingScenes.Remove(sceneRef.ScenePath); }
//When we load the next scene by walking through a door, it remembers everything it should so when the next scene loads it has the correct data; this also loads the next scene of course and starts the FadeOut method public virtual void NextScene(SceneReference scene, int spawnReference) { tileID = id.ToArray(); PlayerPrefsX.SetIntArray(" " + character.gameFile + "TilesToRemove", tileID); PlayerPrefs.SetInt(" " + character.gameFile + "FacingLeft", character.isFacingLeft ? 1 : 0); PlayerPrefs.SetInt(" " + character.gameFile + "SpawnReference", spawnReference); PlayerPrefs.SetInt(" " + character.gameFile + "CurrentHealth", player.GetComponent <PlayerHealth>().healthPoints); StartCoroutine(FadeOut(scene)); }
void ResolveScene(Entity sceneEntity, ref SceneReference scene, RequestSceneLoaded requestSceneLoaded, Hash128 artifactHash) { // Resolve first (Even if the file doesn't exist we want to stop continously trying to load the section) EntityManager.AddBuffer <ResolvedSectionEntity>(sceneEntity); #if UNITY_EDITOR && !USE_SUBSCENE_EDITORBUNDLES EntityManager.AddComponentData(sceneEntity, new ResolvedSceneHash { ArtifactHash = artifactHash }); UnityEditor.Experimental.AssetDatabaseExperimental.GetArtifactPaths(artifactHash, out var paths); var sceneHeaderPath = EntityScenesPaths.GetLoadPathFromArtifactPaths(paths, EntityScenesPaths.PathType.EntitiesHeader); #else var sceneHeaderPath = EntityScenesPaths.GetLoadPath(scene.SceneGUID, EntityScenesPaths.PathType.EntitiesHeader, -1); #endif #if UNITY_ANDROID && !UNITY_EDITOR var uwrFile = new UnityWebRequest(sceneHeaderPath); uwrFile.downloadHandler = new DownloadHandlerBuffer(); uwrFile.SendWebRequest(); while (!uwrFile.isDone) { } if (uwrFile.isNetworkError || uwrFile.isHttpError) { Debug.LogError($"Loading Entity Scene failed because the entity header file could not be found: {scene.SceneGUID}\nNOTE: In order to load SubScenes in the player you have to use the new BuildSettings asset based workflow to build & run your player.\n{sceneHeaderPath}"); return; } if (!BlobAssetReference <SceneMetaData> .TryRead(uwrFile.downloadHandler.data, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef)) { Debug.LogError("Loading Entity Scene failed because the entity header file was an old version: " + scene.SceneGUID); return; } #else if (!File.Exists(sceneHeaderPath)) { #if UNITY_EDITOR Debug.LogError($"Loading Entity Scene failed because the entity header file could not be found: {scene.SceneGUID}\n{sceneHeaderPath}"); #else Debug.LogError($"Loading Entity Scene failed because the entity header file could not be found: {scene.SceneGUID}\nNOTE: In order to load SubScenes in the player you have to use the new BuildSettings asset based workflow to build & run your player.\n{sceneHeaderPath}"); #endif return; } if (!BlobAssetReference <SceneMetaData> .TryRead(sceneHeaderPath, SceneMetaDataSerializeUtility.CurrentFileFormatVersion, out var sceneMetaDataRef)) { Debug.LogError("Loading Entity Scene failed because the entity header file was an old version: " + scene.SceneGUID); return; } #endif LogResolving("ResolveScene (success)", scene.SceneGUID); ref var sceneMetaData = ref sceneMetaDataRef.Value;
public IEnumerator loadDelay(SceneReference gameScene, SceneReference permanentScene, SceneReference saveScene) { yield return(new WaitForEndOfFrame()); SceneManager.LoadSceneAsync(gameScene, LoadSceneMode.Additive); SceneManager.LoadSceneAsync(permanentScene, LoadSceneMode.Additive); SceneManager.LoadSceneAsync(saveScene, LoadSceneMode.Additive); SceneManager.sceneLoaded += FinishLoading; }