GithubHelp home page GithubHelp logo

unity3d-runtimescene's Introduction

GitHub package.json version
GitHub issues GitHub pull requests GitHub last commit GitHub license

Unity3D-RuntimeScene

A simple class that lets you reference scenes in the Editor.

Summary

  • Allows referencing scenes in Unity's Inspector
  • Avoids scene name conflicts when using RuntimeScene methods
  • The resulting RuntimeScene instances in build are super lightweight
  • In the editor, allows loading scene not in Build Settings
  • Add or remove scenes from Build Settings using the Context Menu

Installation

Using git

  • In Window -> Package Manager -> Add package from git URL...
  • Paste https://github.com/marc-antoine-girard/Unity3D-RuntimeScene.git

Using OpenUPM

The package is available on the openupm registry. You can install it via openupm-cli.

openupm add com.marc-antoine-girard.runtimescene

Usage

Note If you're using Assemblies, don't forget to reference ShackLab.RuntimeScene

Here's a simple example on how to use RuntimeScene:

public class LoadScene : MonoBehaviour
{
    public RuntimeScene scene;
    void LoadingMethods()
    {
        // Load scene synchronously 
        scene.LoadScene();
        // Load scene asynchronously 
        scene.LoadSceneAsync();
    }
}

RuntimeScene has many overloaded methods, most mirroring SceneManager.LoadScene and SceneManager.LoadSceneAsync.

image

You can also use SceneManager's methods to load scenes, but it is NOT RECOMMENDED.

The biggest advantages of using RuntimeScene's methods over SceneManager are:

  • In Build, RuntimeScene uses the build Index by default instead of the scene's name, which avoids unnexpected behaviour when Build Settings contains multiple scenes with the same name

  • In the Editor, Scenes will load even if not in the Build Settings.

    • The intent behind this decision is to allow faster testing in some situation.

    • Note that loading a scene that is not in the Build Settings will throw a warning in the Editor, letting you know this won't work in build.

    • If you want to opt-out of this feature, you can define "DISABLE_LOAD_EDITOR" Edit -> Project Settings -> Player -> Other Settings -> Scripting Define Symbols

      Warning | Scene {scene name} is not in the build settings. Consider adding it if you plan on using it in build

Editor Tools

You will also get a warning box under the RuntimeScene when referencing a Scene that is not in Build Settings image

You can quickly add or remove the Scene using the Context Menu (right-click):

imageimage

RuntimeScene Methods

public void LoadScene();
public void LoadScene(LoadSceneMode mode);
public void LoadScene(LoadSceneParameters parameters);

public AsyncOperation LoadSceneAsync(bool allowSceneActivation = true);
public AsyncOperation LoadSceneAsync(LoadSceneMode mode, bool allowSceneActivation = true);
public AsyncOperation LoadSceneAsync(LoadSceneParameters parameters, bool allowSceneActivation = true);

Addressables

When using scenes with Addressables, you can use AssetReferenceScene.

Note AssetReferenceScene is only available when Addressables is in the project.

public class LoadScene : MonoBehaviour
{
    public AssetReferenceScene scene;
    void Start()
    {
        scene.LoadSceneAsync();
    }
}

Contributions

Pull requests are welcomed. Please feel free to fix any issues you find, or add new features.

ko-fi

unity3d-runtimescene's People

Contributors

marc-antoine-girard avatar semantic-release-bot avatar

Stargazers

 avatar  avatar

Watchers

 avatar

unity3d-runtimescene's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.