-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScriptableSceneManagerWindow.cs
131 lines (108 loc) · 4.5 KB
/
ScriptableSceneManagerWindow.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
using System.Collections.Generic;
using CHARK.ScriptableScenes.Editor.Elements;
using CHARK.ScriptableScenes.Editor.Utilities;
using CHARK.ScriptableScenes.Utilities;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace CHARK.ScriptableScenes.Editor
{
/// <summary>
/// Window used to manage all available <see cref="ScriptableSceneCollection"/> assets.
/// </summary>
internal sealed class ScriptableSceneManagerWindow : EditorWindow
{
[SerializeField]
private StyleSheet styleSheet;
private readonly List<ScriptableSceneCollection> sceneCollections = new();
private ScriptableSceneCollectionGlobalActions globalActionsElement;
private ScriptableSceneCollectionList collectionListElement;
[MenuItem(
MenuItemConstants.BaseWindowItemName + "/Scriptable Scenes",
priority = MenuItemConstants.BaseWindowPriority
)]
private static void ShowWindow()
{
var sceneManagerWindow = GetWindow<ScriptableSceneManagerWindow>();
sceneManagerWindow.titleContent = new GUIContent("Scriptable Scenes");
var minSize = sceneManagerWindow.minSize;
minSize.x = 250f;
minSize.y = 100f;
sceneManagerWindow.minSize = minSize;
sceneManagerWindow.Show();
}
private void OnEnable()
{
ScriptableSceneEditorUtilities.OnEditorStateChanged += OnEditorStateChanged;
InitializeUIElements();
BindUIElements();
}
private void OnDisable()
{
ScriptableSceneEditorUtilities.OnEditorStateChanged -= OnEditorStateChanged;
}
private void InitializeUIElements()
{
globalActionsElement = new ScriptableSceneCollectionGlobalActions();
globalActionsElement.OnStopButtonClicked += OnGlobalActionsStopButtonClicked;
globalActionsElement.OnPauseButtonClicked += OnGlobalActionsPauseButtonClicked;
globalActionsElement.OnStepButtonClicked += OnGlobalActionsStepButtonClicked;
collectionListElement = new ScriptableSceneCollectionList(sceneCollections);
collectionListElement.OnSortOrderChanged += CollectionListElementSortOrderChanged;
collectionListElement.OnOpenButtonClicked += CollectionListElementOpenButtonClicked;
collectionListElement.OnPlayButtonClicked += CollectionListElementPlayButtonClicked;
collectionListElement.OnLoadButtonClicked += CollectionListElementLoadButtonClicked;
rootVisualElement.styleSheets.Add(styleSheet);
rootVisualElement.AddToClassList("window-content");
rootVisualElement.Add(globalActionsElement);
rootVisualElement.Add(collectionListElement);
}
private void OnEditorStateChanged()
{
BindUIElements();
}
private static void OnGlobalActionsStopButtonClicked()
{
ScriptableSceneEditorUtilities.StopGame();
}
private static void OnGlobalActionsPauseButtonClicked()
{
ScriptableSceneEditorUtilities.SetPausedGame(EditorApplication.isPaused == false);
}
private static void OnGlobalActionsStepButtonClicked()
{
ScriptableSceneEditorUtilities.StepGame();
}
private void CollectionListElementSortOrderChanged()
{
for (var index = 0; index < sceneCollections.Count; index++)
{
var collection = sceneCollections[index];
if (collection.GetDisplayOrder() == index)
{
continue;
}
collection.SetDisplayOrder(index);
}
}
private static void CollectionListElementOpenButtonClicked(ScriptableSceneCollection collection)
{
collection.Open();
}
private static void CollectionListElementPlayButtonClicked(ScriptableSceneCollection collection)
{
collection.Play();
}
private static void CollectionListElementLoadButtonClicked(ScriptableSceneCollection collection)
{
collection.Load();
}
private void BindUIElements()
{
globalActionsElement?.Bind();
sceneCollections.Clear();
sceneCollections.AddRange(ScriptableSceneEditorUtilities.GetScriptableSceneCollections());
collectionListElement?.RefreshItems();
}
}
}