Skip to content

The Real-Time Unity SceneManager is a utility that keeps track of the names of scenes in Unity projects and generates scripts that can be utilized for code completion purposes.

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

Zain-ul-din/SceneManager

Repository files navigation

SceneManager

The Real-Time Unity SceneManager is a utility that keeps track of the names of scenes in Unity projects and generates scripts that can be utilized for code completion purposes. With this tool, developers can quickly navigate between scenes in their Unity projects without having to manually switch between them.

Note!

limitation: Rewrite the scene name by substituting all spaces with underscores.

Example:- My Scene => My_Scene

Motivation

Managing scene names in Unity can be a daunting task. To help alleviate this, I have created a package that automates the process of fetching all scenes that have been added to the build and provides code completion for them. This package simplifies scene management, making it more accessible to beginners and reducing the likelihood of errors in scene naming.

Example-

Here's an example in C# that demonstrates the difference between using UnityEngine.SceneManagement and Randoms.SceneManager to load a scene. When using UnityEngine.SceneManagement, the scene name is passed as a string, which is case-sensitive and prone to errors if the actual scene name is different or if the scene name is changed in the Unity editor.

However, when using Randoms.SceneManager, the scene name is accessed via an enum called SceneName, which is synced with the actual scene name and provides code completion for scenes that are in build. Additionally, if the scene name is not found, an error will be thrown.

Since spaces cannot be used in enum names. Therefore, all blank spaces will be replaced with underscores when using the enum..

// Load scene using UnityEngine.SceneManagement
SceneManager.LoadScene("myscene"); // potential errors due to string comparison

// Load scene using Randoms.SceneManager
SceneLoaderManager.LoadScene(SceneLoaderManager.SceneName.myscene); // synced with actual scene name, error handling and code completion provided by the enum

UnityEngine.SceneManagement

No Error

Randoms.SceneManager

image

Usage

  • import package
  • press shift + s to open scene window.
  • click on Open Scene Editor to add scenes.
  • click on reload to recompile the project.

Scripting APIS

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// add namespace on the top
using Randoms.SceneManger;

public class Test : MonoBehaviour
{
    private void ReStartGame ()
    {
        // realtime 
        SceneLoaderManager.LoadScene(SceneLoaderManager.SceneName.MyScene);
    }
}

Load Scene Using Unity Button

  • Select btn
  • add component of type SceneLoader
  • select targeted scene from the drop down

About Us

This repository is maintained by Zain-Ul-Din

Show some ❤️ by starring this awesome repository!

Buy Me A Coffee

About

The Real-Time Unity SceneManager is a utility that keeps track of the names of scenes in Unity projects and generates scripts that can be utilized for code completion purposes.

Resources

License

MIT, Unknown licenses found

Licenses found

MIT
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages