Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Scene Switcher Utility Window for Unity

Scene Switcher

A Scene Switcher Utility Window for Unity, Switch between Scenes Effortlessly.

Inspired by Kenney sceneWindow.cs

Deprecation Notice

This gist is deprecated due to release of this utility on Asset Store, you can now get the latest version of this utility from Asset Store, but it is available here as is without any updates.

Features

  • Simplicity
  • Multiple Sources (Assets and Build Settings)
  • Open Scenes by Desired Mode

Screenshots

Scene Switcher Window

Installation

  • Download or Copy/Paste the Script to an Editor folder in Unity like Assets/Editor
  • Navigate to Tools > Scene Switcher menu to open the window
  • You are ready to go!

Related

Resources

License

MIT @ Hasan Bayat

Made with ❤️ by Hasan Bayat

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
using UnityEditor.SceneManagement;
public class SceneSwitcherWindow : EditorWindow
{
public enum ScenesSource
{
Assets,
BuildSettings
}
protected Vector2 scrollPosition;
protected ScenesSource scenesSource = ScenesSource.Assets;
protected OpenSceneMode openSceneMode = OpenSceneMode.Single;
[MenuItem ( "Tools/Scene Switcher" )]
public static void Init ()
{
var window = EditorWindow.GetWindow<SceneSwitcherWindow> ( "Scene Switcher" );
window.Show ();
}
protected virtual void OnGUI ()
{
List<EditorBuildSettingsScene> buildScenes = new List<EditorBuildSettingsScene> ( EditorBuildSettings.scenes );
this.scenesSource = ( ScenesSource )EditorGUILayout.EnumPopup ( "Scenes Source", this.scenesSource );
this.openSceneMode = ( OpenSceneMode )EditorGUILayout.EnumPopup ( "Open Scene Mode", this.openSceneMode );
GUILayout.Label ( "Scenes", EditorStyles.boldLabel );
string [] guids = AssetDatabase.FindAssets ( "t:Scene" );
this.scrollPosition = EditorGUILayout.BeginScrollView ( this.scrollPosition );
EditorGUILayout.BeginVertical ();
for ( int i = 0; i < guids.Length; i++ )
{
string path = AssetDatabase.GUIDToAssetPath ( guids [ i ] );
SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath<SceneAsset> ( path );
EditorBuildSettingsScene buildScene = buildScenes.Find ( (editorBuildScene ) =>
{
return editorBuildScene.path == path;
} );
Scene scene = SceneManager.GetSceneByPath ( path );
bool isOpen = scene.IsValid () && scene.isLoaded;
GUI.enabled = !isOpen;
if ( this.scenesSource == ScenesSource.Assets )
{
if ( GUILayout.Button ( sceneAsset.name ) )
{
Open ( path );
}
}
else
{
if ( buildScene != null )
{
if ( GUILayout.Button ( sceneAsset.name ) )
{
Open ( path );
}
}
}
GUI.enabled = true;
}
if ( GUILayout.Button ( "Create New Scene" ) )
{
Scene newScene = EditorSceneManager.NewScene ( NewSceneSetup.DefaultGameObjects, NewSceneMode.Single );
EditorSceneManager.SaveScene ( newScene );
}
EditorGUILayout.EndVertical ();
EditorGUILayout.EndScrollView ();
}
public virtual void Open ( string path )
{
if ( EditorSceneManager.EnsureUntitledSceneHasBeenSaved ( "You don't have saved the Untitled Scene, Do you want to leave?" ) )
{
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo ();
EditorSceneManager.OpenScene ( path, this.openSceneMode );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment