com.wallstop-studios.unity-helpers 2.0.0-rc73.9 → 2.0.0-rc74.1
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/AnimationEventEditor.cs +4 -5
- package/Editor/CustomEditors/MatchColliderToSpriteEditor.cs +1 -1
- package/Editor/CustomEditors/PersistentDirectoryGUI.cs +796 -0
- package/Editor/CustomEditors/PersistentDirectoryGUI.cs.meta +3 -0
- package/Editor/CustomEditors/SourceFolderEntryDrawer.cs +275 -0
- package/Editor/CustomEditors/SourceFolderEntryDrawer.cs.meta +3 -0
- package/Editor/FitTextureSizeWindow.cs +5 -44
- package/Editor/PersistentDirectorySettings.cs +248 -0
- package/Editor/PersistentDirectorySettings.cs.meta +3 -0
- package/Editor/PrefabChecker.cs +1 -2
- package/Editor/{AnimationCopier.cs → Sprites/AnimationCopier.cs} +33 -166
- package/Editor/{AnimationCreator.cs → Sprites/AnimationCreator.cs} +16 -80
- package/Editor/Sprites/ScriptableSpriteAtlas.cs +95 -0
- package/Editor/Sprites/ScriptableSpriteAtlas.cs.meta +3 -0
- package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs +930 -0
- package/Editor/Sprites/ScriptableSpriteAtlasEditor.cs.meta +3 -0
- package/Editor/{SpriteCropper.cs → Sprites/SpriteCropper.cs} +80 -77
- package/Editor/{SpriteSettingsApplier.cs → Sprites/SpriteSettingsApplier.cs} +9 -76
- package/Editor/{TextureResizerWizard.cs → Sprites/TextureResizerWizard.cs} +1 -1
- package/Editor/{TextureSettingsApplier.cs → Sprites/TextureSettingsApplier.cs} +1 -1
- package/Editor/Sprites.meta +3 -0
- package/Editor/Utils/DxReadOnlyPropertyDrawer.cs +1 -1
- package/Runtime/Core/Helper/DirectoryHelper.cs +64 -0
- package/Runtime/Core/Helper/Partials/ObjectHelpers.cs +3 -2
- package/Runtime/UI/LayeredImage.cs +8 -6
- package/package.json +13 -1
- package/Editor/SpriteAtlasGenerator.cs +0 -895
- package/Editor/SpriteAtlasGenerator.cs.meta +0 -3
- package/Editor/Utils/GUIHorizontalScope.cs +0 -20
- package/Editor/Utils/GUIHorizontalScope.cs.meta +0 -3
- package/Editor/Utils/GUIIndentScope.cs +0 -20
- package/Editor/Utils/GUIIndentScope.cs.meta +0 -3
- /package/Editor/{AnimationCopier.cs.meta → Sprites/AnimationCopier.cs.meta} +0 -0
- /package/Editor/{AnimationCreator.cs.meta → Sprites/AnimationCreator.cs.meta} +0 -0
- /package/Editor/{SpriteCropper.cs.meta → Sprites/SpriteCropper.cs.meta} +0 -0
- /package/Editor/{SpriteSettingsApplier.cs.meta → Sprites/SpriteSettingsApplier.cs.meta} +0 -0
- /package/Editor/{TextureResizerWizard.cs.meta → Sprites/TextureResizerWizard.cs.meta} +0 -0
- /package/Editor/{TextureSettingsApplier.cs.meta → Sprites/TextureSettingsApplier.cs.meta} +0 -0
|
@@ -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;
|
|
@@ -10,16 +10,15 @@
|
|
|
10
10
|
using UnityEngine;
|
|
11
11
|
using Core.Extension;
|
|
12
12
|
using Core.Helper;
|
|
13
|
+
using CustomEditors;
|
|
13
14
|
|
|
14
15
|
public sealed class AnimationCopierWindow : EditorWindow
|
|
15
16
|
{
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
private const string DefaultSourcePath = "Assets/Sprites";
|
|
19
|
-
private const string DefaultDestPath = "Assets/Animations";
|
|
17
|
+
[SerializeField]
|
|
18
|
+
private string _animationSourcePathRelative = "Assets/Sprites";
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
private string _animationDestinationPathRelative = "";
|
|
20
|
+
[SerializeField]
|
|
21
|
+
private string _animationDestinationPathRelative = "Assets/Animations";
|
|
23
22
|
private string _fullSourcePath = "";
|
|
24
23
|
private string _fullDestinationPath = "";
|
|
25
24
|
|
|
@@ -28,6 +27,10 @@
|
|
|
28
27
|
private bool _isCopying;
|
|
29
28
|
private bool _isDeleting;
|
|
30
29
|
|
|
30
|
+
private SerializedObject _serializedObject;
|
|
31
|
+
private SerializedProperty _animationSourcesPathProperty;
|
|
32
|
+
private SerializedProperty _animationDestinationPathProperty;
|
|
33
|
+
|
|
31
34
|
private readonly List<AnimationFileInfo> _sourceAnimations = new();
|
|
32
35
|
private readonly List<AnimationFileInfo> _newAnimations = new();
|
|
33
36
|
private readonly List<AnimationFileInfo> _changedAnimations = new();
|
|
@@ -67,7 +70,13 @@
|
|
|
67
70
|
|
|
68
71
|
private void OnEnable()
|
|
69
72
|
{
|
|
70
|
-
|
|
73
|
+
_serializedObject = new SerializedObject(this);
|
|
74
|
+
_animationSourcesPathProperty = _serializedObject.FindProperty(
|
|
75
|
+
nameof(_animationSourcePathRelative)
|
|
76
|
+
);
|
|
77
|
+
_animationDestinationPathProperty = _serializedObject.FindProperty(
|
|
78
|
+
nameof(_animationDestinationPathRelative)
|
|
79
|
+
);
|
|
71
80
|
ValidatePaths();
|
|
72
81
|
_analysisNeeded = true;
|
|
73
82
|
this.Log($"Animation Copier Window opened.");
|
|
@@ -75,6 +84,7 @@
|
|
|
75
84
|
|
|
76
85
|
private void OnGUI()
|
|
77
86
|
{
|
|
87
|
+
_serializedObject.Update();
|
|
78
88
|
bool operationInProgress = _isAnalyzing || _isCopying || _isDeleting;
|
|
79
89
|
|
|
80
90
|
if (operationInProgress)
|
|
@@ -88,18 +98,18 @@
|
|
|
88
98
|
|
|
89
99
|
EditorGUI.BeginDisabledGroup(operationInProgress);
|
|
90
100
|
|
|
91
|
-
|
|
101
|
+
PersistentDirectoryGUI.PathSelectorString(
|
|
102
|
+
_animationSourcesPathProperty,
|
|
103
|
+
nameof(AnimationCopierWindow),
|
|
92
104
|
"Source Path",
|
|
93
|
-
|
|
94
|
-
ref _fullSourcePath,
|
|
95
|
-
SourcePathPrefKey
|
|
105
|
+
new GUIContent("Source Path")
|
|
96
106
|
);
|
|
97
107
|
EditorGUILayout.Separator();
|
|
98
|
-
|
|
108
|
+
PersistentDirectoryGUI.PathSelectorString(
|
|
109
|
+
_animationDestinationPathProperty,
|
|
110
|
+
nameof(AnimationCopierWindow),
|
|
99
111
|
"Destination Path",
|
|
100
|
-
|
|
101
|
-
ref _fullDestinationPath,
|
|
102
|
-
DestPathPrefKey
|
|
112
|
+
new GUIContent("Destination Path")
|
|
103
113
|
);
|
|
104
114
|
EditorGUILayout.Separator();
|
|
105
115
|
|
|
@@ -126,85 +136,6 @@
|
|
|
126
136
|
}
|
|
127
137
|
}
|
|
128
138
|
|
|
129
|
-
private void DrawPathSection(
|
|
130
|
-
string label,
|
|
131
|
-
ref string relativePath,
|
|
132
|
-
ref string fullPath,
|
|
133
|
-
string prefKey
|
|
134
|
-
)
|
|
135
|
-
{
|
|
136
|
-
if (!prefKey.StartsWith("WallstopStudios.UnityHelpers.Editor"))
|
|
137
|
-
{
|
|
138
|
-
prefKey = "WallstopStudios.UnityHelpers.Editor" + prefKey;
|
|
139
|
-
}
|
|
140
|
-
EditorGUILayout.LabelField(label + ":", EditorStyles.boldLabel);
|
|
141
|
-
|
|
142
|
-
EditorGUI.BeginChangeCheck();
|
|
143
|
-
string newRelativePath = EditorGUILayout.TextField(relativePath ?? "");
|
|
144
|
-
if (EditorGUI.EndChangeCheck() && newRelativePath != relativePath)
|
|
145
|
-
{
|
|
146
|
-
if (string.IsNullOrWhiteSpace(newRelativePath))
|
|
147
|
-
{
|
|
148
|
-
relativePath = "";
|
|
149
|
-
fullPath = "";
|
|
150
|
-
EditorPrefs.SetString(prefKey, "");
|
|
151
|
-
ValidatePaths();
|
|
152
|
-
_analysisNeeded = true;
|
|
153
|
-
}
|
|
154
|
-
else
|
|
155
|
-
{
|
|
156
|
-
string tempFullPath = GetFullPathFromRelative(newRelativePath);
|
|
157
|
-
if (tempFullPath != null && Directory.Exists(tempFullPath))
|
|
158
|
-
{
|
|
159
|
-
relativePath = newRelativePath;
|
|
160
|
-
fullPath = tempFullPath;
|
|
161
|
-
EditorPrefs.SetString(prefKey, relativePath);
|
|
162
|
-
ValidatePaths();
|
|
163
|
-
_analysisNeeded = true;
|
|
164
|
-
}
|
|
165
|
-
else
|
|
166
|
-
{
|
|
167
|
-
this.LogWarn(
|
|
168
|
-
$"Manual path entry '{newRelativePath}' is invalid or not inside Assets. Please use the button."
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (GUILayout.Button("Browse..."))
|
|
175
|
-
{
|
|
176
|
-
string initialPath = Directory.Exists(fullPath) ? fullPath : Application.dataPath;
|
|
177
|
-
string selectedPath = EditorUtility.OpenFolderPanel(
|
|
178
|
-
$"Select {label}",
|
|
179
|
-
initialPath,
|
|
180
|
-
string.Empty
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
if (!string.IsNullOrWhiteSpace(selectedPath))
|
|
184
|
-
{
|
|
185
|
-
string newRelPath = GetRelativeAssetPath(selectedPath);
|
|
186
|
-
if (newRelPath != null)
|
|
187
|
-
{
|
|
188
|
-
relativePath = newRelPath;
|
|
189
|
-
fullPath = selectedPath.SanitizePath();
|
|
190
|
-
EditorPrefs.SetString(prefKey, relativePath);
|
|
191
|
-
this.Log($"{label} set to: {relativePath}");
|
|
192
|
-
ValidatePaths();
|
|
193
|
-
_analysisNeeded = true;
|
|
194
|
-
Repaint();
|
|
195
|
-
}
|
|
196
|
-
else
|
|
197
|
-
{
|
|
198
|
-
EditorUtility.DisplayDialog(
|
|
199
|
-
"Invalid Path",
|
|
200
|
-
"The selected path must be inside the project's 'Assets' folder.",
|
|
201
|
-
"OK"
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
139
|
private void DrawAnalysisSection()
|
|
209
140
|
{
|
|
210
141
|
EditorGUILayout.LabelField("Analysis:", EditorStyles.boldLabel);
|
|
@@ -339,18 +270,6 @@
|
|
|
339
270
|
}
|
|
340
271
|
}
|
|
341
272
|
|
|
342
|
-
private void LoadPaths()
|
|
343
|
-
{
|
|
344
|
-
_animationSourcePathRelative = EditorPrefs.GetString(
|
|
345
|
-
SourcePathPrefKey,
|
|
346
|
-
DefaultSourcePath
|
|
347
|
-
);
|
|
348
|
-
_animationDestinationPathRelative = EditorPrefs.GetString(
|
|
349
|
-
DestPathPrefKey,
|
|
350
|
-
DefaultDestPath
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
273
|
private void ValidatePaths()
|
|
355
274
|
{
|
|
356
275
|
_fullSourcePath = GetFullPathFromRelative(_animationSourcePathRelative);
|
|
@@ -390,7 +309,12 @@
|
|
|
390
309
|
return !string.IsNullOrWhiteSpace(_animationSourcePathRelative)
|
|
391
310
|
&& !string.IsNullOrWhiteSpace(_animationDestinationPathRelative)
|
|
392
311
|
&& _fullSourcePath != null
|
|
393
|
-
&& _fullDestinationPath != null
|
|
312
|
+
&& _fullDestinationPath != null
|
|
313
|
+
&& !string.Equals(
|
|
314
|
+
_animationSourcePathRelative,
|
|
315
|
+
_animationDestinationPathRelative,
|
|
316
|
+
StringComparison.Ordinal
|
|
317
|
+
);
|
|
394
318
|
}
|
|
395
319
|
|
|
396
320
|
private void AnalyzeAnimations()
|
|
@@ -615,7 +539,7 @@
|
|
|
615
539
|
|
|
616
540
|
try
|
|
617
541
|
{
|
|
618
|
-
EnsureDirectoryExists(destDirectory);
|
|
542
|
+
DirectoryHelper.EnsureDirectoryExists(destDirectory);
|
|
619
543
|
}
|
|
620
544
|
catch (Exception ex)
|
|
621
545
|
{
|
|
@@ -902,63 +826,6 @@
|
|
|
902
826
|
return string.Empty;
|
|
903
827
|
}
|
|
904
828
|
}
|
|
905
|
-
|
|
906
|
-
private void EnsureDirectoryExists(string relativeDirectoryPath)
|
|
907
|
-
{
|
|
908
|
-
if (string.IsNullOrWhiteSpace(relativeDirectoryPath))
|
|
909
|
-
{
|
|
910
|
-
return;
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
if (!relativeDirectoryPath.StartsWith("Assets/"))
|
|
914
|
-
{
|
|
915
|
-
if (relativeDirectoryPath.Equals("Assets", StringComparison.OrdinalIgnoreCase))
|
|
916
|
-
{
|
|
917
|
-
return;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
this.LogError(
|
|
921
|
-
$"Attempted to create directory outside of Assets: '{relativeDirectoryPath}'"
|
|
922
|
-
);
|
|
923
|
-
throw new ArgumentException(
|
|
924
|
-
"Cannot create directories outside the Assets folder using AssetDatabase.",
|
|
925
|
-
nameof(relativeDirectoryPath)
|
|
926
|
-
);
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
if (AssetDatabase.IsValidFolder(relativeDirectoryPath))
|
|
930
|
-
{
|
|
931
|
-
return;
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
string parentPath = Path.GetDirectoryName(relativeDirectoryPath).SanitizePath();
|
|
935
|
-
if (
|
|
936
|
-
string.IsNullOrWhiteSpace(parentPath)
|
|
937
|
-
|| parentPath.Equals("Assets", StringComparison.OrdinalIgnoreCase)
|
|
938
|
-
)
|
|
939
|
-
{
|
|
940
|
-
string folderNameToCreate = Path.GetFileName(relativeDirectoryPath);
|
|
941
|
-
if (
|
|
942
|
-
!string.IsNullOrWhiteSpace(folderNameToCreate)
|
|
943
|
-
&& !AssetDatabase.IsValidFolder(relativeDirectoryPath)
|
|
944
|
-
)
|
|
945
|
-
{
|
|
946
|
-
AssetDatabase.CreateFolder("Assets", folderNameToCreate);
|
|
947
|
-
}
|
|
948
|
-
return;
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
EnsureDirectoryExists(parentPath);
|
|
952
|
-
string currentFolderName = Path.GetFileName(relativeDirectoryPath);
|
|
953
|
-
if (
|
|
954
|
-
!string.IsNullOrWhiteSpace(currentFolderName)
|
|
955
|
-
&& !AssetDatabase.IsValidFolder(relativeDirectoryPath)
|
|
956
|
-
)
|
|
957
|
-
{
|
|
958
|
-
AssetDatabase.CreateFolder(parentPath, currentFolderName);
|
|
959
|
-
this.Log($"Created folder: {relativeDirectoryPath}");
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
829
|
}
|
|
963
830
|
#endif
|
|
964
831
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
namespace WallstopStudios.UnityHelpers.Editor
|
|
1
|
+
namespace WallstopStudios.UnityHelpers.Editor.Sprites
|
|
2
2
|
{
|
|
3
3
|
#if UNITY_EDITOR
|
|
4
|
-
using Core.Extension;
|
|
5
4
|
using System;
|
|
6
5
|
using System.Collections.Generic;
|
|
7
6
|
using System.IO;
|
|
8
7
|
using System.Linq;
|
|
9
8
|
using System.Text.RegularExpressions;
|
|
10
|
-
using Core.Helper;
|
|
11
9
|
using UnityEditor;
|
|
12
10
|
using UnityEngine;
|
|
13
|
-
using
|
|
11
|
+
using Core.Extension;
|
|
12
|
+
using Core.Helper;
|
|
13
|
+
using CustomEditors;
|
|
14
14
|
using Object = UnityEngine.Object;
|
|
15
15
|
|
|
16
16
|
[Serializable]
|
|
@@ -78,12 +78,13 @@
|
|
|
78
78
|
_scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition);
|
|
79
79
|
|
|
80
80
|
EditorGUILayout.LabelField("Configuration", EditorStyles.boldLabel);
|
|
81
|
-
|
|
81
|
+
PersistentDirectoryGUI.PathSelectorObjectArray(
|
|
82
|
+
_animationSourcesProp,
|
|
83
|
+
nameof(AnimationCreatorWindow)
|
|
84
|
+
);
|
|
82
85
|
EditorGUILayout.PropertyField(_spriteNameRegexProp);
|
|
83
86
|
EditorGUILayout.PropertyField(_textProp);
|
|
84
87
|
|
|
85
|
-
DrawAddSourceFolderButton();
|
|
86
|
-
|
|
87
88
|
if (!string.IsNullOrWhiteSpace(_errorMessage))
|
|
88
89
|
{
|
|
89
90
|
EditorGUILayout.HelpBox(_errorMessage, MessageType.Error);
|
|
@@ -122,78 +123,6 @@
|
|
|
122
123
|
_ = _serializedObject.ApplyModifiedProperties();
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
private void DrawAddSourceFolderButton()
|
|
126
|
-
{
|
|
127
|
-
if (!GUILayout.Button("Add Source Folder..."))
|
|
128
|
-
{
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
string absolutePath = EditorUtility.OpenFolderPanel(
|
|
133
|
-
"Select Animation Source Folder",
|
|
134
|
-
"Assets",
|
|
135
|
-
""
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
if (string.IsNullOrWhiteSpace(absolutePath))
|
|
139
|
-
{
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
absolutePath = absolutePath.SanitizePath();
|
|
144
|
-
if (absolutePath.StartsWith(Application.dataPath, StringComparison.OrdinalIgnoreCase))
|
|
145
|
-
{
|
|
146
|
-
string relativePath =
|
|
147
|
-
"Assets" + absolutePath.Substring(Application.dataPath.Length);
|
|
148
|
-
|
|
149
|
-
DefaultAsset folderAsset = AssetDatabase.LoadAssetAtPath<DefaultAsset>(
|
|
150
|
-
relativePath
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
if (folderAsset != null && AssetDatabase.IsValidFolder(relativePath))
|
|
154
|
-
{
|
|
155
|
-
bool alreadyExists = false;
|
|
156
|
-
for (int i = 0; i < _animationSourcesProp.arraySize; ++i)
|
|
157
|
-
{
|
|
158
|
-
if (
|
|
159
|
-
_animationSourcesProp.GetArrayElementAtIndex(i).objectReferenceValue
|
|
160
|
-
== folderAsset
|
|
161
|
-
)
|
|
162
|
-
{
|
|
163
|
-
alreadyExists = true;
|
|
164
|
-
this.LogWarn($"Folder '{relativePath}' is already in the list.");
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
if (!alreadyExists)
|
|
170
|
-
{
|
|
171
|
-
_animationSourcesProp.arraySize++;
|
|
172
|
-
_animationSourcesProp
|
|
173
|
-
.GetArrayElementAtIndex(_animationSourcesProp.arraySize - 1)
|
|
174
|
-
.objectReferenceValue = folderAsset;
|
|
175
|
-
this.Log($"Added source folder: {relativePath}");
|
|
176
|
-
|
|
177
|
-
_serializedObject.ApplyModifiedProperties();
|
|
178
|
-
FindAndFilterSprites();
|
|
179
|
-
Repaint();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else
|
|
183
|
-
{
|
|
184
|
-
this.LogError(
|
|
185
|
-
$"Could not load folder asset at path: {relativePath}. Is it a valid folder within the project?"
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
else
|
|
190
|
-
{
|
|
191
|
-
this.LogError(
|
|
192
|
-
$"Selected folder must be inside the project's Assets folder. Path selected: {absolutePath}"
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
126
|
private void DrawCheckSpritesButton()
|
|
198
127
|
{
|
|
199
128
|
if (GUILayout.Button("Check/Refresh Filtered Sprites"))
|
|
@@ -246,7 +175,7 @@
|
|
|
246
175
|
|
|
247
176
|
if (_animationDataIsExpanded)
|
|
248
177
|
{
|
|
249
|
-
using
|
|
178
|
+
using EditorGUI.IndentLevelScope indent = new();
|
|
250
179
|
if (matchCount > 0)
|
|
251
180
|
{
|
|
252
181
|
foreach (int index in matchingIndices)
|
|
@@ -337,6 +266,13 @@
|
|
|
337
266
|
}
|
|
338
267
|
}
|
|
339
268
|
|
|
269
|
+
if (GUILayout.Button("Create new Animation Data"))
|
|
270
|
+
{
|
|
271
|
+
animationData.Add(new AnimationData());
|
|
272
|
+
_serializedObject.Update();
|
|
273
|
+
Repaint();
|
|
274
|
+
}
|
|
275
|
+
|
|
340
276
|
if (_filteredSprites.Count == 0)
|
|
341
277
|
{
|
|
342
278
|
EditorGUILayout.HelpBox(
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
namespace WallstopStudios.UnityHelpers.Editor.Sprites
|
|
2
|
+
{
|
|
3
|
+
#if UNITY_EDITOR
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
using System.Collections.Generic;
|
|
6
|
+
using Core.Attributes;
|
|
7
|
+
using Core.Helper;
|
|
8
|
+
using UnityEditor;
|
|
9
|
+
|
|
10
|
+
[System.Serializable]
|
|
11
|
+
public sealed class SourceFolderEntry
|
|
12
|
+
{
|
|
13
|
+
[Tooltip("Folder to scan for sprites. Path relative to Assets/.")]
|
|
14
|
+
public string folderPath = "Assets/Sprites/";
|
|
15
|
+
|
|
16
|
+
[Tooltip(
|
|
17
|
+
"Regex patterns to match sprite file names within this specific folder. All regexes must match (AND logic). e.g., \"^icon_.*\\.png$\""
|
|
18
|
+
)]
|
|
19
|
+
public List<string> regexes = new();
|
|
20
|
+
|
|
21
|
+
public SourceFolderEntry() { }
|
|
22
|
+
|
|
23
|
+
public SourceFolderEntry(string path)
|
|
24
|
+
{
|
|
25
|
+
folderPath = path;
|
|
26
|
+
regexes = new List<string>();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
[CreateAssetMenu(
|
|
31
|
+
fileName = "NewScriptableSpriteAtlas",
|
|
32
|
+
menuName = "Wallstop Studios/Unity Helpers/Scriptable Sprite Atlas Config"
|
|
33
|
+
)]
|
|
34
|
+
public sealed class ScriptableSpriteAtlas : ScriptableObject
|
|
35
|
+
{
|
|
36
|
+
[Header("Sprite Sources")]
|
|
37
|
+
[Tooltip(
|
|
38
|
+
"Manually added sprites. These will always be included in addition to scanned sprites."
|
|
39
|
+
)]
|
|
40
|
+
public List<Sprite> spritesToPack = new();
|
|
41
|
+
|
|
42
|
+
[Tooltip("Define folders and their specific regex patterns for finding sprites.")]
|
|
43
|
+
public List<SourceFolderEntry> sourceFolderEntries = new();
|
|
44
|
+
|
|
45
|
+
[Header("Output Atlas Settings")]
|
|
46
|
+
[Tooltip("Directory where the .spriteatlas asset will be saved. Relative to Assets/.")]
|
|
47
|
+
public string outputSpriteAtlasDirectory = "Assets/Sprites/SpriteAtlas";
|
|
48
|
+
public string outputSpriteAtlasName = "MyNewAtlas";
|
|
49
|
+
|
|
50
|
+
public string FullOutputPath
|
|
51
|
+
{
|
|
52
|
+
get
|
|
53
|
+
{
|
|
54
|
+
if (
|
|
55
|
+
string.IsNullOrWhiteSpace(outputSpriteAtlasDirectory)
|
|
56
|
+
|| string.IsNullOrWhiteSpace(outputSpriteAtlasName)
|
|
57
|
+
)
|
|
58
|
+
{
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return System
|
|
63
|
+
.IO.Path.Combine(
|
|
64
|
+
outputSpriteAtlasDirectory,
|
|
65
|
+
outputSpriteAtlasName + ".spriteatlas"
|
|
66
|
+
)
|
|
67
|
+
.SanitizePath();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[Header("Packing Settings")]
|
|
72
|
+
public int maxTextureSize = 16384;
|
|
73
|
+
|
|
74
|
+
[Tooltip("Allow Unity to rotate sprites to fit them better.")]
|
|
75
|
+
public bool enableRotation = true;
|
|
76
|
+
|
|
77
|
+
[Tooltip("Padding in pixels between sprites in the atlas.")]
|
|
78
|
+
public int padding = 4;
|
|
79
|
+
|
|
80
|
+
[Tooltip(
|
|
81
|
+
"Enable Read/Write on the generated atlas texture. Needed for some runtime operations, but increases memory."
|
|
82
|
+
)]
|
|
83
|
+
public bool readWriteEnabled = true;
|
|
84
|
+
|
|
85
|
+
[Header("Compression Settings")]
|
|
86
|
+
public bool useCrunchCompression = true;
|
|
87
|
+
|
|
88
|
+
[Range(0, 100)]
|
|
89
|
+
[WShowIf(nameof(useCrunchCompression))]
|
|
90
|
+
public int crunchCompressionLevel = 50;
|
|
91
|
+
|
|
92
|
+
public TextureImporterCompression compression = TextureImporterCompression.Compressed;
|
|
93
|
+
}
|
|
94
|
+
#endif
|
|
95
|
+
}
|