com.wallstop-studios.unity-helpers 2.0.0-rc73.13 → 2.0.0-rc73.15

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.
Files changed (36) hide show
  1. package/Editor/AnimationEventEditor.cs +4 -5
  2. package/Editor/CustomEditors/MatchColliderToSpriteEditor.cs +1 -1
  3. package/Editor/CustomEditors/PersistentDirectoryGUI.cs +590 -0
  4. package/Editor/CustomEditors/PersistentDirectoryGUI.cs.meta +3 -0
  5. package/Editor/CustomEditors/SourceFolderEntryDrawer.cs +298 -0
  6. package/Editor/CustomEditors/SourceFolderEntryDrawer.cs.meta +3 -0
  7. package/Editor/FitTextureSizeWindow.cs +5 -44
  8. package/Editor/PersistentDirectorySettings.cs +248 -0
  9. package/Editor/PersistentDirectorySettings.cs.meta +3 -0
  10. package/Editor/PrefabChecker.cs +1 -2
  11. package/Editor/{AnimationCopier.cs → Sprites/AnimationCopier.cs} +33 -166
  12. package/Editor/{AnimationCreator.cs → Sprites/AnimationCreator.cs} +9 -80
  13. package/Editor/Sprites/ScriptableSpriteAtlas.cs +95 -0
  14. package/Editor/Sprites/ScriptableSpriteAtlas.cs.meta +3 -0
  15. package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs +938 -0
  16. package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs.meta +3 -0
  17. package/Editor/{SpriteCropper.cs → Sprites/SpriteCropper.cs} +68 -66
  18. package/Editor/{SpriteSettingsApplier.cs → Sprites/SpriteSettingsApplier.cs} +9 -76
  19. package/Editor/{TextureResizerWizard.cs → Sprites/TextureResizerWizard.cs} +1 -1
  20. package/Editor/{TextureSettingsApplier.cs → Sprites/TextureSettingsApplier.cs} +1 -1
  21. package/Editor/Sprites.meta +3 -0
  22. package/Editor/Utils/DxReadOnlyPropertyDrawer.cs +1 -1
  23. package/Runtime/Core/Helper/DirectoryHelper.cs +64 -0
  24. package/package.json +3 -1
  25. package/Editor/SpriteAtlasGenerator.cs +0 -895
  26. package/Editor/SpriteAtlasGenerator.cs.meta +0 -3
  27. package/Editor/Utils/GUIHorizontalScope.cs +0 -20
  28. package/Editor/Utils/GUIHorizontalScope.cs.meta +0 -3
  29. package/Editor/Utils/GUIIndentScope.cs +0 -20
  30. package/Editor/Utils/GUIIndentScope.cs.meta +0 -3
  31. /package/Editor/{AnimationCopier.cs.meta → Sprites/AnimationCopier.cs.meta} +0 -0
  32. /package/Editor/{AnimationCreator.cs.meta → Sprites/AnimationCreator.cs.meta} +0 -0
  33. /package/Editor/{SpriteCropper.cs.meta → Sprites/SpriteCropper.cs.meta} +0 -0
  34. /package/Editor/{SpriteSettingsApplier.cs.meta → Sprites/SpriteSettingsApplier.cs.meta} +0 -0
  35. /package/Editor/{TextureResizerWizard.cs.meta → Sprites/TextureResizerWizard.cs.meta} +0 -0
  36. /package/Editor/{TextureSettingsApplier.cs.meta → Sprites/TextureSettingsApplier.cs.meta} +0 -0
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 2a8f0685b47e4e3697ff19800eddc3dd
3
+ timeCreated: 1746911361
@@ -1,4 +1,4 @@
1
- namespace WallstopStudios.UnityHelpers.Editor
1
+ namespace WallstopStudios.UnityHelpers.Editor.Sprites
2
2
  {
3
3
  #if UNITY_EDITOR
4
4
  using System;
@@ -6,9 +6,10 @@
6
6
  using System.IO;
7
7
  using System.Linq;
8
8
  using System.Threading.Tasks;
9
- using Core.Extension;
10
9
  using UnityEditor;
11
10
  using UnityEngine;
11
+ using Core.Extension;
12
+ using CustomEditors;
12
13
  using Object = UnityEngine.Object;
13
14
 
14
15
  public sealed class SpriteCropper : EditorWindow
@@ -35,64 +36,55 @@
35
36
  [SerializeField]
36
37
  private bool _onlyNecessary;
37
38
 
39
+ [SerializeField]
40
+ private int _leftPadding;
41
+
42
+ [SerializeField]
43
+ private int _rightPadding;
44
+
45
+ [SerializeField]
46
+ private int _topPadding;
47
+
48
+ [SerializeField]
49
+ private int _bottomPadding;
50
+
38
51
  private List<string> _filesToProcess;
52
+ private SerializedObject _serializedObject;
53
+ private SerializedProperty _inputDirectoriesProperty;
54
+ private SerializedProperty _onlyNecessaryProperty;
55
+ private SerializedProperty _leftPaddingProperty;
56
+ private SerializedProperty _rightPaddingProperty;
57
+ private SerializedProperty _topPaddingProperty;
58
+ private SerializedProperty _bottomPaddingProperty;
39
59
 
40
60
  [MenuItem("Tools/Wallstop Studios/Unity Helpers/" + Name)]
41
61
  private static void ShowWindow() => GetWindow<SpriteCropper>(Name);
42
62
 
63
+ private void OnEnable()
64
+ {
65
+ _serializedObject = new SerializedObject(this);
66
+ _inputDirectoriesProperty = _serializedObject.FindProperty(nameof(_inputDirectories));
67
+ _onlyNecessaryProperty = _serializedObject.FindProperty(nameof(_onlyNecessary));
68
+ _leftPaddingProperty = _serializedObject.FindProperty(nameof(_leftPadding));
69
+ _rightPaddingProperty = _serializedObject.FindProperty(nameof(_rightPadding));
70
+ _topPaddingProperty = _serializedObject.FindProperty(nameof(_topPadding));
71
+ _bottomPaddingProperty = _serializedObject.FindProperty(nameof(_bottomPadding));
72
+ }
73
+
43
74
  private void OnGUI()
44
75
  {
45
- GUILayout.Label("Drag folders below", EditorStyles.boldLabel);
46
- SerializedObject so = new(this);
47
- so.Update();
48
- SerializedProperty dirs = so.FindProperty(nameof(_inputDirectories));
49
- EditorGUILayout.PropertyField(dirs, true);
50
- SerializedProperty onlyNecessary = so.FindProperty(nameof(_onlyNecessary));
51
- EditorGUILayout.PropertyField(onlyNecessary, true);
52
- so.ApplyModifiedProperties();
53
-
54
- if (GUILayout.Button("Select Input Folder"))
55
- {
56
- string path = EditorUtility.OpenFolderPanel(
57
- "Select Sprite Input Folder",
58
- Application.dataPath,
59
- ""
60
- );
61
- if (!string.IsNullOrWhiteSpace(path))
62
- {
63
- if (path.StartsWith(Application.dataPath, StringComparison.Ordinal))
64
- {
65
- path = "Assets" + path.Substring(Application.dataPath.Length);
66
- if (
67
- !_inputDirectories
68
- .Select(AssetDatabase.GetAssetPath)
69
- .Any(directory =>
70
- string.Equals(
71
- directory,
72
- path,
73
- StringComparison.OrdinalIgnoreCase
74
- )
75
- )
76
- )
77
- {
78
- Object folder = AssetDatabase.LoadAssetAtPath<Object>(path);
79
- if (folder == null)
80
- {
81
- return;
82
- }
83
- _inputDirectories.Add(folder);
84
- }
85
- }
86
- else
87
- {
88
- EditorUtility.DisplayDialog(
89
- "Invalid Folder",
90
- "Please select a folder inside the project's Assets directory.",
91
- "OK"
92
- );
93
- }
94
- }
95
- }
76
+ EditorGUILayout.LabelField("Input directories", EditorStyles.boldLabel);
77
+ _serializedObject.Update();
78
+ PersistentDirectoryGUI.PathSelectorObjectArray(
79
+ _inputDirectoriesProperty,
80
+ nameof(SpriteCropper)
81
+ );
82
+ EditorGUILayout.PropertyField(_onlyNecessaryProperty, true);
83
+ EditorGUILayout.PropertyField(_leftPaddingProperty, true);
84
+ EditorGUILayout.PropertyField(_rightPaddingProperty, true);
85
+ EditorGUILayout.PropertyField(_topPaddingProperty, true);
86
+ EditorGUILayout.PropertyField(_bottomPaddingProperty, true);
87
+ _serializedObject.ApplyModifiedProperties();
96
88
 
97
89
  if (GUILayout.Button("Find Sprites To Process"))
98
90
  {
@@ -229,9 +221,6 @@
229
221
  $"An error occurred during processing. Last processed: {lastProcessed}.",
230
222
  e
231
223
  );
232
- AssetDatabase.StopAssetEditing();
233
- AssetDatabase.SaveAssets();
234
- AssetDatabase.Refresh();
235
224
  }
236
225
  finally
237
226
  {
@@ -302,9 +291,7 @@
302
291
  int maxX = 0;
303
292
  int maxY = 0;
304
293
  bool hasVisible = false;
305
-
306
294
  object lockObject = new();
307
-
308
295
  Parallel.For(
309
296
  0,
310
297
  width * height,
@@ -341,18 +328,28 @@
341
328
  }
342
329
  );
343
330
 
344
- int cropWidth = maxX - minX + 1;
345
- int cropHeight = maxY - minY + 1;
346
-
347
- if (_onlyNecessary && (!hasVisible || (cropWidth == width && cropHeight == height)))
348
- {
349
- return null;
350
- }
351
-
331
+ int cropWidth;
332
+ int cropHeight;
352
333
  if (!hasVisible)
353
334
  {
354
335
  cropWidth = 1;
355
336
  cropHeight = 1;
337
+ minX = 0;
338
+ minY = 0;
339
+ }
340
+ else
341
+ {
342
+ minX = Mathf.Max(0, minX - _leftPadding);
343
+ minY = Mathf.Max(0, minY - _bottomPadding);
344
+ maxX = Mathf.Min(width, maxX + _rightPadding);
345
+ maxY = Mathf.Min(height, maxY + _topPadding);
346
+ cropWidth = maxX - minX + 1;
347
+ cropHeight = maxY - minY + 1;
348
+ }
349
+
350
+ if (_onlyNecessary && (!hasVisible || (cropWidth == width && cropHeight == height)))
351
+ {
352
+ return null;
356
353
  }
357
354
 
358
355
  Texture2D cropped = new(cropWidth, cropHeight, TextureFormat.RGBA32, false);
@@ -407,6 +404,11 @@
407
404
  cropHeight > 0 ? newPivotPixels.y / cropHeight : 0.5f
408
405
  );
409
406
 
407
+ if (!hasVisible)
408
+ {
409
+ newPivotNorm = new Vector2(0.5f, 0.5f);
410
+ }
411
+
410
412
  newImporter.spriteImportMode = SpriteImportMode.Single;
411
413
  newImporter.spritePivot = newPivotNorm;
412
414
  newSettings.spritePivot = newPivotNorm;
@@ -1,16 +1,16 @@
1
1
  // ReSharper disable CompareOfFloatsByEqualityOperator
2
- namespace WallstopStudios.UnityHelpers.Editor
2
+ namespace WallstopStudios.UnityHelpers.Editor.Sprites
3
3
  {
4
4
  #if UNITY_EDITOR
5
- using Core.Attributes;
6
- using Core.Extension;
7
5
  using System;
8
6
  using System.Collections.Generic;
9
7
  using System.IO;
10
8
  using System.Linq;
11
9
  using UnityEditor;
12
10
  using UnityEngine;
13
- using Utils;
11
+ using Core.Attributes;
12
+ using Core.Extension;
13
+ using CustomEditors;
14
14
  using Object = UnityEngine.Object;
15
15
 
16
16
  [Serializable]
@@ -77,7 +77,7 @@ namespace WallstopStudios.UnityHelpers.Editor
77
77
  }
78
78
 
79
79
  [CustomPropertyDrawer(typeof(SpriteSettings))]
80
- public class SpriteSettingsDrawer : PropertyDrawer
80
+ public sealed class SpriteSettingsDrawer : PropertyDrawer
81
81
  {
82
82
  private const float CheckboxWidth = 18f;
83
83
  private const float HorizontalSpacing = 5f;
@@ -204,7 +204,7 @@ namespace WallstopStudios.UnityHelpers.Editor
204
204
  valuePropHeight
205
205
  );
206
206
 
207
- using (new GUIIndentScope())
207
+ using (new EditorGUI.IndentLevelScope())
208
208
  {
209
209
  EditorGUI.PropertyField(valueRect, valueProp, GUIContent.none, true);
210
210
  }
@@ -301,25 +301,16 @@ namespace WallstopStudios.UnityHelpers.Editor
301
301
  private void OnGUI()
302
302
  {
303
303
  _serializedObject.Update();
304
-
305
304
  _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
306
305
 
307
306
  EditorGUILayout.LabelField("Sprite Sources", EditorStyles.boldLabel);
308
307
  EditorGUILayout.PropertyField(_spritesProp, new GUIContent("Specific Sprites"), true);
309
-
310
308
  EditorGUILayout.Space();
311
-
312
309
  EditorGUILayout.LabelField("Directory Sources", EditorStyles.boldLabel);
313
- EditorGUILayout.PropertyField(
310
+ PersistentDirectoryGUI.PathSelectorObjectArray(
314
311
  _directoriesProp,
315
- new GUIContent("Scan Directories"),
316
- true
312
+ nameof(SpriteSettingsApplierWindow)
317
313
  );
318
- if (GUILayout.Button("Add Directory via Browser"))
319
- {
320
- AddDirectory();
321
- }
322
-
323
314
  EditorGUILayout.Space();
324
315
  EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);
325
316
  EditorGUILayout.PropertyField(
@@ -332,7 +323,6 @@ namespace WallstopStudios.UnityHelpers.Editor
332
323
  new GUIContent("Sprite Settings Profiles"),
333
324
  true
334
325
  );
335
-
336
326
  EditorGUILayout.Space();
337
327
  EditorGUILayout.LabelField("Actions", EditorStyles.boldLabel);
338
328
 
@@ -363,67 +353,10 @@ namespace WallstopStudios.UnityHelpers.Editor
363
353
  _serializedObject.ApplyModifiedProperties();
364
354
  }
365
355
 
366
- private void AddDirectory()
367
- {
368
- string path = EditorUtility.OpenFolderPanel("Select Directory", "Assets", "");
369
- if (string.IsNullOrWhiteSpace(path))
370
- {
371
- return;
372
- }
373
-
374
- if (path.StartsWith(Application.dataPath, StringComparison.Ordinal))
375
- {
376
- string relativePath = "Assets" + path.Substring(Application.dataPath.Length);
377
- Object folderAsset = AssetDatabase.LoadAssetAtPath<Object>(relativePath);
378
- if (folderAsset != null)
379
- {
380
- _directoriesProp.serializedObject.Update();
381
- bool alreadyExists = false;
382
- for (int i = 0; i < _directoriesProp.arraySize; i++)
383
- {
384
- if (
385
- _directoriesProp.GetArrayElementAtIndex(i).objectReferenceValue
386
- == folderAsset
387
- )
388
- {
389
- alreadyExists = true;
390
- break;
391
- }
392
- }
393
-
394
- if (!alreadyExists)
395
- {
396
- int newIndex = _directoriesProp.arraySize;
397
- _directoriesProp.InsertArrayElementAtIndex(newIndex);
398
- _directoriesProp.GetArrayElementAtIndex(newIndex).objectReferenceValue =
399
- folderAsset;
400
- this.Log($"Added directory: {relativePath}");
401
- }
402
- else
403
- {
404
- this.LogWarn($"Directory already in list: {relativePath}");
405
- }
406
- _directoriesProp.serializedObject.ApplyModifiedProperties();
407
- }
408
- else
409
- {
410
- this.LogError(
411
- $"Could not load asset at path: {relativePath}. Is it a valid folder within Assets?"
412
- );
413
- }
414
- }
415
- else
416
- {
417
- this.LogError(
418
- $"Selected folder must be inside the project's Assets folder. Path selected: {path}"
419
- );
420
- }
421
- }
422
-
423
356
  private List<(string fullFilePath, string relativePath)> GetTargetSpritePaths()
424
357
  {
425
358
  HashSet<string> uniqueRelativePaths = new(StringComparer.OrdinalIgnoreCase);
426
- List<Object> validDirectories = new();
359
+ HashSet<Object> validDirectories = new();
427
360
 
428
361
  for (int i = 0; i < _directoriesProp.arraySize; i++)
429
362
  {
@@ -1,4 +1,4 @@
1
- namespace WallstopStudios.UnityHelpers.Editor
1
+ namespace WallstopStudios.UnityHelpers.Editor.Sprites
2
2
  {
3
3
  #if UNITY_EDITOR
4
4
  using System;
@@ -1,4 +1,4 @@
1
- namespace WallstopStudios.UnityHelpers.Editor
1
+ namespace WallstopStudios.UnityHelpers.Editor.Sprites
2
2
  {
3
3
  #if UNITY_EDITOR
4
4
  using System;
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 047a84383e254687a6110295f9a67349
3
+ timeCreated: 1746910939
@@ -3,7 +3,7 @@
3
3
  #if UNITY_EDITOR
4
4
  using UnityEditor;
5
5
  using UnityEngine;
6
- using WallstopStudios.UnityHelpers.Core.Attributes;
6
+ using Core.Attributes;
7
7
 
8
8
  // https://www.patrykgalach.com/2020/01/20/readonly-attribute-in-unity-editor/
9
9
  [CustomPropertyDrawer(typeof(DxReadOnlyAttribute))]
@@ -4,9 +4,73 @@
4
4
  using System.IO;
5
5
  using System.Runtime.CompilerServices;
6
6
  using UnityEngine;
7
+ #if UNITY_EDITOR
8
+ using UnityEditor;
9
+ #endif
7
10
 
8
11
  public static class DirectoryHelper
9
12
  {
13
+ public static void EnsureDirectoryExists(string relativeDirectoryPath)
14
+ {
15
+ if (string.IsNullOrWhiteSpace(relativeDirectoryPath))
16
+ {
17
+ return;
18
+ }
19
+
20
+ #if UNITY_EDITOR
21
+ if (!relativeDirectoryPath.StartsWith("Assets/"))
22
+ {
23
+ if (relativeDirectoryPath.Equals("Assets", StringComparison.OrdinalIgnoreCase))
24
+ {
25
+ return;
26
+ }
27
+
28
+ Debug.LogError(
29
+ $"Attempted to create directory outside of Assets: '{relativeDirectoryPath}'"
30
+ );
31
+ throw new ArgumentException(
32
+ "Cannot create directories outside the Assets folder using AssetDatabase.",
33
+ nameof(relativeDirectoryPath)
34
+ );
35
+ }
36
+
37
+ if (AssetDatabase.IsValidFolder(relativeDirectoryPath))
38
+ {
39
+ return;
40
+ }
41
+
42
+ string parentPath = Path.GetDirectoryName(relativeDirectoryPath).SanitizePath();
43
+ if (
44
+ string.IsNullOrWhiteSpace(parentPath)
45
+ || parentPath.Equals("Assets", StringComparison.OrdinalIgnoreCase)
46
+ )
47
+ {
48
+ string folderNameToCreate = Path.GetFileName(relativeDirectoryPath);
49
+ if (
50
+ !string.IsNullOrWhiteSpace(folderNameToCreate)
51
+ && !AssetDatabase.IsValidFolder(relativeDirectoryPath)
52
+ )
53
+ {
54
+ AssetDatabase.CreateFolder("Assets", folderNameToCreate);
55
+ }
56
+ return;
57
+ }
58
+
59
+ EnsureDirectoryExists(parentPath);
60
+ string currentFolderName = Path.GetFileName(relativeDirectoryPath);
61
+ if (
62
+ !string.IsNullOrWhiteSpace(currentFolderName)
63
+ && !AssetDatabase.IsValidFolder(relativeDirectoryPath)
64
+ )
65
+ {
66
+ AssetDatabase.CreateFolder(parentPath, currentFolderName);
67
+ Debug.Log($"Created folder: {relativeDirectoryPath}");
68
+ }
69
+ #else
70
+ Directory.CreateDirectory(relativeDirectoryPath);
71
+ #endif
72
+ }
73
+
10
74
  public static string GetCallerScriptDirectory([CallerFilePath] string sourceFilePath = "")
11
75
  {
12
76
  return string.IsNullOrWhiteSpace(sourceFilePath)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc73.13",
3
+ "version": "2.0.0-rc73.15",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},
@@ -49,3 +49,5 @@
49
49
 
50
50
 
51
51
 
52
+
53
+