Skip to content

Commit

Permalink
Change scene recognition method.
Browse files Browse the repository at this point in the history
Use scene path instead of scene name to have uniqueness.
  • Loading branch information
inertiave committed Nov 23, 2020
1 parent 84ba304 commit c2639f2
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions Assets/Plugins/Editor/CustomToolbar/Scripts/CustomToolbarLeft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace UnityToolbarExtender
{
[InitializeOnLoad]
public class CustomToolbarLeft {

class SceneData
{
public string path;
public GUIContent popupDisplay;
}

private static bool _deleteKeys = false;

private static GUIContent savePassiveBtn;
Expand All @@ -18,7 +25,7 @@ public class CustomToolbarLeft {
private static GUIContent reloadSceneBtn;
private static GUIContent startFromFirstSceneBtn;

static GUIContent[] scenesPopupDisplay;
static SceneData[] scenesPopupDisplay;
static string[] scenesPath;
static string[] scenesBuildPath;
static int selectedSceneIndex;
Expand Down Expand Up @@ -118,12 +125,12 @@ public class CustomToolbarLeft {
}

private static void DrawSceneDropdown() {
selectedSceneIndex = EditorGUILayout.Popup(selectedSceneIndex, scenesPopupDisplay, GUILayout.Width(150f));
selectedSceneIndex = EditorGUILayout.Popup(selectedSceneIndex, scenesPopupDisplay.Select(e => e.popupDisplay).ToArray(), GUILayout.Width(150f));

if (GUI.changed && 0 <= selectedSceneIndex && selectedSceneIndex < scenesPopupDisplay.Length) {
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) {
foreach (var scenePath in scenesPath) {
if(GetSceneName(scenePath) == scenesPopupDisplay[selectedSceneIndex].text) {
if((scenePath) == scenesPopupDisplay[selectedSceneIndex].path) {
EditorSceneManager.OpenScene(scenePath);
break;
}
Expand All @@ -134,7 +141,9 @@ public class CustomToolbarLeft {
}

static void RefreshScenesList() {
List<GUIContent> toDisplay = new List<GUIContent>();


List<SceneData> toDisplay = new List<SceneData>();

selectedSceneIndex = -1;

Expand All @@ -157,10 +166,18 @@ public class CustomToolbarLeft {

GUIContent content = new GUIContent(name, EditorGUIUtility.Load("BuildSettings.Editor.Small") as Texture, "Open scene");

toDisplay.Add(content);
toDisplay.Add(new SceneData()
{
path = scenesBuildPath[i],
popupDisplay = content,
});
}

toDisplay.Add(new GUIContent("\0"));
toDisplay.Add(new SceneData()
{
path = "\0",
popupDisplay = new GUIContent("\0"),
});
++usedIds;

for (int i = 0; i < scenesPath.Length; ++i) {
Expand All @@ -174,7 +191,11 @@ public class CustomToolbarLeft {

GUIContent content = new GUIContent(name, "Open scene");

toDisplay.Add(content);
toDisplay.Add(new SceneData()
{
path = scenesPath[i],
popupDisplay = content,
});

++usedIds;
}
Expand Down

0 comments on commit c2639f2

Please sign in to comment.