Skip to content

Instantly share code, notes, and snippets.

@noisecrime
Created June 21, 2014 21:26
Show Gist options
  • Save noisecrime/bcc09d73eac71f801927 to your computer and use it in GitHub Desktop.
Save noisecrime/bcc09d73eac71f801927 to your computer and use it in GitHub Desktop.
Unity - Access Scenes added to build menu in Inspector.
// NoiseCrime Gist
// 2014.06.21
// Unity Version: 3.5.7+
// This script provides access to a projects scene names in the Inspector.
// It uses MenuItem to assing commands to the component context menu.
// Docs: http://docs.unity3d.com/ScriptReference/MenuItem.html
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ExtractSceneNames : MonoBehaviour
{
public string[] m_Level_NameArray;
#if UNITY_EDITOR
static bool m_Level_SkipFirstScene = false;
static bool m_Level_SkipDisabled = false;
private static string[] ReadNames()
{
List<string> temp = new List<string>();
bool firstScene = true;
foreach (UnityEditor.EditorBuildSettingsScene S in UnityEditor.EditorBuildSettings.scenes)
{
if(m_Level_SkipFirstScene && firstScene)
{
firstScene = false;
continue;
}
if(m_Level_SkipDisabled && !S.enabled) continue;
string name = S.path.Substring(S.path.LastIndexOf('/')+1);
name = name.Substring(0,name.Length-6);
temp.Add(name);
}
return temp.ToArray();
}
[UnityEditor.MenuItem("CONTEXT/ExtractSceneNames/Fetch Scene Names")]
private static void FetchSceneNames(UnityEditor.MenuCommand command)
{
ExtractSceneNames context = (ExtractSceneNames)command.context;
context.m_Level_NameArray = ReadNames();
}
// Reset command
private void Reset()
{
m_Level_NameArray = ReadNames();
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment