-
Notifications
You must be signed in to change notification settings - Fork 878
Expand file tree
/
Copy pathVFXViewPreference.cs
More file actions
275 lines (237 loc) · 13.8 KB
/
Copy pathVFXViewPreference.cs
File metadata and controls
275 lines (237 loc) · 13.8 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
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.VFX;
namespace UnityEditor.VFX
{
static class VFXViewPreference
{
private static readonly int kAuthoringPrewarmStepCountPerSecondsDefault = 20;
private static readonly float kAuthoringPrewarmMaxTimeDefault = 3.0f;
private static readonly int kAuthoringPrewarmStepCountPerSecondsMax = 200;
private static readonly float kAuthoringPrewarmMaxTimeMax = 60.0f;
private static bool m_Loaded = false;
private static bool m_DisplayExperimentalOperator = false;
private static bool m_AllowShaderExternalization = false;
private static bool m_GenerateShadersWithDebugSymbols = false;
private static bool m_DisplayExtraDebugInfo = false;
private static bool m_ForceEditionCompilation = false;
private static bool m_AdvancedLogs = false;
private static VFXMainCameraBufferFallback m_CameraBuffersFallback = VFXMainCameraBufferFallback.PreferMainCamera;
private static bool m_MultithreadUpdateEnabled = true;
private static bool m_InstancingEnabled = true;
private static int m_AuthoringPrewarmStepCountPerSeconds = kAuthoringPrewarmStepCountPerSecondsDefault;
private static float m_AuthoringPrewarmMaxTime = kAuthoringPrewarmMaxTimeDefault;
private static bool m_VisualEffectTargetListed = false;
public static bool displayExperimentalOperator
{
get
{
LoadIfNeeded();
return m_DisplayExperimentalOperator;
}
}
public static bool displayExtraDebugInfo
{
get
{
LoadIfNeeded();
return m_DisplayExtraDebugInfo;
}
}
public static bool generateShadersWithDebugSymbols
{
get
{
LoadIfNeeded();
return m_GenerateShadersWithDebugSymbols;
}
}
public static bool advancedLogs
{
get
{
LoadIfNeeded();
return m_AdvancedLogs;
}
}
public static bool forceEditionCompilation
{
get
{
LoadIfNeeded();
return m_ForceEditionCompilation;
}
}
public static VFXMainCameraBufferFallback cameraBuffersFallback
{
get
{
LoadIfNeeded();
return m_CameraBuffersFallback;
}
}
public static bool multithreadUpdateEnabled
{
get
{
LoadIfNeeded();
return m_MultithreadUpdateEnabled;
}
}
public static bool instancingEnabled
{
get
{
LoadIfNeeded();
return m_InstancingEnabled;
}
}
public static int authoringPrewarmStepCountPerSeconds
{
get
{
LoadIfNeeded();
return m_AuthoringPrewarmStepCountPerSeconds;
}
}
public static float authoringPrewarmMaxTime
{
get
{
LoadIfNeeded();
return m_AuthoringPrewarmMaxTime;
}
}
public static bool visualEffectTargetListed
{
get
{
LoadIfNeeded();
return m_VisualEffectTargetListed;
}
}
public const string experimentalOperatorKey = "VFX.displayExperimentalOperatorKey";
public const string extraDebugInfoKey = "VFX.ExtraDebugInfo";
public const string forceEditionCompilationKey = "VFX.ForceEditionCompilation";
public const string allowShaderExternalizationKey = "VFX.allowShaderExternalization";
public const string generateShadersWithDebugSymbolsKey = "VFX.generateShadersWithDebugSymbols";
public const string advancedLogsKey = "VFX.AdvancedLogs";
public const string cameraBuffersFallbackKey = "VFX.CameraBuffersFallback";
public const string multithreadUpdateEnabledKey = "VFX.MultithreadUpdateEnabled";
public const string instancingEnabledKey = "VFX.InstancingEnabled";
public const string authoringPrewarmStepCountPerSecondsKey = "VFX.AuthoringPrewarmStepCountPerSeconds";
public const string authoringPrewarmMaxTimeKey = "VFX.AuthoringPrewarmMaxTimeKey";
public const string visualEffectTargetListedKey = UnityEditor.ShaderGraph.VFXTarget.kVisualEffectTargetListedKey;
private static void LoadIfNeeded()
{
if (!m_Loaded)
{
m_DisplayExperimentalOperator = EditorPrefs.GetBool(experimentalOperatorKey, false);
m_DisplayExtraDebugInfo = EditorPrefs.GetBool(extraDebugInfoKey, false);
m_ForceEditionCompilation = EditorPrefs.GetBool(forceEditionCompilationKey, false);
m_AllowShaderExternalization = EditorPrefs.GetBool(allowShaderExternalizationKey, false);
m_GenerateShadersWithDebugSymbols = EditorPrefs.GetBool(generateShadersWithDebugSymbolsKey, false);
m_AdvancedLogs = EditorPrefs.GetBool(advancedLogsKey, false);
m_CameraBuffersFallback = (VFXMainCameraBufferFallback)EditorPrefs.GetInt(cameraBuffersFallbackKey, (int)VFXMainCameraBufferFallback.PreferMainCamera);
m_MultithreadUpdateEnabled = EditorPrefs.GetBool(multithreadUpdateEnabledKey, true);
m_InstancingEnabled = EditorPrefs.GetBool(instancingEnabledKey, true);
m_AuthoringPrewarmStepCountPerSeconds = EditorPrefs.GetInt(authoringPrewarmStepCountPerSecondsKey, kAuthoringPrewarmStepCountPerSecondsDefault);
m_AuthoringPrewarmStepCountPerSeconds = Mathf.Clamp(m_AuthoringPrewarmStepCountPerSeconds, 0, kAuthoringPrewarmStepCountPerSecondsMax);
m_AuthoringPrewarmMaxTime = EditorPrefs.GetFloat(authoringPrewarmMaxTimeKey, kAuthoringPrewarmMaxTimeDefault);
m_AuthoringPrewarmMaxTime = Mathf.Clamp(m_AuthoringPrewarmMaxTime, 0.0f, kAuthoringPrewarmMaxTimeMax);
m_VisualEffectTargetListed = EditorPrefs.GetBool(visualEffectTargetListedKey, false);
m_Loaded = true;
}
}
class VFXSettingsProvider : SettingsProvider
{
public VFXSettingsProvider() : base("Preferences/Visual Effects", SettingsScope.User)
{
hasSearchInterestHandler = HasSearchInterestHandler;
}
bool HasSearchInterestHandler(string searchContext)
{
return true;
}
private static void ForEachVFXInProject(Action<VisualEffectAsset> func)
{
var vfxAssets = new HashSet<VisualEffectAsset>();
var vfxAssetsGuid = AssetDatabase.FindAssets("t:VisualEffectAsset");
foreach (var guid in vfxAssetsGuid)
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
var vfxAsset = AssetDatabase.LoadAssetAtPath<VisualEffectAsset>(assetPath);
if (vfxAsset != null)
vfxAssets.Add(vfxAsset);
}
foreach (var vfxAsset in vfxAssets)
func(vfxAsset);
}
private static bool DisplayReimportPopup()
{
return EditorUtility.DisplayDialog("Recompile all VFX?", "This change will only apply upon VFX asset recompilation.\n\nDo you want to recompile all VFX assets in the project? (This may take some time)", "Yes", "No");
}
public override void OnGUI(string searchContext)
{
using (new SettingsWindow.GUIScope())
{
LoadIfNeeded();
m_DisplayExperimentalOperator = EditorGUILayout.Toggle(new GUIContent("Experimental Operators/Blocks", "When enabled, operators and blocks which are still in an experimental state become available to use within the Visual Effect Graph."), m_DisplayExperimentalOperator);
m_DisplayExtraDebugInfo = EditorGUILayout.Toggle(new GUIContent("Show Additional Debug info", "When enabled, additional information becomes available in the inspector when selecting blocks, such as the attributes they use and their shader code."), m_DisplayExtraDebugInfo);
m_AdvancedLogs = EditorGUILayout.Toggle(new GUIContent("Verbose Mode for compilation", "When enabled, additional information about the data, expressions, and generated shaders is displayed in the console whenever a graph is compiled."), m_AdvancedLogs);
m_AllowShaderExternalization = EditorGUILayout.Toggle(new GUIContent("Experimental shader externalization", "When enabled, the generated shaders are stored alongside the Visual Effect asset, enabling their direct modification."), m_AllowShaderExternalization);
bool oldGenerateShaderWithDebugSymbols = m_GenerateShadersWithDebugSymbols;
m_GenerateShadersWithDebugSymbols = EditorGUILayout.Toggle(new GUIContent("Generate Shaders with Debug Symbols", "When enabled, the VFX shaders are generated with debug symbols."), m_GenerateShadersWithDebugSymbols);
if (oldGenerateShaderWithDebugSymbols != m_GenerateShadersWithDebugSymbols && DisplayReimportPopup())
ForEachVFXInProject(vfx => AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(vfx.GetResource())));
bool oldForceEditionCompilation = m_ForceEditionCompilation;
m_ForceEditionCompilation = EditorGUILayout.Toggle(new GUIContent("Force Compilation in Edition Mode", "When enabled, the unoptimized edit version of the Visual Effect is compiled even when the effect is not being edited. Otherwise, an optimized runtime version is compiled."), m_ForceEditionCompilation);
if (m_ForceEditionCompilation != oldForceEditionCompilation)
{
bool forceReimport = DisplayReimportPopup();
ForEachVFXInProject(vfx => vfx.GetResource().GetOrCreateGraph().SetCompilationMode(m_ForceEditionCompilation ? VFXCompilationMode.Edition : VFXCompilationMode.Runtime, forceReimport));
}
#if UNITY_2022_1_OR_NEWER
if (Unsupported.IsDeveloperMode())
{
m_MultithreadUpdateEnabled = EditorGUILayout.Toggle(new GUIContent("Multithread Update Enabled", "When enabled, visual effects will be updated in parallel when possible."), m_MultithreadUpdateEnabled);
m_InstancingEnabled = EditorGUILayout.Toggle(new GUIContent("Instancing Enabled", "When enabled, visual effects will be processed in batches when possible."), m_InstancingEnabled);
}
#endif
m_CameraBuffersFallback = (VFXMainCameraBufferFallback)EditorGUILayout.EnumPopup(new GUIContent("Main Camera fallback", "Specifies the camera source for MainCamera Operators and Blocks to use when in the editor."), m_CameraBuffersFallback);
m_VisualEffectTargetListed = EditorGUILayout.Toggle(new GUIContent("Show Target in Shader Graph (deprecated)", "When enabled, the Visual Effect Target is listed in Active Targets dropdown in Shader Graph."), m_VisualEffectTargetListed);
m_AuthoringPrewarmStepCountPerSeconds = EditorGUILayout.IntField(new GUIContent("Authoring Prewarm Step Count Per Second", "Specifies the step count per second for prewarming during VFX authoring. High values may impact performance."), m_AuthoringPrewarmStepCountPerSeconds);
m_AuthoringPrewarmMaxTime = EditorGUILayout.FloatField(new GUIContent("Authoring Prewarm Maximum Time", "Specifies the maximum prewarming time allowed during VFX authoring in seconds. High values may impact performance."), m_AuthoringPrewarmMaxTime);
if (GUI.changed)
{
EditorPrefs.SetBool(experimentalOperatorKey, m_DisplayExperimentalOperator);
EditorPrefs.SetBool(extraDebugInfoKey, m_DisplayExtraDebugInfo);
EditorPrefs.SetBool(forceEditionCompilationKey, m_ForceEditionCompilation);
EditorPrefs.SetBool(advancedLogsKey, m_AdvancedLogs);
EditorPrefs.SetBool(allowShaderExternalizationKey, m_AllowShaderExternalization);
EditorPrefs.SetBool(generateShadersWithDebugSymbolsKey, m_GenerateShadersWithDebugSymbols);
EditorPrefs.SetInt(cameraBuffersFallbackKey, (int)m_CameraBuffersFallback);
EditorPrefs.SetBool(multithreadUpdateEnabledKey, m_MultithreadUpdateEnabled);
EditorPrefs.SetBool(instancingEnabledKey, m_InstancingEnabled);
m_AuthoringPrewarmStepCountPerSeconds = Mathf.Clamp(m_AuthoringPrewarmStepCountPerSeconds, 0, kAuthoringPrewarmStepCountPerSecondsMax);
EditorPrefs.SetInt(authoringPrewarmStepCountPerSecondsKey, m_AuthoringPrewarmStepCountPerSeconds);
m_AuthoringPrewarmMaxTime = Mathf.Clamp(m_AuthoringPrewarmMaxTime, 0.0f, kAuthoringPrewarmMaxTimeMax);
EditorPrefs.SetFloat(authoringPrewarmMaxTimeKey, m_AuthoringPrewarmMaxTime);
EditorPrefs.SetBool(visualEffectTargetListedKey, m_VisualEffectTargetListed);
}
}
base.OnGUI(searchContext);
}
}
[SettingsProvider]
public static SettingsProvider PreferenceSettingsProvider()
{
return new VFXSettingsProvider();
}
public static void PreferencesGUI()
{
}
}
}