Skip to content

Instantly share code, notes, and snippets.

@dyguests
Last active October 7, 2022 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyguests/19c6313ed7cad3f6a000b8aacb3ce96e to your computer and use it in GitHub Desktop.
Save dyguests/19c6313ed7cad3f6a000b8aacb3ce96e to your computer and use it in GitHub Desktop.
Scene Manager
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