Set Active Scene#
Scenes / Set Active Scene
Description#
Sets a loaded additive scene as the main active one
Note
The scene must have been additively loaded
Parameters#
| Name | Description |
|---|---|
| Scene | The scene to be set as active |
Code#
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Title("Set Active Scene")]
[Image(typeof(IconUnity), ColorTheme.Type.Blue)]
[Description("Sets a loaded additive scene as the main active one")]
[Category("Scenes/Set Active Scene")]
[Parameter("Scene", "The scene to be set as active")]
[Note("The scene must have been additively loaded")]
[Serializable]
public class InstructionCoreSetActiveScene : Instruction
{
[SerializeField] private GetScene m_Scene = new GetScene();
protected override string GetTitle(GameObject source) => $"Set {this.m_Scene} as active";
protected override Awaitable Run(Args args)
{
int sceneIndex = this.m_Scene.Get(args);
if (sceneIndex >= 0)
{
Scene scene = SceneManager.GetSceneByBuildIndex(sceneIndex);
if (scene.isLoaded) SceneManager.SetActiveScene(scene);
}
return Done;
}
}
}