com.wallstop-studios.unity-helpers 2.0.0-rc74.4 → 2.0.0-rc74.6

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.
@@ -816,6 +816,7 @@
816
816
  int errorCount = 0;
817
817
  HashSet<string> processedAssetPaths = new();
818
818
 
819
+ List<TextureImporter> importers = new();
819
820
  AssetDatabase.StartAssetEditing();
820
821
  try
821
822
  {
@@ -901,6 +902,7 @@
901
902
  if (settingsActuallyModified)
902
903
  {
903
904
  importer.SaveAndReimport();
905
+ importers.Add(importer);
904
906
  modifiedCount++;
905
907
  this.Log(
906
908
  $"Set import settings for texture: {assetPath} (from sprite: {sprite.name}) to uncompressed ({targetFormat})."
@@ -914,8 +916,14 @@
914
916
  EditorUtility.ClearProgressBar();
915
917
  }
916
918
 
919
+ foreach (TextureImporter importer in importers)
920
+ {
921
+ importer.SaveAndReimport();
922
+ }
923
+
917
924
  if (modifiedCount > 0 || errorCount > 0)
918
925
  {
926
+ AssetDatabase.SaveAssets();
919
927
  AssetDatabase.Refresh();
920
928
  }
921
929
 
@@ -5,11 +5,13 @@
5
5
  using System.Collections.Generic;
6
6
  using System.IO;
7
7
  using System.Linq;
8
+ using System.Text.RegularExpressions;
8
9
  using System.Threading.Tasks;
9
10
  using UnityEditor;
10
11
  using UnityEngine;
11
12
  using Core.Extension;
12
13
  using CustomEditors;
14
+ using Microsoft.CodeAnalysis.CSharp.Syntax;
13
15
  using Object = UnityEngine.Object;
14
16
 
15
17
  public sealed class SpriteCropper : EditorWindow
@@ -33,6 +35,9 @@
33
35
  [SerializeField]
34
36
  private List<Object> _inputDirectories = new();
35
37
 
38
+ [SerializeField]
39
+ private string _spriteNameRegex = ".*";
40
+
36
41
  [SerializeField]
37
42
  private bool _onlyNecessary;
38
43
 
@@ -56,6 +61,9 @@
56
61
  private SerializedProperty _rightPaddingProperty;
57
62
  private SerializedProperty _topPaddingProperty;
58
63
  private SerializedProperty _bottomPaddingProperty;
64
+ private SerializedProperty _spriteNameRegexProperty;
65
+
66
+ private Regex _regex;
59
67
 
60
68
  [MenuItem("Tools/Wallstop Studios/Unity Helpers/" + Name)]
61
69
  private static void ShowWindow() => GetWindow<SpriteCropper>(Name);
@@ -69,6 +77,7 @@
69
77
  _rightPaddingProperty = _serializedObject.FindProperty(nameof(_rightPadding));
70
78
  _topPaddingProperty = _serializedObject.FindProperty(nameof(_topPadding));
71
79
  _bottomPaddingProperty = _serializedObject.FindProperty(nameof(_bottomPadding));
80
+ _spriteNameRegexProperty = _serializedObject.FindProperty(nameof(_spriteNameRegex));
72
81
  }
73
82
 
74
83
  private void OnGUI()
@@ -79,6 +88,7 @@
79
88
  _inputDirectoriesProperty,
80
89
  nameof(SpriteCropper)
81
90
  );
91
+ EditorGUILayout.PropertyField(_spriteNameRegexProperty, true);
82
92
  EditorGUILayout.PropertyField(_onlyNecessaryProperty, true);
83
93
  EditorGUILayout.PropertyField(_leftPaddingProperty, true);
84
94
  EditorGUILayout.PropertyField(_rightPaddingProperty, true);
@@ -88,6 +98,9 @@
88
98
 
89
99
  if (GUILayout.Button("Find Sprites To Process"))
90
100
  {
101
+ _regex = !string.IsNullOrWhiteSpace(_spriteNameRegex)
102
+ ? new Regex(_spriteNameRegex)
103
+ : null;
91
104
  FindFilesToProcess();
92
105
  }
93
106
 
@@ -146,6 +159,13 @@
146
159
  {
147
160
  continue;
148
161
  }
162
+
163
+ string fileName = Path.GetFileNameWithoutExtension(file);
164
+ if (_regex != null && !_regex.IsMatch(fileName))
165
+ {
166
+ continue;
167
+ }
168
+
149
169
  _filesToProcess.Add(file);
150
170
  }
151
171
  }
@@ -559,6 +559,7 @@ namespace WallstopStudios.UnityHelpers.Editor.Sprites
559
559
  return;
560
560
  }
561
561
 
562
+ List<TextureImporter> importers = new();
562
563
  AssetDatabase.StartAssetEditing();
563
564
  try
564
565
  {
@@ -591,6 +592,7 @@ namespace WallstopStudios.UnityHelpers.Editor.Sprites
591
592
  try
592
593
  {
593
594
  importer.SaveAndReimport();
595
+ importers.Add(importer);
594
596
  }
595
597
  catch (Exception ex)
596
598
  {
@@ -604,6 +606,11 @@ namespace WallstopStudios.UnityHelpers.Editor.Sprites
604
606
  {
605
607
  AssetDatabase.StopAssetEditing();
606
608
  EditorUtility.ClearProgressBar();
609
+ foreach (TextureImporter importer in importers)
610
+ {
611
+ importer.SaveAndReimport();
612
+ }
613
+
607
614
  this.Log($"Processed {spriteCount} sprites.");
608
615
  if (0 < spriteCount)
609
616
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc74.4",
3
+ "version": "2.0.0-rc74.6",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},
@@ -57,6 +57,8 @@
57
57
 
58
58
 
59
59
 
60
+
61
+
60
62
 
61
63
 
62
64