Skip to content

Commit 7665663

Browse files
authored
Merge pull request #10 from coryleach/dev
Merge version 1.0.3
2 parents 6026c6b + 0fd9ad6 commit 7665663

File tree

3 files changed

+135
-63
lines changed

3 files changed

+135
-63
lines changed

Editor/SceneSwitcherWindow.cs

+131-45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Linq;
33
using UnityEditor;
44
using UnityEditor.SceneManagement;
@@ -21,10 +21,37 @@ private static void OpenWindow()
2121
[System.Serializable]
2222
private class SceneSwitcherData
2323
{
24-
public List<string> sceneGuids = new List<string>();
24+
public List<SceneData> scenes = new List<SceneData>();
2525
public bool sortRecentToTop = true;
2626
public bool loadAdditive = true;
2727
public bool closeScenes = true;
28+
29+
public void AddScene(string guid)
30+
{
31+
if (!scenes.Exists((scene) => scene.guid == guid))
32+
{
33+
var sceneData = new SceneData() { guid = guid, color = Color.white };
34+
35+
scenes.Add(sceneData);
36+
}
37+
}
38+
39+
[System.Serializable]
40+
internal class SceneData
41+
{
42+
public string guid;
43+
public Color color;
44+
public bool foldout;
45+
public BooleanOverride loadAdditive;
46+
public BooleanOverride closeScenes;
47+
}
48+
}
49+
50+
public enum BooleanOverride
51+
{
52+
Default = 0,
53+
Yes = 1,
54+
No = 2
2855
}
2956

3057
private SceneSwitcherData _sceneSwitcherData = new SceneSwitcherData();
@@ -44,6 +71,11 @@ private void OnEnable()
4471
}
4572

4673
private void OnDisable()
74+
{
75+
SaveState();
76+
}
77+
78+
private void SaveState()
4779
{
4880
//Save State
4981
PlayerPrefs.SetString(PrefsKey, JsonUtility.ToJson(_sceneSwitcherData));
@@ -81,7 +113,7 @@ private void OnGUI()
81113
break;
82114
}
83115

84-
if (_sceneSwitcherData.sceneGuids.Count > 0)
116+
if (_sceneSwitcherData.scenes.Count > 0)
85117
{
86118
SceneListGui();
87119
}
@@ -107,67 +139,117 @@ private static void BoxGui(string text)
107139
private void SceneListGui()
108140
{
109141
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
142+
const int lineHeight = 18;
110143

111144
GUILayout.BeginVertical(new GUIStyle("GroupBox"));
112-
foreach (var guid in _sceneSwitcherData.sceneGuids)
145+
foreach (var sceneData in _sceneSwitcherData.scenes)
113146
{
147+
if (sceneData.foldout)
148+
{
149+
GUILayout.BeginVertical(EditorStyles.helpBox);
150+
}
151+
else
152+
{
153+
GUILayout.BeginVertical();
154+
}
155+
114156
GUILayout.BeginHorizontal();
115157

116158
if (_editing)
117159
{
118160
if (GUILayout.Button("↑", GUILayout.MaxWidth(20)))
119161
{
120-
MoveUp(guid);
121-
return;
162+
MoveUp(sceneData);
163+
GUILayout.EndHorizontal();
164+
GUILayout.EndVertical();
165+
break;
122166
}
123-
124-
if (GUILayout.Button("↓", GUILayout.MaxWidth(20)))
167+
else if (GUILayout.Button("↓", GUILayout.MaxWidth(20)))
125168
{
126-
MoveDown(guid);
127-
return;
169+
MoveDown(sceneData);
170+
GUILayout.EndHorizontal();
171+
GUILayout.EndVertical();
172+
break;
128173
}
129174
}
130175

131-
var path = AssetDatabase.GUIDToAssetPath(guid);
176+
var path = AssetDatabase.GUIDToAssetPath(sceneData.guid);
177+
var preColorBG = GUI.backgroundColor;
178+
GUI.backgroundColor = sceneData.color;
179+
132180
if (GUILayout.Button(System.IO.Path.GetFileNameWithoutExtension(path)))
133181
{
182+
GUI.backgroundColor = preColorBG;
134183
// Give user option to save/cancel
135184
if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
136185
{
137-
return;
186+
GUILayout.EndHorizontal();
187+
GUILayout.EndVertical();
188+
break;
138189
}
139190

140-
SwitchToScene(path);
191+
SwitchToScene(sceneData, path);
141192
if (_sceneSwitcherData.sortRecentToTop)
142193
{
143-
MoveToTop(guid);
194+
MoveToTop(sceneData);
144195
}
145196

146-
return;
197+
GUILayout.EndHorizontal();
198+
GUILayout.EndVertical();
199+
break;
147200
}
148201

202+
GUI.backgroundColor = preColorBG;
203+
149204
if (_editing)
150205
{
151206
GUI.backgroundColor = Color.red;
152-
if (GUILayout.Button("X", GUILayout.MaxWidth(20)))
207+
if (GUILayout.Button(EditorGUIUtility.IconContent("d_TreeEditor.Trash"), GUILayout.Width(30)))
153208
{
154-
_sceneSwitcherData.sceneGuids.Remove(guid);
155-
return;
209+
_sceneSwitcherData.scenes.Remove(sceneData);
210+
SaveState();
211+
GUILayout.EndHorizontal();
212+
GUILayout.EndVertical();
213+
break;
156214
}
157-
158215
GUI.backgroundColor = Color.white;
216+
217+
var arrowTexture = sceneData.foldout ? EditorGUIUtility.IconContent("d_scrolldown") : EditorGUIUtility.IconContent("d_scrollup");
218+
if (GUILayout.Button(arrowTexture, GUILayout.Width(25), GUILayout.Height(20)))
219+
{
220+
sceneData.foldout = !sceneData.foldout;
221+
}
159222
}
160223

161224
GUILayout.EndHorizontal();
225+
226+
if (_editing && sceneData.foldout)
227+
{
228+
GUILayout.BeginVertical();
229+
230+
var temp = EditorGUIUtility.labelWidth;
231+
EditorGUIUtility.labelWidth = 100;
232+
233+
sceneData.color = EditorGUILayout.ColorField("Button Tint",sceneData.color);
234+
sceneData.loadAdditive = (BooleanOverride)EditorGUILayout.EnumPopup(new GUIContent("Additive Load", "Loads scenes additively"),sceneData.loadAdditive);
235+
sceneData.closeScenes = (BooleanOverride)EditorGUILayout.EnumPopup(new GUIContent("Close Others", "Will close/unload other scenes when additive loading is active"),sceneData.closeScenes);
236+
237+
EditorGUIUtility.labelWidth = temp;
238+
239+
GUILayout.EndVertical();
240+
}
241+
242+
GUILayout.EndVertical();
243+
162244
}
163245

164246
GUILayout.EndVertical();
165247

166-
const int lineHeight = 18;
167248
if (_editing)
168249
{
169250
//Draw Toggle Buttons
170-
GUILayout.BeginHorizontal();
251+
GUILayout.Label("Default Settings");
252+
GUILayout.BeginHorizontal(new GUIStyle("GroupBox"));
171253
_sceneSwitcherData.sortRecentToTop = GUILayout.Toggle(_sceneSwitcherData.sortRecentToTop,
172254
new GUIContent("Auto Sort", "Will sort most recently used scenes to the top"),
173255
GUILayout.Height(lineHeight));
@@ -177,7 +259,7 @@ private void SceneListGui()
177259
new GUIContent("Close", "Will close/unload other scenes when additive loading is active"),
178260
GUILayout.Height(lineHeight));
179261
GUILayout.EndHorizontal();
180-
262+
181263
//Draw Done Button
182264
GUILayout.BeginHorizontal();
183265

@@ -190,47 +272,53 @@ private void SceneListGui()
190272
GUI.backgroundColor = Color.white;
191273

192274
GUILayout.EndHorizontal();
275+
276+
EditorGUILayout.Space();
277+
EditorGUILayout.Space();
278+
193279
}
194-
280+
195281
EditorGUILayout.EndScrollView();
196282
}
197283

198-
private void MoveToTop(string guid)
284+
private void MoveToTop(SceneSwitcherData.SceneData guid)
199285
{
200-
_sceneSwitcherData.sceneGuids.Remove(guid);
201-
_sceneSwitcherData.sceneGuids.Insert(0, guid);
286+
_sceneSwitcherData.scenes.Remove(guid);
287+
_sceneSwitcherData.scenes.Insert(0, guid);
202288
}
203289

204-
private void MoveUp(string guid)
290+
private void MoveUp(SceneSwitcherData.SceneData guid)
205291
{
206-
var index = _sceneSwitcherData.sceneGuids.IndexOf(guid);
207-
_sceneSwitcherData.sceneGuids.RemoveAt(index);
292+
var index = _sceneSwitcherData.scenes.IndexOf(guid);
293+
_sceneSwitcherData.scenes.RemoveAt(index);
208294
if (index > 0)
209295
{
210296
index--;
211297
}
212298

213-
_sceneSwitcherData.sceneGuids.Insert(index, guid);
299+
_sceneSwitcherData.scenes.Insert(index, guid);
214300
}
215301

216-
private void MoveDown(string guid)
302+
private void MoveDown(SceneSwitcherData.SceneData guid)
217303
{
218-
var index = _sceneSwitcherData.sceneGuids.IndexOf(guid);
219-
_sceneSwitcherData.sceneGuids.RemoveAt(index);
220-
if (index < _sceneSwitcherData.sceneGuids.Count)
304+
var index = _sceneSwitcherData.scenes.IndexOf(guid);
305+
_sceneSwitcherData.scenes.RemoveAt(index);
306+
if (index < _sceneSwitcherData.scenes.Count)
221307
{
222308
index++;
223309
}
224310

225-
_sceneSwitcherData.sceneGuids.Insert(index, guid);
311+
_sceneSwitcherData.scenes.Insert(index, guid);
226312
}
227313

228-
private void SwitchToScene(string path)
314+
private void SwitchToScene(SceneSwitcherData.SceneData sceneData, string path)
229315
{
230-
var scene = EditorSceneManager.OpenScene(path,
231-
_sceneSwitcherData.loadAdditive ? OpenSceneMode.Additive : OpenSceneMode.Single);
316+
var closeScenes = sceneData.closeScenes == BooleanOverride.Default ? _sceneSwitcherData.closeScenes : (sceneData.closeScenes == BooleanOverride.Yes);
317+
var loadAdditively = sceneData.loadAdditive == BooleanOverride.Default ? _sceneSwitcherData.loadAdditive : (sceneData.loadAdditive == BooleanOverride.Yes);
318+
319+
var scene = EditorSceneManager.OpenScene(path, loadAdditively ? OpenSceneMode.Additive : OpenSceneMode.Single);
232320

233-
if (!_sceneSwitcherData.closeScenes)
321+
if (!closeScenes)
234322
{
235323
return;
236324
}
@@ -260,11 +348,9 @@ private void AddObjects(Object[] objects)
260348
var path = AssetDatabase.GetAssetPath(sceneAsset);
261349
var guid = AssetDatabase.AssetPathToGUID(path);
262350

263-
if (!_sceneSwitcherData.sceneGuids.Contains(guid))
264-
{
265-
_sceneSwitcherData.sceneGuids.Add(guid);
266-
}
351+
_sceneSwitcherData.AddScene(guid);
267352
}
353+
SaveState();
268354
}
269355

270356
private static bool IsValidSelection(IEnumerable<Object> objects)
@@ -286,6 +372,6 @@ private void ToggleEdit()
286372
}
287373

288374
#endregion
289-
375+
290376
}
291-
}
377+
}

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ Unity editor window for quick scene switching.
1919
#### Using UnityPackageManager (for Unity 2019.3 or later)
2020
Open the package manager window (menu: Window > Package Manager)<br/>
2121
Select "Add package from git URL...", fill in the pop-up with the following link:<br/>
22-
https://github.com/coryleach/UnitySceneSwitcher.git#1.0.2<br/>
22+
https://github.com/coryleach/UnitySceneSwitcher.git#1.0.3<br/>
2323

2424
#### Using UnityPackageManager (for Unity 2019.1 or later)
2525

2626
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
2727
```js
2828
{
2929
"dependencies": {
30-
"com.gameframe.sceneswitcher": "https://github.com/coryleach/UnitySceneSwitcher.git#1.0.2",
30+
"com.gameframe.sceneswitcher": "https://github.com/coryleach/UnitySceneSwitcher.git#1.0.3",
3131
...
3232
},
3333
}
@@ -76,8 +76,8 @@ Close = Closes other scenes
7676
7777
7878
## Show your support
79-
8079
Give a ⭐️ if this project helped you!
8180
81+
8282
***
8383
_This README was generated with ❤️ by [Gameframe.Packages](https://github.com/coryleach/unitypackages)_

package.json

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
1-
{
2-
"name": "com.gameframe.sceneswitcher",
3-
"displayName": "Gameframe.SceneSwitcher",
4-
"version": "1.0.2",
5-
"description": "Unity editor window for quick scene switching.",
6-
"keywords": [],
7-
"author": {
8-
"name": "Cory Leach",
9-
"email": "cory.leach@gmail.com",
10-
"url": "https://github.com/coryleach",
11-
"github": "coryleach",
12-
"twitter": "coryleach"
13-
},
14-
"repositoryName": "UnitySceneSwitcher"
15-
}
1+
{"name":"com.gameframe.sceneswitcher","displayName":"Gameframe.SceneSwitcher","version":"1.0.3","description":"Unity editor window for quick scene switching.","keywords":[],"author":{"name":"Cory Leach","email":"cory.leach@gmail.com","url":"https://github.com/coryleach","github":"coryleach","twitter":"coryleach","kofi":""},"repositoryName":"UnitySceneSwitcher"}

0 commit comments

Comments
 (0)