forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleSystemEditor.cs
More file actions
255 lines (216 loc) · 8.98 KB
/
Copy pathParticleSystemEditor.cs
File metadata and controls
255 lines (216 loc) · 8.98 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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
namespace UnityEditor
{
[CustomEditor(typeof(ParticleSystem))]
[CanEditMultipleObjects]
internal class ParticleSystemInspector : Editor, ParticleEffectUIOwner
{
ParticleEffectUI m_ParticleEffectUI;
GUIContent m_PreviewTitle = EditorGUIUtility.TrTextContent("Particle System Curves");
GUIContent showWindowText = EditorGUIUtility.TrTextContent("Open Editor...");
GUIContent closeWindowText = EditorGUIUtility.TrTextContent("Close Editor");
GUIContent hideWindowText = EditorGUIUtility.TrTextContent("Hide Editor");
static GUIContent m_PlayBackTitle;
public static GUIContent playBackTitle
{
get
{
if (m_PlayBackTitle == null)
m_PlayBackTitle = EditorGUIUtility.TrTextContent("Particle Effect");
return m_PlayBackTitle;
}
}
private bool selectedInParticleSystemWindow
{
get
{
GameObject targetGameObject = (target as ParticleSystem).gameObject;
GameObject currentGameObject;
if (ParticleSystemEditorUtils.lockedParticleSystem == null)
currentGameObject = Selection.activeGameObject;
else
currentGameObject = ParticleSystemEditorUtils.lockedParticleSystem.gameObject;
return currentGameObject == targetGameObject;
}
}
public Editor customEditor { get { return this; } }
public void OnEnable()
{
// Get notified when hierarchy- or project window has changes so we can detect if particle systems have been dragged in or out.
EditorApplication.hierarchyChanged += HierarchyOrProjectWindowWasChanged;
EditorApplication.projectChanged += HierarchyOrProjectWindowWasChanged;
SceneView.onSceneGUIDelegate += OnSceneViewGUI;
Undo.undoRedoPerformed += UndoRedoPerformed;
}
public void OnDisable()
{
SceneView.onSceneGUIDelegate -= OnSceneViewGUI;
EditorApplication.projectChanged -= HierarchyOrProjectWindowWasChanged;
EditorApplication.hierarchyChanged -= HierarchyOrProjectWindowWasChanged;
Undo.undoRedoPerformed -= UndoRedoPerformed;
if (m_ParticleEffectUI != null)
m_ParticleEffectUI.Clear();
}
private void HierarchyOrProjectWindowWasChanged()
{
// target can be null if child particle system was deleted when ParticleSystemWindow is open
if (target != null && ShouldShowInspector())
Init(true);
}
void UndoRedoPerformed()
{
Init(true);
if (m_ParticleEffectUI != null)
m_ParticleEffectUI.UndoRedoPerformed();
}
private void Init(bool forceInit)
{
IEnumerable<ParticleSystem> systems = from p in targets.OfType<ParticleSystem>() where (p != null) select p;
if (systems == null || !systems.Any())
{
m_ParticleEffectUI = null;
return;
}
if (m_ParticleEffectUI == null)
{
m_ParticleEffectUI = new ParticleEffectUI(this);
m_ParticleEffectUI.InitializeIfNeeded(systems);
}
else if (forceInit)
{
m_ParticleEffectUI.InitializeIfNeeded(systems);
}
}
void ShowEdiorButtonGUI()
{
GUILayout.BeginHorizontal();
{
GUILayout.FlexibleSpace();
if (m_ParticleEffectUI == null || !m_ParticleEffectUI.multiEdit)
{
bool alreadySelected = selectedInParticleSystemWindow;
GameObject targetGameObject = (target as ParticleSystem).gameObject;
GUIContent text = null;
ParticleSystemWindow window = ParticleSystemWindow.GetInstance();
if (window)
window.customEditor = this; // window can be created by LoadWindowLayout, when Editor starts up, so always make sure the custom editor member is set up (case 930005)
if (window && window.IsVisible() && alreadySelected)
{
if (window.GetNumTabs() > 1)
text = hideWindowText;
else
text = closeWindowText;
}
else
{
text = showWindowText;
}
if (GUILayout.Button(text, EditorStyles.miniButton, GUILayout.Width(110)))
{
if (window && window.IsVisible() && alreadySelected)
{
// Hide window (close instead if not possible)
if (!window.ShowNextTabIfPossible())
window.Close();
}
else
{
if (!alreadySelected)
{
ParticleSystemEditorUtils.lockedParticleSystem = null;
Selection.activeGameObject = targetGameObject;
}
if (window)
{
if (!alreadySelected)
window.Clear();
// Show window
window.Focus();
}
else
{
// Kill inspector gui first to ensure playback time is cached properly
Clear();
// Create new window
ParticleSystemWindow.CreateWindow();
window = ParticleSystemWindow.GetInstance();
window.customEditor = this;
GUIUtility.ExitGUI();
}
}
}
}
}
GUILayout.EndHorizontal();
}
public override bool UseDefaultMargins() { return false; }
public override void OnInspectorGUI()
{
EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
ShowEdiorButtonGUI();
if (ShouldShowInspector())
{
if (m_ParticleEffectUI == null)
Init(true);
EditorGUILayout.EndVertical();
EditorGUILayout.BeginVertical(EditorStyles.inspectorFullWidthMargins);
m_ParticleEffectUI.OnGUI();
EditorGUILayout.EndVertical();
EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins);
}
else
{
Clear();
}
EditorGUILayout.EndVertical();
}
void Clear()
{
if (m_ParticleEffectUI != null)
m_ParticleEffectUI.Clear();
m_ParticleEffectUI = null;
}
private bool ShouldShowInspector()
{
// Only show the inspector GUI if we are not showing the ParticleSystemWindow
ParticleSystemWindow window = ParticleSystemWindow.GetInstance();
return !window || !window.IsVisible() || !selectedInParticleSystemWindow;
}
public void OnSceneViewGUI(SceneView sceneView)
{
if (ShouldShowInspector())
{
Init(false); // Here because can be called before inspector GUI so to prevent blinking GUI when selecting ps.
if (m_ParticleEffectUI != null)
{
m_ParticleEffectUI.OnSceneViewGUI();
}
}
}
public override bool HasPreviewGUI()
{
return ShouldShowInspector();
}
public override void DrawPreview(Rect previewArea)
{
ObjectPreview.DrawPreview(this, previewArea, new Object[] { targets[0] }); // only draw the first preview - all the selected systems share it
}
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
if (m_ParticleEffectUI != null)
m_ParticleEffectUI.GetParticleSystemCurveEditor().OnGUI(r);
}
public override GUIContent GetPreviewTitle()
{
return m_PreviewTitle;
}
public override void OnPreviewSettings()
{
}
}
} // namespace UnityEditor