forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleSystemWindow.cs
More file actions
312 lines (255 loc) · 10.4 KB
/
Copy pathParticleSystemWindow.cs
File metadata and controls
312 lines (255 loc) · 10.4 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.IO;
namespace UnityEditor
{
internal class ParticleSystemWindow : EditorWindow, ParticleEffectUIOwner
{
static ParticleSystemWindow s_Instance;
ParticleSystem m_Target;
ParticleEffectUI m_ParticleEffectUI;
bool m_IsVisible;
private static GUIContent[] s_Icons;
class Texts
{
public GUIContent lockParticleSystem = new GUIContent("", "Lock the current selected Particle System");
public GUIContent previewAll = EditorGUIUtility.TrTextContent("Simulate All", "Simulate all particle systems that have Play On Awake set");
}
static Texts s_Texts;
public Editor customEditor { get; set; }
static public void CreateWindow()
{
s_Instance = EditorWindow.GetWindow<ParticleSystemWindow>();
s_Instance.titleContent = EditorGUIUtility.TrTextContent("Particle Effect");
s_Instance.minSize = ParticleEffectUI.GetMinSize();
}
internal static ParticleSystemWindow GetInstance()
{
return s_Instance;
}
internal bool IsVisible()
{
return m_IsVisible;
}
// Prevent created from outside
private ParticleSystemWindow()
{
}
void OnEnable()
{
s_Instance = this;
m_Target = null; // Ensure we recreate EffectUI after script reloads
ParticleEffectUI.m_VerticalLayout = EditorPrefs.GetBool("ShurikenVerticalLayout", false);
// Get notified when hierarchy- or project window has changes so we can detect if particle systems have been dragged in or out.
EditorApplication.hierarchyChanged += OnHierarchyOrProjectWindowWasChanged;
EditorApplication.projectChanged += OnHierarchyOrProjectWindowWasChanged;
SceneView.onSceneGUIDelegate += OnSceneViewGUI;
EditorApplication.pauseStateChanged += OnPauseStateChanged;
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
Undo.undoRedoPerformed += UndoRedoPerformed;
autoRepaintOnSceneChange = false;
}
void OnDisable()
{
SceneView.onSceneGUIDelegate -= OnSceneViewGUI;
EditorApplication.projectChanged -= OnHierarchyOrProjectWindowWasChanged;
EditorApplication.hierarchyChanged -= OnHierarchyOrProjectWindowWasChanged;
EditorApplication.pauseStateChanged -= OnPauseStateChanged;
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
Undo.undoRedoPerformed -= UndoRedoPerformed;
Clear();
if (s_Instance == this)
s_Instance = null;
}
internal void Clear()
{
m_Target = null;
if (m_ParticleEffectUI != null)
{
m_ParticleEffectUI.Clear();
m_ParticleEffectUI = null;
}
}
void OnPauseStateChanged(PauseState state)
{
Repaint();
}
void OnPlayModeStateChanged(PlayModeStateChange state)
{
// Need to refresh because UpdateAll changes state
Repaint();
}
void UndoRedoPerformed()
{
if (m_ParticleEffectUI != null)
m_ParticleEffectUI.UndoRedoPerformed();
Repaint();
}
private void OnHierarchyOrProjectWindowWasChanged()
{
InitEffectUI();
}
void OnBecameVisible()
{
if (m_IsVisible)
return;
m_IsVisible = true;
InitEffectUI();
SceneView.RepaintAll();
InspectorWindow.RepaintAllInspectors();
}
void OnBecameInvisible()
{
m_IsVisible = false;
Clear();
SceneView.RepaintAll();
InspectorWindow.RepaintAllInspectors();
}
void OnSelectionChange()
{
InitEffectUI();
Repaint();
}
void InitEffectUI()
{
if (!m_IsVisible)
return;
// Use locked particle system if set otherwise check selected gameobject
ParticleSystem target = ParticleSystemEditorUtils.lockedParticleSystem;
if (target == null && Selection.activeGameObject != null)
target = Selection.activeGameObject.GetComponent<ParticleSystem>();
m_Target = target;
if (m_Target != null)
{
if (m_ParticleEffectUI == null)
m_ParticleEffectUI = new ParticleEffectUI(this);
if (m_ParticleEffectUI.InitializeIfNeeded(new ParticleSystem[] { m_Target }))
Repaint();
}
// Cleanup if needed
if (m_Target == null && m_ParticleEffectUI != null)
{
Clear();
Repaint();
SceneView.RepaintAll();
GameView.RepaintAll();
}
}
void Awake()
{
}
void DoToolbarGUI()
{
GUILayout.BeginHorizontal("Toolbar");
using (new EditorGUI.DisabledScope(m_ParticleEffectUI == null))
{
if (!EditorApplication.isPlaying)
{
bool isPlaying = false;
if (m_ParticleEffectUI != null)
{
isPlaying = m_ParticleEffectUI.IsPlaying();
}
if (GUILayout.Button(isPlaying ? ParticleEffectUI.texts.pause : ParticleEffectUI.texts.play, "ToolbarButton", GUILayout.Width(65)))
{
if (m_ParticleEffectUI != null)
{
if (isPlaying)
m_ParticleEffectUI.Pause();
else
m_ParticleEffectUI.Play();
}
Repaint(); // we switch texts
}
if (GUILayout.Button(ParticleEffectUI.texts.stop, "ToolbarButton"))
if (m_ParticleEffectUI != null)
m_ParticleEffectUI.Stop();
}
else
{
// In play mode we have pulse play behavior
if (GUILayout.Button(ParticleEffectUI.texts.play, "ToolbarButton", GUILayout.Width(65)))
{
if (m_ParticleEffectUI != null)
{
m_ParticleEffectUI.Stop();
m_ParticleEffectUI.Play();
}
}
if (GUILayout.Button(ParticleEffectUI.texts.stop, "ToolbarButton"))
{
if (m_ParticleEffectUI != null)
m_ParticleEffectUI.Stop();
}
}
GUILayout.FlexibleSpace();
bool isShowOnlySelected = m_ParticleEffectUI != null ? m_ParticleEffectUI.IsShowOnlySelectedMode() : false;
bool newState = GUILayout.Toggle(isShowOnlySelected, isShowOnlySelected ? "Show: Selected" : "Show: All", ParticleSystemStyles.Get().toolbarButtonLeftAlignText, GUILayout.Width(100));
if (newState != isShowOnlySelected && m_ParticleEffectUI != null)
m_ParticleEffectUI.SetShowOnlySelectedMode(newState);
// Resimulation toggle
ParticleSystemEditorUtils.resimulation = GUILayout.Toggle(ParticleSystemEditorUtils.resimulation, ParticleEffectUI.texts.resimulation, "ToolbarButton");
// Bounds toggle
ParticleEffectUI.m_ShowBounds = GUILayout.Toggle(ParticleEffectUI.m_ShowBounds, ParticleEffectUI.texts.showBounds, "ToolbarButton");
// Editor layout
if (GUILayout.Button(ParticleEffectUI.m_VerticalLayout ? s_Icons[0] : s_Icons[1], "ToolbarButton"))
{
ParticleEffectUI.m_VerticalLayout = !ParticleEffectUI.m_VerticalLayout;
EditorPrefs.SetBool("ShurikenVerticalLayout", ParticleEffectUI.m_VerticalLayout);
{
Clear();
}
}
// Lock toggle
GUILayout.BeginVertical();
GUILayout.Space(3);
ParticleSystem lockedParticleSystem = ParticleSystemEditorUtils.lockedParticleSystem;
bool isLocked = lockedParticleSystem != null;
bool newLocked = GUILayout.Toggle(isLocked, s_Texts.lockParticleSystem, "IN LockButton");
if (isLocked != newLocked)
{
if (m_ParticleEffectUI != null && m_Target != null)
{
if (newLocked)
ParticleSystemEditorUtils.lockedParticleSystem = m_Target;
else
ParticleSystemEditorUtils.lockedParticleSystem = null;
}
}
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
}
void OnGUI()
{
if (s_Texts == null)
s_Texts = new Texts();
if (s_Icons == null)
s_Icons = new GUIContent[] { EditorGUIUtility.IconContent("HorizontalSplit"), EditorGUIUtility.IconContent("VerticalSplit") };
if (m_Target == null && (Selection.activeGameObject != null || ParticleSystemEditorUtils.lockedParticleSystem != null))
{
InitEffectUI();
}
DoToolbarGUI();
if (m_Target != null && m_ParticleEffectUI != null)
m_ParticleEffectUI.OnGUI();
}
public void OnSceneViewGUI(SceneView sceneView)
{
if (!m_IsVisible)
return;
if (m_ParticleEffectUI != null)
{
m_ParticleEffectUI.OnSceneViewGUI();
}
}
void OnDidOpenScene()
{
Repaint();
}
} // ParticleSystemWindow
} // UnityEditor