-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEzSceneSwitch.cs
184 lines (156 loc) · 6.56 KB
/
EzSceneSwitch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*********************************************************************************************************************
▄█ ▄ ▄████ ▄█ ▄ ▄█ ▄▄▄▄▀ ▄███▄ ▄████ ████▄ █▄▄▄▄ █▀▄▀█
██ █ █▀ ▀ ██ █ ██ ▀▀▀ █ █▀ ▀ █▀ ▀ █ █ █ ▄▀ █ █ █
██ ██ █ █▀▀ ██ ██ █ ██ █ ██▄▄ █▀▀ █ █ █▀▀▌ █ ▄ █
▐█ █ █ █ █ ▐█ █ █ █ ▐█ █ █▄ ▄▀ █ ▀████ █ █ █ █
▐ █ █ █ █ ▐ █ █ █ ▐ ▀ ▀███▀ █ █ █
█ ██ ▀ █ ██ ▀ ▀ ▀
**********************************************[BRANDON BARTRAM]*******************************************************
NOTES: Made this so I can switch between scenes easier without having to navigate to art team folder
*********************************************************************************************************************/
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
//********************************************************************************************************************
[System.Serializable]
public class EzSceneSwitchSettings : ScriptableObject
{
public List<string> scenePaths = new();
}
public class EzSceneSwitch : EditorWindow
{
private EzSceneSwitchSettings settings;
private ReorderableList reorderableList;
private Vector2 scrollPosition;
[MenuItem("Tools/Ez Scene Switch")]
public static void ShowWindow()
{
GetWindow<EzSceneSwitch>("Ez Scene Switch");
}
private void OnEnable()
{
LoadSettings();
SetupReorderableList();
}
private void LoadSettings()
{
settings = AssetDatabase.LoadAssetAtPath<EzSceneSwitchSettings>("Assets/Editor/EzSceneSwitchSettings.asset");
if (settings == null)
{
settings = CreateInstance<EzSceneSwitchSettings>();
AssetDatabase.CreateAsset(settings, "Assets/Editor/EzSceneSwitchSettings.asset");
AssetDatabase.SaveAssets();
}
}
private void SetupReorderableList()
{
reorderableList = new ReorderableList(settings.scenePaths, typeof(string), true, true, false, false)
{
drawHeaderCallback = (Rect rect) =>
{
EditorGUI.LabelField(rect, "Scene List", EditorStyles.boldLabel);
},
drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
{
string path = settings.scenePaths[index];
string sceneName = System.IO.Path.GetFileNameWithoutExtension(path);
Texture2D sceneIcon = AssetPreview.GetMiniThumbnail(AssetDatabase.LoadAssetAtPath<SceneAsset>(path));
rect.y += 2;
rect.height = EditorGUIUtility.singleLineHeight;
if (sceneIcon != null)
{
GUI.DrawTexture(new Rect(rect.x, rect.y, rect.height, rect.height), sceneIcon);
}
EditorGUI.LabelField(new Rect(rect.x + rect.height + 5, rect.y, rect.width - 130, rect.height), sceneName);
// Load Scene button (additive)
if (GUI.Button(new Rect(rect.x + rect.width - 130, rect.y, 60, rect.height), "Load", EditorStyles.miniButtonLeft))
{
LoadSceneAdditive(path);
}
// Unload Scene button
if (GUI.Button(new Rect(rect.x + rect.width - 70, rect.y, 60, rect.height), "Unload", EditorStyles.miniButtonRight))
{
UnloadScene(sceneName);
}
}
};
}
private void OnGUI()
{
GUILayout.Space(10);
GUILayout.BeginVertical("box");
// Limit the height of the list area to around 4 scenes
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(EditorGUIUtility.singleLineHeight * 5 + 10));
// Draw the reorderable list
reorderableList.DoLayoutList();
GUILayout.EndScrollView();
GUILayout.Space(10);
// Buttons at the bottom of the list
if (GUILayout.Button("Add Current Scene", GUILayout.Height(30)))
{
AddCurrentScene();
}
GUILayout.Space(5);
if (GUILayout.Button("Clear Scene List", GUILayout.Height(30)))
{
ClearSceneList();
}
GUILayout.EndVertical();
}
private void LoadSceneAdditive(string path)
{
if (EditorApplication.isPlaying)
{
SceneManager.LoadScene(System.IO.Path.GetFileNameWithoutExtension(path), LoadSceneMode.Additive);
}
else
{
EditorSceneManager.OpenScene(path, OpenSceneMode.Additive);
}
}
private void UnloadScene(string sceneName)
{
if (EditorApplication.isPlaying)
{
SceneManager.UnloadSceneAsync(sceneName);
}
else
{
Scene scene = SceneManager.GetSceneByName(sceneName);
if (scene.isLoaded)
{
EditorSceneManager.CloseScene(scene, true);
}
}
}
private void AddCurrentScene()
{
string activeScenePath = SceneManager.GetActiveScene().path;
if (!settings.scenePaths.Contains(activeScenePath))
{
settings.scenePaths.Add(activeScenePath);
SaveSettings();
}
else
{
EditorUtility.DisplayDialog("Scene Already Added", "This scene is already in the list.", "OK");
}
}
private void ClearSceneList()
{
if (EditorUtility.DisplayDialog("Clear Scene List", "Are you sure you want to clear the scene list?", "Yes", "No"))
{
settings.scenePaths.Clear();
SaveSettings();
}
}
private void SaveSettings()
{
EditorUtility.SetDirty(settings);
AssetDatabase.SaveAssets();
Repaint();
}
}