-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneViewer.cs
More file actions
136 lines (115 loc) · 4.78 KB
/
SceneViewer.cs
File metadata and controls
136 lines (115 loc) · 4.78 KB
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
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.IO;
using UnityEditor.SceneManagement;
namespace BYUtils.EditorTools
{
public class SceneViewer : EditorWindow
{
private Vector2 scrollPosition;
private List<string> scenePathList = new List<string>();
private GUIStyle headerStyle;
private GUIStyle buttonStyle;
[MenuItem("Tools/BY Utils/Scene Viewer")]
public static void ShowWindow()
{
SceneViewer window = GetWindow<SceneViewer>("Scene Viewer");
window.minSize = new Vector2(300, 200);
window.Show();
}
private void OnEnable()
{
RefreshSceneList();
}
private void CreateStyles()
{
if (headerStyle == null)
{
headerStyle = new GUIStyle(GUI.skin.label)
{
fontSize = 14,
fontStyle = FontStyle.Bold,
alignment = TextAnchor.MiddleCenter,
padding = new RectOffset(0, 0, 5, 10)
};
}
if (buttonStyle == null)
{
buttonStyle = new GUIStyle(GUI.skin.button)
{
padding = new RectOffset(10, 10, 6, 6),
margin = new RectOffset(10, 10, 4, 4)
};
}
}
private void RefreshSceneList()
{
scenePathList.Clear();
// Find all scene files
string[] sceneGuids = AssetDatabase.FindAssets("t:Scene");
foreach (string guid in sceneGuids)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
// Only add scenes from the Assets folder, exclude Package scenes
if (!string.IsNullOrEmpty(path) && path.StartsWith("Assets/"))
{
scenePathList.Add(path);
}
}
// Sort scenes by name
scenePathList.Sort((a, b) => Path.GetFileNameWithoutExtension(a).CompareTo(Path.GetFileNameWithoutExtension(b)));
}
private void OnGUI()
{
CreateStyles();
EditorGUILayout.BeginVertical();
if (GUILayout.Button("Refresh Scene List", GUILayout.Height(30)))
{
RefreshSceneList();
}
EditorGUILayout.Space(10);
EditorGUILayout.LabelField("Click on a scene below to open it:", EditorStyles.boldLabel);
EditorGUILayout.Space(5);
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
if (scenePathList.Count == 0)
{
EditorGUILayout.HelpBox("No scenes found in the project.", MessageType.Info);
}
else
{
foreach (string scenePath in scenePathList)
{
EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
string sceneName = Path.GetFileNameWithoutExtension(scenePath);
// Main scene button, using ExpandWidth to ensure it takes up most of the space
if (GUILayout.Button(sceneName, buttonStyle, GUILayout.Height(30), GUILayout.ExpandWidth(true)))
{
// Locate and highlight the scene file in Project window
UnityEngine.Object sceneAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(scenePath);
EditorGUIUtility.PingObject(sceneAsset);
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
}
}
// Add button with fixed width
if (GUILayout.Button("Add", GUILayout.Width(50), GUILayout.Height(30)))
{
// Locate and highlight the scene file in Project window
UnityEngine.Object sceneAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(scenePath);
EditorGUIUtility.PingObject(sceneAsset);
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
{
EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space(2); // Add a small vertical spacing
}
}
EditorGUILayout.EndScrollView();
EditorGUILayout.EndVertical();
}
}
}