com.wallstop-studios.unity-helpers 2.0.0-rc74.5 → 2.0.0-rc74.7

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.
@@ -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
  }
@@ -343,10 +363,10 @@
343
363
  }
344
364
  else
345
365
  {
346
- minX = Mathf.Max(0, minX - _leftPadding);
347
- minY = Mathf.Max(0, minY - _bottomPadding);
348
- maxX = Mathf.Min(width, maxX + _rightPadding);
349
- maxY = Mathf.Min(height, maxY + _topPadding);
366
+ minX -= _leftPadding;
367
+ minY -= _bottomPadding;
368
+ maxX += _rightPadding;
369
+ maxY += _topPadding;
350
370
  cropWidth = maxX - minX + 1;
351
371
  cropHeight = maxY - minY + 1;
352
372
  }
@@ -368,7 +388,17 @@
368
388
  int destYOffset = y * cropWidth;
369
389
  for (int x = 0; x < cropWidth; ++x)
370
390
  {
371
- croppedPixels[destYOffset + x] = pixels[sourceYOffset + x + minX];
391
+ int sourceIndex = sourceYOffset + x + minX;
392
+ Color32 sourcePixel;
393
+ if (sourceIndex < 0 || pixels.Length <= sourceIndex)
394
+ {
395
+ sourcePixel = Color.clear;
396
+ }
397
+ else
398
+ {
399
+ sourcePixel = pixels[sourceIndex];
400
+ }
401
+ croppedPixels[destYOffset + x] = sourcePixel;
372
402
  }
373
403
  }
374
404
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc74.5",
3
+ "version": "2.0.0-rc74.7",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},
@@ -58,6 +58,8 @@
58
58
 
59
59
 
60
60
 
61
+
62
+
61
63
 
62
64
 
63
65