com.wallstop-studios.unity-helpers 2.0.0-rc73.19 → 2.0.0-rc73.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/{Sprites/AnimationCopier.cs → AnimationCopier.cs} +209 -84
- package/Editor/{Sprites/AnimationCreator.cs → AnimationCreator.cs} +100 -29
- package/Editor/AnimationEventEditor.cs +23 -10
- package/Editor/CustomEditors/MatchColliderToSpriteEditor.cs +1 -1
- package/Editor/FitTextureSizeWindow.cs +53 -14
- package/Editor/PrefabChecker.cs +18 -11
- package/Editor/SpriteAtlasGenerator.cs +914 -0
- package/Editor/SpriteAtlasGenerator.cs.meta +3 -0
- package/Editor/{Sprites/SpriteCropper.cs → SpriteCropper.cs} +143 -172
- package/Editor/{Sprites/SpriteSettingsApplier.cs → SpriteSettingsApplier.cs} +77 -12
- package/Editor/{Sprites/TextureResizerWizard.cs → TextureResizerWizard.cs} +1 -1
- package/Editor/{Sprites/TextureSettingsApplier.cs → TextureSettingsApplier.cs} +1 -1
- package/Editor/Utils/DxReadOnlyPropertyDrawer.cs +1 -1
- package/Editor/Utils/GUIHorizontalScope.cs +20 -0
- package/Editor/Utils/GUIHorizontalScope.cs.meta +3 -0
- package/Runtime/Core/DataStructure/Circle.cs +1 -1
- package/Runtime/Core/DataStructure/QuadTree.cs +4 -4
- package/Runtime/Core/Extension/ColorExtensions.cs +5 -5
- package/Runtime/Core/Extension/IEnumerableExtensions.cs +1 -1
- package/Runtime/Core/Extension/UnityExtensions.cs +14 -14
- package/Runtime/Core/Helper/DirectoryHelper.cs +0 -64
- package/Runtime/Core/Helper/Helpers.cs +9 -9
- package/Runtime/Core/Helper/Logging/UnityLogTagFormatter.cs +8 -31
- package/Runtime/Core/Helper/Partials/ObjectHelpers.cs +4 -5
- package/Runtime/Core/Helper/PathHelper.cs +1 -2
- package/Runtime/Core/Random/DotNetRandom.cs +1 -1
- package/Runtime/Core/Random/SplitMix64.cs +1 -1
- package/Runtime/Core/Random/SquirrelRandom.cs +7 -7
- package/Runtime/Core/Random/ThreadLocalRandom.cs +1 -1
- package/Runtime/Core/Random/WyRandom.cs +1 -1
- package/Runtime/Tags/EffectHandler.cs +1 -1
- package/Runtime/UI/LayeredImage.cs +161 -309
- package/Runtime/Utils/AnimatorEnumStateMachine.cs +1 -1
- package/Runtime/Utils/SetTextureImportData.cs +1 -1
- package/Runtime/Utils/TextureScale.cs +4 -4
- package/Styles/Elements/Progress/MarchingAntsProgressBar.cs +20 -20
- package/package.json +1 -17
- package/Editor/CustomEditors/PersistentDirectoryGUI.cs +0 -796
- package/Editor/CustomEditors/PersistentDirectoryGUI.cs.meta +0 -3
- package/Editor/CustomEditors/SourceFolderEntryDrawer.cs +0 -275
- package/Editor/CustomEditors/SourceFolderEntryDrawer.cs.meta +0 -3
- package/Editor/PersistentDirectorySettings.cs +0 -248
- package/Editor/PersistentDirectorySettings.cs.meta +0 -3
- package/Editor/Sprites/ScriptableSpriteAtlas.cs +0 -95
- package/Editor/Sprites/ScriptableSpriteAtlas.cs.meta +0 -3
- package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs +0 -930
- package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs.meta +0 -3
- package/Editor/Sprites.meta +0 -3
- /package/Editor/{Sprites/AnimationCopier.cs.meta → AnimationCopier.cs.meta} +0 -0
- /package/Editor/{Sprites/AnimationCreator.cs.meta → AnimationCreator.cs.meta} +0 -0
- /package/Editor/{Sprites/SpriteCropper.cs.meta → SpriteCropper.cs.meta} +0 -0
- /package/Editor/{Sprites/SpriteSettingsApplier.cs.meta → SpriteSettingsApplier.cs.meta} +0 -0
- /package/Editor/{Sprites/TextureResizerWizard.cs.meta → TextureResizerWizard.cs.meta} +0 -0
- /package/Editor/{Sprites/TextureSettingsApplier.cs.meta → TextureSettingsApplier.cs.meta} +0 -0
|
@@ -1,796 +0,0 @@
|
|
|
1
|
-
namespace WallstopStudios.UnityHelpers.Editor.CustomEditors
|
|
2
|
-
{
|
|
3
|
-
#if UNITY_EDITOR
|
|
4
|
-
using System;
|
|
5
|
-
using UnityEngine;
|
|
6
|
-
using UnityEditor;
|
|
7
|
-
using System.Collections.Generic;
|
|
8
|
-
using System.Linq;
|
|
9
|
-
using Core.Helper;
|
|
10
|
-
using System.IO;
|
|
11
|
-
using Object = UnityEngine.Object;
|
|
12
|
-
|
|
13
|
-
public static class PersistentDirectoryGUI
|
|
14
|
-
{
|
|
15
|
-
private static readonly Dictionary<string, bool> ContextFoldoutStates = new(
|
|
16
|
-
StringComparer.Ordinal
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
public static float DrawFrequentPathsWithEditorGUI(
|
|
20
|
-
Rect parentRect,
|
|
21
|
-
ref float currentY,
|
|
22
|
-
string toolName,
|
|
23
|
-
string contextKey,
|
|
24
|
-
Action<string> onPathClickedFromHistory,
|
|
25
|
-
bool allowExpansion = true,
|
|
26
|
-
int topN = 5,
|
|
27
|
-
string listLabel = "History:"
|
|
28
|
-
)
|
|
29
|
-
{
|
|
30
|
-
if (PersistentDirectorySettings.Instance == null)
|
|
31
|
-
{
|
|
32
|
-
return 0f;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (onPathClickedFromHistory == null)
|
|
36
|
-
{
|
|
37
|
-
Debug.LogError(
|
|
38
|
-
"PersistentDirectoryGUI.DrawFrequentPathsWithEditorGUI: onPathClickedFromHistory callback cannot be null."
|
|
39
|
-
);
|
|
40
|
-
return 0f;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
float startY = currentY;
|
|
44
|
-
float availableWidth = parentRect.width;
|
|
45
|
-
float startX = parentRect.x;
|
|
46
|
-
|
|
47
|
-
DirectoryUsageData[] topPaths = PersistentDirectorySettings.Instance.GetPaths(
|
|
48
|
-
toolName,
|
|
49
|
-
contextKey,
|
|
50
|
-
true,
|
|
51
|
-
topN
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
if (topPaths.Length <= 0)
|
|
55
|
-
{
|
|
56
|
-
return currentY - startY;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
Rect historyLabelRect = new(
|
|
60
|
-
startX,
|
|
61
|
-
currentY,
|
|
62
|
-
availableWidth,
|
|
63
|
-
EditorGUIUtility.singleLineHeight
|
|
64
|
-
);
|
|
65
|
-
EditorGUI.LabelField(historyLabelRect, listLabel, EditorStyles.miniBoldLabel);
|
|
66
|
-
currentY += historyLabelRect.height;
|
|
67
|
-
|
|
68
|
-
foreach (DirectoryUsageData dirData in topPaths)
|
|
69
|
-
{
|
|
70
|
-
Rect historyButtonRect = new(
|
|
71
|
-
startX + 15f,
|
|
72
|
-
currentY,
|
|
73
|
-
availableWidth - 15f,
|
|
74
|
-
EditorGUIUtility.singleLineHeight
|
|
75
|
-
);
|
|
76
|
-
if (
|
|
77
|
-
GUI.Button(
|
|
78
|
-
historyButtonRect,
|
|
79
|
-
new GUIContent($"({dirData.count}) {dirData.path}", dirData.path),
|
|
80
|
-
EditorStyles.miniButtonLeft
|
|
81
|
-
)
|
|
82
|
-
)
|
|
83
|
-
{
|
|
84
|
-
onPathClickedFromHistory.Invoke(dirData.path);
|
|
85
|
-
}
|
|
86
|
-
currentY += historyButtonRect.height;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (allowExpansion)
|
|
90
|
-
{
|
|
91
|
-
string foldoutKey = $"{toolName}/{contextKey}_AllPathsHistory_EditorGUI";
|
|
92
|
-
ContextFoldoutStates.TryAdd(foldoutKey, false);
|
|
93
|
-
DirectoryUsageData[] allPaths = PersistentDirectorySettings.Instance.GetPaths(
|
|
94
|
-
toolName,
|
|
95
|
-
contextKey,
|
|
96
|
-
false,
|
|
97
|
-
0
|
|
98
|
-
);
|
|
99
|
-
if (allPaths.Length > topN)
|
|
100
|
-
{
|
|
101
|
-
Rect expansionFoldoutRect = new(
|
|
102
|
-
startX + 15f,
|
|
103
|
-
currentY,
|
|
104
|
-
availableWidth - 15f,
|
|
105
|
-
EditorGUIUtility.singleLineHeight
|
|
106
|
-
);
|
|
107
|
-
ContextFoldoutStates[foldoutKey] = EditorGUI.Foldout(
|
|
108
|
-
expansionFoldoutRect,
|
|
109
|
-
ContextFoldoutStates[foldoutKey],
|
|
110
|
-
"Show All History (" + allPaths.Length + ")",
|
|
111
|
-
true,
|
|
112
|
-
EditorStyles.foldout
|
|
113
|
-
);
|
|
114
|
-
currentY += expansionFoldoutRect.height;
|
|
115
|
-
|
|
116
|
-
if (ContextFoldoutStates[foldoutKey])
|
|
117
|
-
{
|
|
118
|
-
List<DirectoryUsageData> pathsNotAlreadyInTop = allPaths
|
|
119
|
-
.Skip(topN)
|
|
120
|
-
.ToList();
|
|
121
|
-
if (pathsNotAlreadyInTop.Any())
|
|
122
|
-
{
|
|
123
|
-
foreach (DirectoryUsageData dirData in pathsNotAlreadyInTop)
|
|
124
|
-
{
|
|
125
|
-
Rect moreHistoryButtonRect = new(
|
|
126
|
-
startX + 30f,
|
|
127
|
-
currentY,
|
|
128
|
-
availableWidth - 30f,
|
|
129
|
-
EditorGUIUtility.singleLineHeight
|
|
130
|
-
);
|
|
131
|
-
if (
|
|
132
|
-
GUI.Button(
|
|
133
|
-
moreHistoryButtonRect,
|
|
134
|
-
new GUIContent(
|
|
135
|
-
$"({dirData.count}) {dirData.path}",
|
|
136
|
-
dirData.path
|
|
137
|
-
),
|
|
138
|
-
EditorStyles.miniButtonLeft
|
|
139
|
-
)
|
|
140
|
-
)
|
|
141
|
-
{
|
|
142
|
-
onPathClickedFromHistory.Invoke(dirData.path);
|
|
143
|
-
}
|
|
144
|
-
currentY += moreHistoryButtonRect.height;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
else
|
|
148
|
-
{
|
|
149
|
-
Rect noMorePathsLabelRect = new(
|
|
150
|
-
startX + 30f,
|
|
151
|
-
currentY,
|
|
152
|
-
availableWidth - 30f,
|
|
153
|
-
EditorGUIUtility.singleLineHeight
|
|
154
|
-
);
|
|
155
|
-
EditorGUI.LabelField(
|
|
156
|
-
noMorePathsLabelRect,
|
|
157
|
-
"All paths already displayed.",
|
|
158
|
-
EditorStyles.centeredGreyMiniLabel
|
|
159
|
-
);
|
|
160
|
-
currentY += noMorePathsLabelRect.height;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
currentY += EditorGUIUtility.standardVerticalSpacing;
|
|
167
|
-
return currentY - startY;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
public static float GetDrawFrequentPathsHeightEditorGUI(
|
|
171
|
-
string toolName,
|
|
172
|
-
string contextKey,
|
|
173
|
-
bool allowExpansion = true,
|
|
174
|
-
int topN = 5
|
|
175
|
-
)
|
|
176
|
-
{
|
|
177
|
-
if (PersistentDirectorySettings.Instance == null)
|
|
178
|
-
{
|
|
179
|
-
return 0f;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
float height = 0f;
|
|
183
|
-
DirectoryUsageData[] topPaths = PersistentDirectorySettings.Instance.GetPaths(
|
|
184
|
-
toolName,
|
|
185
|
-
contextKey,
|
|
186
|
-
true,
|
|
187
|
-
topN
|
|
188
|
-
);
|
|
189
|
-
|
|
190
|
-
if (topPaths.Length <= 0)
|
|
191
|
-
{
|
|
192
|
-
return height;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
height +=
|
|
196
|
-
(topPaths.Length + 1)
|
|
197
|
-
* (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
|
|
198
|
-
if (allowExpansion)
|
|
199
|
-
{
|
|
200
|
-
DirectoryUsageData[] allPaths = PersistentDirectorySettings.Instance.GetPaths(
|
|
201
|
-
toolName,
|
|
202
|
-
contextKey,
|
|
203
|
-
false,
|
|
204
|
-
0
|
|
205
|
-
);
|
|
206
|
-
if (allPaths.Length > topN)
|
|
207
|
-
{
|
|
208
|
-
height +=
|
|
209
|
-
EditorGUIUtility.singleLineHeight
|
|
210
|
-
+ EditorGUIUtility.standardVerticalSpacing;
|
|
211
|
-
|
|
212
|
-
string foldoutKey = $"{toolName}/{contextKey}_AllPathsHistory_EditorGUI";
|
|
213
|
-
bool isExpanded = ContextFoldoutStates.GetValueOrDefault(foldoutKey, false);
|
|
214
|
-
if (isExpanded)
|
|
215
|
-
{
|
|
216
|
-
height +=
|
|
217
|
-
Mathf.Max(1, allPaths.Skip(topN).Count())
|
|
218
|
-
* (
|
|
219
|
-
EditorGUIUtility.singleLineHeight
|
|
220
|
-
+ EditorGUIUtility.standardVerticalSpacing
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return height;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
public static float GetDrawFrequentPathsHeight(
|
|
229
|
-
string toolName,
|
|
230
|
-
string contextKey,
|
|
231
|
-
bool allowExpansion = true,
|
|
232
|
-
int topN = 5
|
|
233
|
-
)
|
|
234
|
-
{
|
|
235
|
-
if (PersistentDirectorySettings.Instance == null)
|
|
236
|
-
{
|
|
237
|
-
return 0f;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
float height = 0f;
|
|
241
|
-
DirectoryUsageData[] topPaths = PersistentDirectorySettings.Instance.GetPaths(
|
|
242
|
-
toolName,
|
|
243
|
-
contextKey,
|
|
244
|
-
true,
|
|
245
|
-
topN
|
|
246
|
-
);
|
|
247
|
-
|
|
248
|
-
if (topPaths.Length <= 0)
|
|
249
|
-
{
|
|
250
|
-
return height;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
height +=
|
|
254
|
-
(1 + topPaths.Length)
|
|
255
|
-
* (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
|
|
256
|
-
|
|
257
|
-
if (allowExpansion)
|
|
258
|
-
{
|
|
259
|
-
DirectoryUsageData[] allPaths = PersistentDirectorySettings.Instance.GetPaths(
|
|
260
|
-
toolName,
|
|
261
|
-
contextKey,
|
|
262
|
-
false,
|
|
263
|
-
0
|
|
264
|
-
);
|
|
265
|
-
if (allPaths.Length > topN)
|
|
266
|
-
{
|
|
267
|
-
height +=
|
|
268
|
-
EditorGUIUtility.singleLineHeight
|
|
269
|
-
+ EditorGUIUtility.standardVerticalSpacing;
|
|
270
|
-
string foldoutKey = $"{toolName}/{contextKey}_AllPathsHistory";
|
|
271
|
-
bool isExpanded = ContextFoldoutStates.GetValueOrDefault(foldoutKey, false);
|
|
272
|
-
if (isExpanded)
|
|
273
|
-
{
|
|
274
|
-
height +=
|
|
275
|
-
Mathf.Max(1, allPaths.Skip(topN).Count())
|
|
276
|
-
* (
|
|
277
|
-
EditorGUIUtility.singleLineHeight
|
|
278
|
-
+ EditorGUIUtility.standardVerticalSpacing
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (height > 0)
|
|
285
|
-
{
|
|
286
|
-
height += EditorGUIUtility.standardVerticalSpacing * 2;
|
|
287
|
-
}
|
|
288
|
-
return height;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
public static float GetPathSelectorHeight(
|
|
292
|
-
string toolName,
|
|
293
|
-
string contextKeyForHistory,
|
|
294
|
-
bool displayFrequentPaths = true
|
|
295
|
-
)
|
|
296
|
-
{
|
|
297
|
-
float height = 0f;
|
|
298
|
-
|
|
299
|
-
height += EditorGUIUtility.singleLineHeight;
|
|
300
|
-
|
|
301
|
-
if (!displayFrequentPaths)
|
|
302
|
-
{
|
|
303
|
-
return height;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
float historyHeight = GetDrawFrequentPathsHeight(toolName, contextKeyForHistory);
|
|
307
|
-
if (historyHeight > 0)
|
|
308
|
-
{
|
|
309
|
-
height += EditorGUIUtility.standardVerticalSpacing;
|
|
310
|
-
height += historyHeight;
|
|
311
|
-
}
|
|
312
|
-
return height;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
public static float GetPathSelectorStringHeight(
|
|
316
|
-
SerializedProperty propertyForContext,
|
|
317
|
-
string toolName
|
|
318
|
-
)
|
|
319
|
-
{
|
|
320
|
-
if (propertyForContext is not { propertyType: SerializedPropertyType.String })
|
|
321
|
-
{
|
|
322
|
-
return EditorGUIUtility.singleLineHeight;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
float height = 0f;
|
|
326
|
-
height += EditorGUIUtility.singleLineHeight;
|
|
327
|
-
height += EditorGUIUtility.standardVerticalSpacing;
|
|
328
|
-
string internalContextKey =
|
|
329
|
-
$"{propertyForContext.serializedObject.targetObject.GetType().Name}_{propertyForContext.propertyPath}";
|
|
330
|
-
height += GetPathSelectorHeight(toolName, internalContextKey);
|
|
331
|
-
return height;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
public static void PathSelectorString(
|
|
335
|
-
SerializedProperty property,
|
|
336
|
-
string toolName,
|
|
337
|
-
string label,
|
|
338
|
-
GUIContent content
|
|
339
|
-
)
|
|
340
|
-
{
|
|
341
|
-
if (property == null)
|
|
342
|
-
{
|
|
343
|
-
EditorGUILayout.LabelField(
|
|
344
|
-
$"Error: Property is null in {nameof(PathSelectorString)}.",
|
|
345
|
-
EditorStyles.miniBoldLabel
|
|
346
|
-
);
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
if (property.propertyType != SerializedPropertyType.String)
|
|
350
|
-
{
|
|
351
|
-
EditorGUILayout.LabelField(
|
|
352
|
-
$"Error: Property '{property.displayName}' is not a string.",
|
|
353
|
-
EditorStyles.miniBoldLabel
|
|
354
|
-
);
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
EditorGUILayout.LabelField(label, EditorStyles.boldLabel);
|
|
359
|
-
PathSelector(
|
|
360
|
-
content,
|
|
361
|
-
property.stringValue,
|
|
362
|
-
toolName,
|
|
363
|
-
property.name,
|
|
364
|
-
chosenPath =>
|
|
365
|
-
{
|
|
366
|
-
property.stringValue = chosenPath;
|
|
367
|
-
property.serializedObject.ApplyModifiedProperties();
|
|
368
|
-
},
|
|
369
|
-
"Select Directory"
|
|
370
|
-
);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
public static void PathSelectorObject(
|
|
374
|
-
SerializedProperty property,
|
|
375
|
-
string toolName,
|
|
376
|
-
string label,
|
|
377
|
-
GUIContent content
|
|
378
|
-
)
|
|
379
|
-
{
|
|
380
|
-
if (property == null)
|
|
381
|
-
{
|
|
382
|
-
EditorGUILayout.LabelField(
|
|
383
|
-
$"Error: Property is null in {nameof(PathSelectorObject)}.",
|
|
384
|
-
EditorStyles.miniBoldLabel
|
|
385
|
-
);
|
|
386
|
-
return;
|
|
387
|
-
}
|
|
388
|
-
if (property.propertyType != SerializedPropertyType.ObjectReference)
|
|
389
|
-
{
|
|
390
|
-
EditorGUILayout.LabelField(
|
|
391
|
-
$"Error: Property '{property.displayName}' is not an Object Reference.",
|
|
392
|
-
EditorStyles.miniBoldLabel
|
|
393
|
-
);
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
EditorGUILayout.LabelField(label, EditorStyles.boldLabel);
|
|
397
|
-
PathSelector(
|
|
398
|
-
content,
|
|
399
|
-
property.objectReferenceValue == null
|
|
400
|
-
? string.Empty
|
|
401
|
-
: AssetDatabase.GetAssetPath(property.objectReferenceValue),
|
|
402
|
-
toolName,
|
|
403
|
-
property.name,
|
|
404
|
-
chosenPath =>
|
|
405
|
-
{
|
|
406
|
-
if (!string.IsNullOrWhiteSpace(chosenPath))
|
|
407
|
-
{
|
|
408
|
-
Object defaultFolder = AssetDatabase.LoadAssetAtPath<Object>(chosenPath);
|
|
409
|
-
property.objectReferenceValue = defaultFolder;
|
|
410
|
-
}
|
|
411
|
-
else
|
|
412
|
-
{
|
|
413
|
-
property.objectReferenceValue = null;
|
|
414
|
-
}
|
|
415
|
-
property.serializedObject.ApplyModifiedProperties();
|
|
416
|
-
},
|
|
417
|
-
"Select Directory"
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
public static void PathSelectorStringArray(SerializedProperty listProp, string toolName)
|
|
422
|
-
{
|
|
423
|
-
if (listProp == null)
|
|
424
|
-
{
|
|
425
|
-
EditorGUILayout.LabelField(
|
|
426
|
-
$"Error: Property is null in {nameof(PathSelectorStringArray)}.",
|
|
427
|
-
EditorStyles.miniBoldLabel
|
|
428
|
-
);
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
using (new EditorGUILayout.HorizontalScope())
|
|
433
|
-
{
|
|
434
|
-
EditorGUILayout.LabelField("Number of Directories:", GUILayout.Width(150));
|
|
435
|
-
int currentSize = listProp.arraySize;
|
|
436
|
-
int newSize = EditorGUILayout.IntField(currentSize, GUILayout.Width(50));
|
|
437
|
-
if (newSize != currentSize)
|
|
438
|
-
{
|
|
439
|
-
newSize = Mathf.Max(0, newSize);
|
|
440
|
-
listProp.arraySize = newSize;
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
using (new EditorGUI.IndentLevelScope())
|
|
445
|
-
{
|
|
446
|
-
for (int i = 0; i < listProp.arraySize; i++)
|
|
447
|
-
{
|
|
448
|
-
SerializedProperty elementProp = listProp.GetArrayElementAtIndex(i);
|
|
449
|
-
using (new EditorGUILayout.HorizontalScope())
|
|
450
|
-
{
|
|
451
|
-
int currentIndex = i;
|
|
452
|
-
PathSelector(
|
|
453
|
-
new GUIContent($"Path {i + 1}"),
|
|
454
|
-
elementProp.stringValue,
|
|
455
|
-
toolName,
|
|
456
|
-
listProp.name,
|
|
457
|
-
chosenPath =>
|
|
458
|
-
{
|
|
459
|
-
SerializedProperty currentElementProp =
|
|
460
|
-
listProp.GetArrayElementAtIndex(currentIndex);
|
|
461
|
-
currentElementProp.stringValue = chosenPath;
|
|
462
|
-
currentElementProp.serializedObject.ApplyModifiedProperties();
|
|
463
|
-
},
|
|
464
|
-
$"Select Directory {i + 1}"
|
|
465
|
-
);
|
|
466
|
-
|
|
467
|
-
if (GUILayout.Button("-", GUILayout.Width(25)))
|
|
468
|
-
{
|
|
469
|
-
elementProp.stringValue = string.Empty;
|
|
470
|
-
listProp.DeleteArrayElementAtIndex(i);
|
|
471
|
-
break;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
EditorGUILayout.Space(3);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
if (GUILayout.Button("Add New Directory Path", GUILayout.Width(200)))
|
|
479
|
-
{
|
|
480
|
-
listProp.InsertArrayElementAtIndex(listProp.arraySize);
|
|
481
|
-
listProp.GetArrayElementAtIndex(listProp.arraySize - 1).stringValue = string.Empty;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
public static void PathSelectorObjectArray(SerializedProperty listProp, string toolName)
|
|
486
|
-
{
|
|
487
|
-
if (listProp == null)
|
|
488
|
-
{
|
|
489
|
-
EditorGUILayout.LabelField(
|
|
490
|
-
$"Error: Property is null in {nameof(PathSelectorObjectArray)}.",
|
|
491
|
-
EditorStyles.miniBoldLabel
|
|
492
|
-
);
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
using (new EditorGUILayout.HorizontalScope())
|
|
497
|
-
{
|
|
498
|
-
EditorGUILayout.LabelField("Number of Directories:", GUILayout.Width(150));
|
|
499
|
-
int currentSize = listProp.arraySize;
|
|
500
|
-
int newSize = EditorGUILayout.IntField(currentSize, GUILayout.Width(50));
|
|
501
|
-
if (newSize != currentSize)
|
|
502
|
-
{
|
|
503
|
-
newSize = Mathf.Max(0, newSize);
|
|
504
|
-
listProp.arraySize = newSize;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
using (new EditorGUI.IndentLevelScope())
|
|
509
|
-
{
|
|
510
|
-
for (int i = 0; i < listProp.arraySize; i++)
|
|
511
|
-
{
|
|
512
|
-
SerializedProperty elementProp = listProp.GetArrayElementAtIndex(i);
|
|
513
|
-
using (new EditorGUILayout.HorizontalScope())
|
|
514
|
-
{
|
|
515
|
-
int currentIndex = i;
|
|
516
|
-
PathSelector(
|
|
517
|
-
new GUIContent($"Path {i + 1}"),
|
|
518
|
-
elementProp.objectReferenceValue == null
|
|
519
|
-
? string.Empty
|
|
520
|
-
: AssetDatabase.GetAssetPath(elementProp.objectReferenceValue),
|
|
521
|
-
toolName,
|
|
522
|
-
listProp.name,
|
|
523
|
-
chosenPath =>
|
|
524
|
-
{
|
|
525
|
-
SerializedProperty currentElementProp =
|
|
526
|
-
listProp.GetArrayElementAtIndex(currentIndex);
|
|
527
|
-
if (!string.IsNullOrWhiteSpace(chosenPath))
|
|
528
|
-
{
|
|
529
|
-
Object defaultFolder = AssetDatabase.LoadAssetAtPath<Object>(
|
|
530
|
-
chosenPath
|
|
531
|
-
);
|
|
532
|
-
currentElementProp.objectReferenceValue = defaultFolder;
|
|
533
|
-
}
|
|
534
|
-
else
|
|
535
|
-
{
|
|
536
|
-
currentElementProp.objectReferenceValue = null;
|
|
537
|
-
}
|
|
538
|
-
currentElementProp.serializedObject.ApplyModifiedProperties();
|
|
539
|
-
},
|
|
540
|
-
$"Select Directory {i + 1}"
|
|
541
|
-
);
|
|
542
|
-
|
|
543
|
-
if (GUILayout.Button("-", GUILayout.Width(25)))
|
|
544
|
-
{
|
|
545
|
-
elementProp.stringValue = "";
|
|
546
|
-
listProp.DeleteArrayElementAtIndex(i);
|
|
547
|
-
|
|
548
|
-
break;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
EditorGUILayout.Space(3);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
if (GUILayout.Button("Add New Directory Path", GUILayout.Width(200)))
|
|
557
|
-
{
|
|
558
|
-
listProp.InsertArrayElementAtIndex(listProp.arraySize);
|
|
559
|
-
listProp.GetArrayElementAtIndex(listProp.arraySize - 1).objectReferenceValue = null;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
public static string PathSelector(
|
|
564
|
-
GUIContent label,
|
|
565
|
-
string currentPath,
|
|
566
|
-
string toolName,
|
|
567
|
-
string contextKey,
|
|
568
|
-
Action<string> onPathChosen,
|
|
569
|
-
string dialogTitle = "Select Folder",
|
|
570
|
-
float textFieldWidthOverride = -1f
|
|
571
|
-
)
|
|
572
|
-
{
|
|
573
|
-
if (onPathChosen == null)
|
|
574
|
-
{
|
|
575
|
-
Debug.LogError(
|
|
576
|
-
"PersistentDirectoryGUI.PathSelector: onPathChosen callback cannot be null."
|
|
577
|
-
);
|
|
578
|
-
return currentPath;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
string pathInTextField = currentPath;
|
|
582
|
-
|
|
583
|
-
using (new EditorGUILayout.HorizontalScope())
|
|
584
|
-
{
|
|
585
|
-
if (textFieldWidthOverride > 0)
|
|
586
|
-
{
|
|
587
|
-
pathInTextField = EditorGUILayout.TextField(
|
|
588
|
-
label,
|
|
589
|
-
pathInTextField,
|
|
590
|
-
GUILayout.Width(textFieldWidthOverride)
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
else
|
|
594
|
-
{
|
|
595
|
-
pathInTextField = EditorGUILayout.TextField(label, pathInTextField);
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
if (GUILayout.Button("Browse...", GUILayout.ExpandWidth(false)))
|
|
599
|
-
{
|
|
600
|
-
string initialBrowsePath = Application.dataPath;
|
|
601
|
-
if (!string.IsNullOrWhiteSpace(pathInTextField))
|
|
602
|
-
{
|
|
603
|
-
try
|
|
604
|
-
{
|
|
605
|
-
string fullPotentialPath = Path.GetFullPath(
|
|
606
|
-
pathInTextField.StartsWith("Assets")
|
|
607
|
-
? pathInTextField
|
|
608
|
-
: Path.Combine(Application.dataPath, "..", pathInTextField)
|
|
609
|
-
);
|
|
610
|
-
if (Directory.Exists(fullPotentialPath))
|
|
611
|
-
{
|
|
612
|
-
initialBrowsePath = fullPotentialPath;
|
|
613
|
-
}
|
|
614
|
-
else
|
|
615
|
-
{
|
|
616
|
-
string dirName = Path.GetDirectoryName(fullPotentialPath);
|
|
617
|
-
if (Directory.Exists(dirName))
|
|
618
|
-
{
|
|
619
|
-
initialBrowsePath = dirName;
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
catch { }
|
|
624
|
-
}
|
|
625
|
-
if (!Directory.Exists(initialBrowsePath))
|
|
626
|
-
{
|
|
627
|
-
initialBrowsePath = Application.dataPath;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
string selectedPathSys = EditorUtility.OpenFolderPanel(
|
|
631
|
-
dialogTitle,
|
|
632
|
-
initialBrowsePath,
|
|
633
|
-
""
|
|
634
|
-
);
|
|
635
|
-
|
|
636
|
-
if (!string.IsNullOrWhiteSpace(selectedPathSys))
|
|
637
|
-
{
|
|
638
|
-
string processedPath = selectedPathSys.SanitizePath();
|
|
639
|
-
if (processedPath.StartsWith(Application.dataPath.SanitizePath()))
|
|
640
|
-
{
|
|
641
|
-
processedPath =
|
|
642
|
-
"Assets"
|
|
643
|
-
+ processedPath.Substring(
|
|
644
|
-
Application.dataPath.SanitizePath().Length
|
|
645
|
-
);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
pathInTextField = processedPath;
|
|
649
|
-
PersistentDirectorySettings.Instance.RecordPath(
|
|
650
|
-
toolName,
|
|
651
|
-
contextKey,
|
|
652
|
-
processedPath
|
|
653
|
-
);
|
|
654
|
-
onPathChosen.Invoke(processedPath);
|
|
655
|
-
GUI.FocusControl(null);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
DrawFrequentPaths(
|
|
661
|
-
toolName,
|
|
662
|
-
contextKey,
|
|
663
|
-
chosenHistoryPath =>
|
|
664
|
-
{
|
|
665
|
-
pathInTextField = chosenHistoryPath;
|
|
666
|
-
PersistentDirectorySettings.Instance.RecordPath(
|
|
667
|
-
toolName,
|
|
668
|
-
contextKey,
|
|
669
|
-
chosenHistoryPath
|
|
670
|
-
);
|
|
671
|
-
onPathChosen.Invoke(chosenHistoryPath);
|
|
672
|
-
GUI.FocusControl(null);
|
|
673
|
-
},
|
|
674
|
-
true,
|
|
675
|
-
5,
|
|
676
|
-
"History:"
|
|
677
|
-
);
|
|
678
|
-
|
|
679
|
-
return pathInTextField;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
public static void DrawFrequentPaths(
|
|
683
|
-
string toolName,
|
|
684
|
-
string contextKey,
|
|
685
|
-
Action<string> onPathClickedFromHistory,
|
|
686
|
-
bool allowExpansion = true,
|
|
687
|
-
int topN = 5,
|
|
688
|
-
string listLabel = "Frequent Paths:"
|
|
689
|
-
)
|
|
690
|
-
{
|
|
691
|
-
if (PersistentDirectorySettings.Instance == null)
|
|
692
|
-
{
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
if (onPathClickedFromHistory == null)
|
|
697
|
-
{
|
|
698
|
-
Debug.LogError(
|
|
699
|
-
"PersistentDirectoryGUI.DrawFrequentPaths: onPathClickedFromHistory callback cannot be null."
|
|
700
|
-
);
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
DirectoryUsageData[] topPaths = PersistentDirectorySettings.Instance.GetPaths(
|
|
705
|
-
toolName,
|
|
706
|
-
contextKey,
|
|
707
|
-
true,
|
|
708
|
-
topN
|
|
709
|
-
);
|
|
710
|
-
|
|
711
|
-
if (topPaths.Length <= 0)
|
|
712
|
-
{
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
using (new EditorGUILayout.HorizontalScope())
|
|
717
|
-
{
|
|
718
|
-
GUILayout.Space(EditorGUI.indentLevel * 15f + 15f);
|
|
719
|
-
using (new EditorGUILayout.VerticalScope())
|
|
720
|
-
{
|
|
721
|
-
EditorGUILayout.LabelField(listLabel, EditorStyles.miniBoldLabel);
|
|
722
|
-
foreach (DirectoryUsageData dirData in topPaths)
|
|
723
|
-
{
|
|
724
|
-
if (
|
|
725
|
-
GUILayout.Button(
|
|
726
|
-
new GUIContent($"({dirData.count}) {dirData.path}", dirData.path),
|
|
727
|
-
EditorStyles.miniButtonLeft
|
|
728
|
-
)
|
|
729
|
-
)
|
|
730
|
-
{
|
|
731
|
-
onPathClickedFromHistory.Invoke(dirData.path);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
if (!allowExpansion)
|
|
736
|
-
{
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
string foldoutKey = $"{toolName}/{contextKey}_AllPathsHistory";
|
|
741
|
-
ContextFoldoutStates.TryAdd(foldoutKey, false);
|
|
742
|
-
|
|
743
|
-
DirectoryUsageData[] allPaths = PersistentDirectorySettings.Instance.GetPaths(
|
|
744
|
-
toolName,
|
|
745
|
-
contextKey,
|
|
746
|
-
false,
|
|
747
|
-
0
|
|
748
|
-
);
|
|
749
|
-
if (allPaths.Length <= topN)
|
|
750
|
-
{
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
ContextFoldoutStates[foldoutKey] = EditorGUILayout.Foldout(
|
|
755
|
-
ContextFoldoutStates[foldoutKey],
|
|
756
|
-
"Show All History (" + allPaths.Length + ")",
|
|
757
|
-
true,
|
|
758
|
-
EditorStyles.foldout
|
|
759
|
-
);
|
|
760
|
-
if (!ContextFoldoutStates[foldoutKey])
|
|
761
|
-
{
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
DirectoryUsageData[] pathsNotAlreadyInTop = allPaths.Skip(topN).ToArray();
|
|
766
|
-
if (0 < pathsNotAlreadyInTop.Length)
|
|
767
|
-
{
|
|
768
|
-
foreach (DirectoryUsageData dirData in pathsNotAlreadyInTop)
|
|
769
|
-
{
|
|
770
|
-
if (
|
|
771
|
-
GUILayout.Button(
|
|
772
|
-
new GUIContent(
|
|
773
|
-
$"({dirData.count}) {dirData.path}",
|
|
774
|
-
dirData.path
|
|
775
|
-
),
|
|
776
|
-
EditorStyles.miniButtonLeft
|
|
777
|
-
)
|
|
778
|
-
)
|
|
779
|
-
{
|
|
780
|
-
onPathClickedFromHistory.Invoke(dirData.path);
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
else
|
|
785
|
-
{
|
|
786
|
-
EditorGUILayout.LabelField(
|
|
787
|
-
"All paths already displayed above.",
|
|
788
|
-
EditorStyles.centeredGreyMiniLabel
|
|
789
|
-
);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
#endif
|
|
796
|
-
}
|