Scene Loader

Code examples to perform various interactions with the Scene Loader

Activate Loaded Scene

Activate the current loaded Scene.
Works only if the SceneLoader has loaded a scene and its AllowSceneActivation option is set to false.
This method enables the ‘allowSceneActivation’ for the CurrentAsyncOperation that has been paused at 90%.

When loading a scene, Unity first loads the scene (load progress from 0% to 90%) and then activates it (load progress from 90% to 100%). It’s a two state process.
This method is meant to be used for after the scene has been loaded and before its activation (at 90% load progress).

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    
    private void Start()
    {
        MySceneLoader.ActivateLoadedScene();
    }
}

Load Scene Async

Loads the Scene, with the current settings (in the SceneLoader), asynchronously in the background

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    
    private void Start()
    {
        MySceneLoader.LoadSceneAsync();
    }
}

Load Scene Async – by build index

Loads a Scene asynchronously in the background, by its index in Build Settings

using Doozy.Engine.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public int MySceneBuildIndex;
    public LoadSceneMode MyLoadSceneMode;
    
    private void Start()
    {
        MySceneLoader.LoadSceneAsync(MySceneBuildIndex, MyLoadSceneMode);
    }
}

Load Scene Async – by scene name

Loads a Scene asynchronously in the background, by its name in Build Settings

using Doozy.Engine.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public string MySceneName;
    public LoadSceneMode MyLoadSceneMode;
    
    private void Start()
    {
        MySceneLoader.LoadSceneAsync(MySceneName, MyLoadSceneMode);
    }
}

Load Scene Async Additive – by build index

Loads a Scene asynchronously in the background, by its index in Build Settings, with the LoadSceneMode.Additive setting

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public int MySceneBuildIndex;
    
    private void Start()
    {
        MySceneLoader.LoadSceneAsyncAdditive(MySceneBuildIndex);
    }
}

Load Scene Async Additive – by scene name

Loads a Scene asynchronously in the background, by its name in Build Settings, with the LoadSceneMode.Additive setting

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public string MySceneName;
    
    private void Start()
    {
        MySceneLoader.LoadSceneAsyncAdditive(MySceneName);
    }
}

Load Scene Async Single- by build index

Loads a Scene asynchronously in the background, by its index in Build Settings, with the LoadSceneMode.Single setting

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public int MySceneBuildIndex;
    
    private void Start()
    {
        MySceneLoader.LoadSceneAsyncSingle(MySceneBuildIndex);
    }
}

Load Scene Async Single – by scene name

Loads a Scene asynchronously in the background, by its name in Build Settings, with the LoadSceneMode.Single setting

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public string MySceneName;
    
    private void Start()
    {
        MySceneLoader.LoadSceneAsyncSingle(MySceneName);
    }
}

Set Allow Scene Activation

Set the AllowSceneActivation that that allows for a Scene to be activated as soon as it is ready

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;

    private void Start()
    {
        //ENABLE - Allow Scene Activation
        MySceneLoader.SetAllowSceneActivation(true);
        
        //DISABLE - Allow Scene Activation
        MySceneLoader.SetAllowSceneActivation(false);
    }
}

Set Load Scene By

Set the GetSceneBy value, that determines what load method this SceneLoader will use by default

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public GetSceneBy GetMethod; //Load method this SceneLoader will use if the load scene method is called without any parameters

    private void Start()
    {
        MySceneLoader.SetLoadSceneBy(GetMethod);
    }
}

Set Load Scene Mode

Set the LoadSceneMode value, that determines how the new scene is loaded by this SceneLoader

using Doozy.Engine.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public LoadSceneMode LoadMode; //Load mode used when loading a scene

    private void Start()
    {
        MySceneLoader.SetLoadSceneMode(LoadMode);
    }
}

Set Progressor

Set the Progressor reference that will get updates when this SceneLoader loads a scene

using Doozy.Engine.Progress;
using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public Progressor MyProgressor;

    private void Start()
    {
        MySceneLoader.SetProgressor(MyProgressor); 
    }
}

Set Scene Activation Delay

Set the activation delay that determines how long will the SceneLoader wait, after a scene has been loaded, before it starts the scene activation process (works only if AllowSceneActivation is enabled)

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public float MyActivationDelay;

    private void Start()
    {
        MySceneLoader.SetSceneActivationDelay(MyActivationDelay);
    }
}

Set Scene Build Index

Set the SceneBuildIndex, in the Build Settings, of the Scene to load

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public int MySceneBuildIndex;

    private void Start()
    {
        MySceneLoader.SetSceneBuildIndex(MySceneBuildIndex);
    }
}

Set Scene Name

Set the SceneName, name or path, of the Scene to load

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;
    public string MySceneName;

    private void Start()
    {
        MySceneLoader.SetSceneName(MySceneName);
    }
}

Set Self Destruct After Scene Loaded

Set this SceneLoader to self destruct (to destroy itself) after it loads a Scene

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public SceneLoader MySceneLoader;

    private void Start()
    {
        //ENABLE - Self Destruct after the Scene Loader loaded a Scene
        MySceneLoader.SetSelfDestructAfterSceneLoaded(true);
        
        //DISABLE - Self Destruct after the Scene Loader loaded a Scene
        MySceneLoader.SetSelfDestructAfterSceneLoaded(false);
    }
}

GLOBAL – Activate Loaded Scenes

Activates all the loaded scenes for all the SceneLoaders that have scenes ready to be activated.
A Scene is ready to be activated if the load progress is at 0.9 (90%).

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    private void Start()
    {
       SceneLoader.ActivateLoadedScenes();
    }
}

GLOBAL – Get Loader

Create a new GameObject with a SceneLoader script attached and then get the reference to the newly created script

using Doozy.Engine.SceneManagement;
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    private void Start()
    {
        SceneLoader loader = SceneLoader.GetLoader();
    }
}