Last active
October 7, 2022 02:38
-
-
Save dyguests/19c6313ed7cad3f6a000b8aacb3ce96e to your computer and use it in GitHub Desktop.
Scene Manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine.SceneManagement; | |
namespace Tools | |
{ | |
public static class SceneStacker | |
{ | |
private static readonly Stack<string> SceneStack = new(); | |
private static bool sIsInitialization; | |
public static void InitScene() | |
{ | |
if (sIsInitialization) return; | |
sIsInitialization = true; | |
SceneStack.Push(SceneManager.GetActiveScene().name); | |
} | |
public static void LoadScene(string scene) | |
{ | |
SceneManager.LoadScene(scene); | |
SceneStack.Push(scene); | |
} | |
public static void ReloadScene() | |
{ | |
SceneManager.LoadScene(SceneStack.Peek()); | |
} | |
public static void BackScene() | |
{ | |
if (SceneStack.Count <= 1) | |
{ | |
return; | |
} | |
SceneStack.Pop(); | |
SceneManager.LoadScene(SceneStack.Peek()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment