private void SceneUnloaded(Scene scene) { if (scene == missionScene) { missionScene = null; } }
private void PlaySceneOutAnim(Scene?currentScene) { if (currentScene == null) { return; } Debug.LogWarning("Implement Scene Out Anim here"); //TODO //Move out current scene here }
public async Task Unload() { if (!currentScene.HasValue) { return; } await SceneManager.UnloadSceneAsync(currentScene.Value); currentScene = null; }
public static void OpenObjectInScene(PathInfo pathInfo) { // Debug.Log("[SceneUtil] Opening object:" + pathInfo.FullPath()); Scene?scene = SceneUtil.LoadScene(pathInfo.assetPath, OpenSceneMode.Single); if (scene.HasValue) { UnityEngine.Object obj = pathInfo.objID.searchForObjectInScene(scene.Value); Selection.activeObject = obj; } }
public void AssignOpenScene(Scene sceneForChunk) { if (Loaded || _loading) { SceneManager.UnloadSceneAsync(sceneForChunk); return; } _scene = sceneForChunk; RelocateChunkObjectsToChunk(_scene.Value.GetRootGameObjects()); }
/// <summary> /// Start a minigame that is in a separate scene which will be additively loaded on top of the current scene. /// The scene should have its own Camera since the main camera will be disabled. /// Remember to add the scene to BuildSettings /// Calling Exit will unload the additive scene. /// </summary> public void EnterScene(string additiveSceneName) { EnterInternal(disableCamera: true); IsMiniGameSceneActive = true; RenderSettings.fog = false; SetMainSceneObjectsEnabled(false); SceneManager.LoadScene(additiveSceneName, LoadSceneMode.Additive); Scene = SceneManager.GetSceneByName(additiveSceneName); }
/*--------------------------------------------------------------------------------------------*/ private void LoadSceneForNonplayingEditor() { #if UNITY_EDITOR string fullPath = Application.dataPath+"/"+SceneFolderPath+SceneName+".unity"; vLoadedScene = UnityEditor.SceneManagement.EditorSceneManager.OpenScene( fullPath, UnityEditor.SceneManagement.OpenSceneMode.Additive); Debug.Log("Loaded scene for editor: "+fullPath, this); OnSceneLoadedEvent.Invoke(this); #endif }
public bool TranslateText(Scene?scene, object source, TextTranslationEventArgs e, out string translate) { if (TextTranslationPool.Translate(scene, source, e, out var temp)) { translate = temp; return(true); } translate = temp; return(false); }
/// <summary> /// Unloads current map asynchronously /// </summary> public void UnloadMapAsync() { if (string.IsNullOrEmpty(loadedSceneName)) { return; } LaneSnapping.Deinitialize(); SceneManager.UnloadSceneAsync(loadedSceneName); loadedSceneName = null; loadedScene = null; }
/// Dictate the type of UI to look for when scene is loaded. /// Pass in the UIDataEvent, you create and manage your own UIDataEvent. /// All UIs only add to the scene. public SceneControllerToken <TModel> LoadSceneControllerAsync <TModel>(TModel model, Transform parent = null, LoadSceneMode loadSceneMode = LoadSceneMode.Additive) where TModel : SceneControllerModel { var controllerName = DeriveControllerName <TModel>(); var token = new SceneControllerToken <TModel>(Guid.NewGuid(), model); scene = null; AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(controllerName, loadSceneMode); RunCoroutine.Instance.StartCoroutine(LoadController <TModel>(asyncOperation, token, controllerName, parent)); return(token); }
private void ClientSceneReady(NetworkConnection connection, SceneReadyMessage message) { Scene?scene = SceneManagerExtensions.GetSceneByPathOrName(message.sceneNameOrPath); if (scene == null) { Debug.LogWarning($"Scene {message.sceneNameOrPath} not loaded on server despite client readying it"); return; } PlayerForConnection(connection).MoveToScene(scene.Value); }
/// <summary> /// End the scene /// </summary> /// <exception cref="InvalidOperationException"></exception> public void EndScene() { // Throw an exception if there is no current scene if (CurrentScene == null) { throw new InvalidOperationException("There is no currently active scene"); } // End the current scene, if any Log.Info($"Ending scene \"{CurrentScene.Name}\"", nameof(SceneManager)); CurrentScene.End(); CurrentScene = null; }
/// <summary> /// End the current scene, if any, and start a scene /// </summary> /// <param name="scene"></param> public void StartScene(Scene scene, double time) { // End the current scene, if any if (CurrentScene != null) { EndScene(); } // Start new scene Log.Info($"Starting scene \"{scene.Name}\"", nameof(SceneManager)); CurrentScene = scene; CurrentScene.Start(); }
public UnityObjectOptionTree(Type type, Scene?scene, string title = null) : this ( type, type.DisplayName(), type.Icon(), scene, true, uo => true, title ?? type.DisplayName() ) { }
public static T FindFirstObject <T>(Scene?scene = null, bool includeInactive = true) where T : Component { foreach (var rootObject in GetRootGameObjects(scene)) { if (rootObject.GetComponentsInChildren <T>(includeInactive).FirstOrDefault() is T t) { return(t); } } return(null); }
private static void CollectHierarchyObjects() { // 実行中は負荷が高いので実行しない. if (Application.isPlaying) { return; } currentScene = SceneManager.GetSceneAt(0); hierarchyObjects = UnityEditorUtility.FindAllObjectsInHierarchy(); }
private static void HierarchyChanged() { // 実行中は負荷が高いので実行しない. if (Application.isPlaying) { return; } if (onHierarchyChangedAsObservable != null) { onHierarchyChangedAsObservable.OnNext(Unit.Default); } var createObserver = onCreateAsObservable != null && onCreateAsObservable.HasObservers; var deleteObserver = onDeleteAsObservable != null && onDeleteAsObservable.HasObservers; if (createObserver || deleteObserver) { var nowScene = SceneManager.GetActiveScene(); // Hierarchy上のGameObjectを検索して取得. hierarchyObjects = UnityEditorUtility.FindAllObjectsInHierarchy(); // シーンが変わっていた場合Hierarchy上のGameObjectをキャッシュ. if (currentScene != nowScene) { markedObjects = hierarchyObjects.Select(x => x.GetInstanceID()).ToArray(); currentScene = nowScene; } // キャッシュ済みGameObjectとの差分で新規作成されたGameObjectを発見. var newObjects = hierarchyObjects.Where(x => !markedObjects.Any(y => y == x.GetInstanceID())).ToArray(); // 新規作成通知. if (0 < newObjects.Length) { if (onCreateAsObservable != null) { onCreateAsObservable.OnNext(newObjects.ToArray()); } } if (hierarchyObjects.Length < markedObjects.Length) { if (onDeleteAsObservable != null) { onDeleteAsObservable.OnNext(Unit.Default); } } markedObjects = hierarchyObjects.Select(x => x.GetInstanceID()).ToArray(); } }
/// <summary> /// Helper method to get the DontDestroyOnLoad Scene. It's inaccessible by standard Unity methods. /// </summary> /// <returns>The DontDestroyOnLoad Scene.</returns> private static Scene GetDontDestroyOnLoadScene() { if (!_dontDestroyOnLoadScene.HasValue) { GameObject temp = new GameObject("AMS-DontDestroyOnLoad-Finder"); Object.DontDestroyOnLoad(temp); _dontDestroyOnLoadScene = temp.scene; Object.DestroyImmediate(temp); } return(_dontDestroyOnLoadScene.Value); }
public static void Prompt(Scene?defaultParentScene, Action <Scene?, Transform> onConfirm) { if (instance == null) { var instance = CreateInstance <ReparentingPrompt>(); instance.minSize = instance.maxSize = new Vector2(300, 88); } instance.parentScene = defaultParentScene; instance.onConfirm = onConfirm; instance.ShowUtility(); instance.Center(); }
// Use this for initialization void Start () { SceneStartingScene = SceneManager.GetActiveScene(); if (LevelCache.IsLoaded(SceneStartingScene.name)){ return; } else { LevelCache.CurrentRootObject = SceneStartingScene.name; } DontDestroyOnLoad(gameObject); currentScene = SceneStartingScene; IsLoading = true; }
private static void CollectHierarchyObjects() { // 実行中は負荷が高いので実行しない. if (Application.isPlaying) { return; } var nowScene = SceneManager.GetSceneAt(0); hierarchyObjects = UnityEditorUtility.FindAllObjectsInHierarchy(); markedObjects = hierarchyObjects.Select(x => x.GetInstanceID()).ToArray(); currentScene = nowScene; }
public static void LaunchEvolutionScene() { //Evolution scene controller entrance arguments should have already been set before launching scene //Previous scene should have paused itself before launching the evolution scene if (evolutionScene != null) { Debug.LogError("Evolution scene trying to be launched while one already active"); return; } EvolutionSceneClosed = null; Scene oldScene = CurrentScene; EvolutionSceneClosed += () => { SceneManager.SetActiveScene(oldScene); }; StartFadeOut(); FadeOutComplete += () => { int newSceneIndex = SceneManager.sceneCount; AsyncOperation loadSceneOperation = SceneManager.LoadSceneAsync(evolutionSceneIdentifier, LoadSceneMode.Additive); loadSceneOperation.completed += (ao) => { evolutionScene = SceneManager.GetSceneAt(newSceneIndex); EvolutionScene.EvolutionSceneController evolutionSceneController = EvolutionScene.EvolutionSceneController.GetEvolutionSceneController((Scene)evolutionScene); SceneManager.SetActiveScene((Scene)evolutionScene); StartFadeIn(); FadeInComplete += () => { evolutionSceneController.StartAnimation(); evolutionSceneController.EvolutionAnimationComplete += () => { CloseEvolutionScene(); }; }; }; }; }
public void Load(string fileName) { _context = new AssimpContext(); _context.SetConfig(new BooleanPropertyConfig(AiConfigs.AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, false)); _fileName = fileName; _scene = _context.ImportFile(fileName, PostProcessSteps.GenerateBoundingBoxes | PostProcessSteps.CalculateTangentSpace | PostProcessSteps.EmbedTextures); _sceneContext.CurrentScene = _scene; _materialProvider.Load(_scene); }
private void SetSceneActive(Scene?scene) { if (!scene.HasValue) { return; } if (!scene.Value.IsValid()) { return; } SceneManager.SetActiveScene(scene.Value); }
//----- method ----- public SceneInstance(Scenes?identifier, ISceneBase instance, Scene?scene) { this.scene = scene; Identifier = identifier; Instance = instance; var rootObjects = scene.Value.GetRootGameObjects(); activeRoots = rootObjects .Where(x => !UnityUtility.IsNull(x)) .Where(x => UnityUtility.IsActive(x)) .ToArray(); }
private void SceneManager_SceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.buildIndex == 0) { // We don't care for the base scene loading. The base scene will always load // first when the application launches. return; } Assert.IsTrue(mode == LoadSceneMode.Additive, $"Only {nameof(LoadSceneMode.Additive)} scene loading is allowed!"); currentExampleScene = scene; // While we have an exmaple scene loaded we want the examples selection to disappear. ExamplesUI.SetActive(false); }
void OnCollisionExit(Collision col) { if (col.transform.tag != "Player") { return; } if (_scene == null) { throw new NullReferenceException(); } col.transform.parent = null; SceneManager.MoveGameObjectToScene(col.gameObject, (Scene)_scene); _scene = null; }
IEnumerator ToLevel(int levelIndex, bool useFade = true) { if (levelIndex < 0 || levelIndex >= this.TotalLevels) { yield break; } else if (this.loading) { yield break; } this.loading = true; // Fade.. if (this.fadeEffect != null && useFade) { yield return(this.fadeEffect.FadeOut()); } if (this.LastScene != null) { var u = this.LastScene.Value; if (u.isLoaded && u.IsValid()) { yield return(SceneManager.UnloadSceneAsync(u)); } } this.CurrentLevel = levelIndex; var count = SceneManager.sceneCount; yield return(SceneManager.LoadSceneAsync(levelIndex + 1, LoadSceneMode.Additive)); var s = SceneManager.GetSceneAt(count); if (this.fadeEffect != null && useFade) { yield return(this.fadeEffect.FadeIn()); } #if UNITY_EDITOR Debug.Log("Level: " + this.CurrentLevel.ToString() + "/ " + this.TotalLevels.ToString()); #endif this.LastScene = s; this.loading = false; }
public static void LaunchTradeScene() { if (tradeScene != null) { Debug.LogError("Trade trying to be launched while battle already active"); return; } if (pausedFreeRoamScene != null) { Debug.LogError("Trying to launch trade scene while there is already a paused scene"); return; } pausedFreeRoamScene = CurrentScene; FreeRoamSceneController pausedSceneController = GetFreeRoamSceneController((Scene)pausedFreeRoamScene); pausedSceneController.SetDoorsEnabledState(false); pausedSceneController.SetSceneRunningState(false); StartFadeOut(); FadeOutComplete += () => { pausedSceneController.SetSceneRunningState(true); pausedSceneController.SetEnabledState(false); int newSceneIndex = SceneManager.sceneCount; AsyncOperation loadSceneOperation = SceneManager.LoadSceneAsync(tradeSceneIdentifier, LoadSceneMode.Additive); loadSceneOperation.completed += (ao) => { tradeScene = SceneManager.GetSceneAt(newSceneIndex); Trade.TradeManager tradeManager = Trade.TradeManager.GetTradeSceneTradeManager((Scene)tradeScene); SceneManager.SetActiveScene((Scene)tradeScene); StartFadeIn(); FadeInComplete += () => { tradeManager.StartTradeScene(); }; }; }; }
public void CreateScene(int width, int height, FloatColor color, bool useAntialiasing) { var renderTarget = new Framebuffer(width, height); renderTarget.Clear(color); var camera = new PerspectiveCamera(renderTarget, new Vector3(0f, 0, -10), Vector3.Forward, Vector3.Up); var objects = new List <IHittable>(); var circuitryTexture = Texture.LoadFrom(@"_Resources/Textures/circuitry-albedo.png").ToInfo(3); var sunTexture = Texture.LoadFrom(@"_Resources/Textures/sun.png").ToInfo(); var modelTexture = Texture.LoadFrom(@"_Resources/Textures/texel_density.png").ToInfo(); var crystalTexture = Texture.LoadFrom(@"_Resources/Textures/crystal.png").ToInfo(); var circuitryMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 0.5f, circuitryTexture); var sunMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 1f, sunTexture); var modelMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 1f, modelTexture); var crystalMaterial = new PhongMaterial(FloatColor.White, 1f, 8, 50, 1f, crystalTexture); var circuitry = new Sphere(new Vector3(2.5f, -1, 0), 0.5f, circuitryMaterial); var sun = new Sphere(new Vector3(2.5f, -2.5f, 0), 0.75f, sunMaterial); var model = Model.LoadFromFile("_Resources/Models/lowpolytree_unwrap.obj", modelMaterial, 1, Vector3.Down); var crystal = Model.LoadFromFile("_Resources/Models/crystal.obj", crystalMaterial, 3, Vector3.Left * 2); objects.Add(circuitry); objects.Add(sun); objects.Add(model); objects.Add(crystal); Scene = new Scene(objects, camera, new List <Light> { new PointLight { Position = new Vector3(1, 2f, 0), Color = FloatColor.White }, new PointLight { Position = new Vector3(-2, 2f, 0), Color = FloatColor.Red }, new PointLight { Position = new Vector3(-4, 2f, -3), Color = FloatColor.White }, new PointLight { Position = new Vector3(-2, -1f, 0), Color = FloatColor.Green }, }, FloatColor.Black); }
IEnumerator ExitInternal() { // unload all additive minigame scenes. don't leave cutscene mode until its done to avoid weirdness if (Scene.HasValue) { yield return(SceneManager.UnloadSceneAsync(Scene.Value)); Scene = null; } CutsceneMode.Exit(); IsMiniGameActive = false; Globals.GameVars.camera_Mapview.SetActive(true); Globals.GameVars.FPVCamera.SetActive(true); }
void UpdateSceneUI() { if (_loadedScene.HasValue) { SceneManager.UnloadSceneAsync(_loadedScene.Value); _loadedScene = null; } DemoDescription desc = demoScenes[_currentSceneIndex]; string scenename = desc.sceneName + scenePostfix; SceneManager.LoadSceneAsync(scenename, LoadSceneMode.Additive); demoNameText.text = desc.name; demoInfoText.text = desc.info; _loadedScene = SceneManager.GetSceneByName(scenename); }
public void Loading() { try { if (currentScene.Value.isLoaded) { var rootObject = CreateRoomObject(currentScene.Value.name); AddLevelToCache(currentScene.Value, rootObject); CurrenSceneIndex++; SceneManager.LoadScene(CurrenSceneIndex, LoadSceneMode.Additive); currentScene = SceneManager.GetSceneAt(CurrenSceneIndex); } } catch (IndexOutOfRangeException) { Debug.Log("Out of range exit"); LevelCache.LevelMap[SceneStartingScene.name].gameObject.SetActive(true); IsLoading = false; } }
private void SceneChanged(Scene oldScene, Scene newScene) { if (SpaceTraderConfig.LocalPlayer) { return; } /* if loading into a new scene with no player, and it's a mission scene, start that mission */ var missionForScene = SpaceTraderConfig.MissionsConfiguration.MissionForScene(newScene); if (missionForScene) { Debug.Assert(!missionScene.HasValue, "can't load two missions scenes at once"); missionScene = newScene; Mission = ActiveMission.Create(missionForScene); } else if (mission) { CancelMission(); } }