com.wallstop-studios.unity-helpers 2.0.0-rc76.6 → 2.0.0-rc76.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.
@@ -1,23 +1,93 @@
1
1
  namespace WallstopStudios.UnityHelpers.Editor.Sprites
2
2
  {
3
3
  #if UNITY_EDITOR
4
+ using System;
4
5
  using UnityEngine;
5
6
  using System.Collections.Generic;
6
7
  using Core.Attributes;
7
8
  using Core.Helper;
8
9
  using UnityEditor;
9
10
 
10
- [System.Serializable]
11
+ [Flags]
12
+ public enum SpriteSelectionMode
13
+ {
14
+ [Obsolete("Please select a valid value")]
15
+ None = 0,
16
+ Regex = 1 << 0,
17
+ Labels = 1 << 1,
18
+ }
19
+
20
+ public enum LabelSelectionMode
21
+ {
22
+ [Obsolete("Please select a valid value")]
23
+ None = 0,
24
+ All = 1 << 0,
25
+ AnyOf = 1 << 1,
26
+ }
27
+
28
+ public enum SpriteSelectionBooleanLogic
29
+ {
30
+ [Obsolete("Please select a valid value")]
31
+ None = 0,
32
+ And = 1 << 0,
33
+ Or = 1 << 1,
34
+ }
35
+
36
+ [Serializable]
11
37
  public sealed class SourceFolderEntry
12
38
  {
13
39
  [Tooltip("Folder to scan for sprites. Path relative to Assets/.")]
14
40
  public string folderPath = "Assets/Sprites/";
15
41
 
42
+ public SpriteSelectionMode selectionMode = SpriteSelectionMode.Regex;
43
+
44
+ [WShowIf(
45
+ nameof(selectionMode),
46
+ expectedValues = new object[]
47
+ {
48
+ SpriteSelectionMode.Regex,
49
+ SpriteSelectionMode.Regex | SpriteSelectionMode.Labels,
50
+ }
51
+ )]
16
52
  [Tooltip(
17
53
  "Regex patterns to match sprite file names within this specific folder. All regexes must match (AND logic). e.g., \"^icon_.*\\.png$\""
18
54
  )]
19
55
  public List<string> regexes = new();
20
56
 
57
+ [WShowIf(
58
+ nameof(selectionMode),
59
+ expectedValues = new object[]
60
+ {
61
+ SpriteSelectionMode.Regex | SpriteSelectionMode.Labels,
62
+ (SpriteSelectionMode)(-1),
63
+ }
64
+ )]
65
+ public SpriteSelectionBooleanLogic regexAndTagLogic = SpriteSelectionBooleanLogic.And;
66
+
67
+ [WShowIf(
68
+ nameof(selectionMode),
69
+ expectedValues = new object[]
70
+ {
71
+ SpriteSelectionMode.Labels,
72
+ SpriteSelectionMode.Regex | SpriteSelectionMode.Labels,
73
+ (SpriteSelectionMode)(-1),
74
+ }
75
+ )]
76
+ public LabelSelectionMode labelSelectionMode = LabelSelectionMode.All;
77
+
78
+ [WShowIf(
79
+ nameof(selectionMode),
80
+ expectedValues = new object[]
81
+ {
82
+ SpriteSelectionMode.Labels,
83
+ SpriteSelectionMode.Regex | SpriteSelectionMode.Labels,
84
+ (SpriteSelectionMode)(-1),
85
+ }
86
+ )]
87
+ [Tooltip("Asset labels to include in the folders.")]
88
+ [StringInList(typeof(Helpers), nameof(Helpers.GetAllSpriteLabelNames))]
89
+ public List<string> labels = new();
90
+
21
91
  public SourceFolderEntry() { }
22
92
 
23
93
  public SourceFolderEntry(string path)
@@ -3,6 +3,7 @@
3
3
  #if UNITY_EDITOR
4
4
  using System;
5
5
  using System.Collections.Generic;
6
+ using System.ComponentModel;
6
7
  using System.IO;
7
8
  using System.Linq;
8
9
  using System.Text.RegularExpressions;
@@ -376,22 +377,18 @@
376
377
  GUILayout.Button(
377
378
  $"Force Uncompressed for {validSpriteCount} Source Sprites in '{config.name}'"
378
379
  )
380
+ && EditorUtility.DisplayDialog(
381
+ "Force Uncompressed Source Sprites",
382
+ $"This will modify the import settings of {validSpriteCount} source sprites currently in the '{config.name}' list.\n\n"
383
+ + "- Crunch compression will be disabled.\n"
384
+ + "- Texture format for the 'Default' platform will be set to uncompressed (RGBA32 or RGB24).\n\n"
385
+ + "This action modifies source asset import settings and may require re-packing atlases. Are you sure?",
386
+ "Yes, Modify Source Sprites",
387
+ "Cancel"
388
+ )
379
389
  )
380
390
  {
381
- if (
382
- EditorUtility.DisplayDialog(
383
- "Force Uncompressed Source Sprites",
384
- $"This will modify the import settings of {validSpriteCount} source sprites currently in the '{config.name}' list.\n\n"
385
- + "- Crunch compression will be disabled.\n"
386
- + "- Texture format for the 'Default' platform will be set to uncompressed (RGBA32 or RGB24).\n\n"
387
- + "This action modifies source asset import settings and may require re-packing atlases. Are you sure?",
388
- "Yes, Modify Source Sprites",
389
- "Cancel"
390
- )
391
- )
392
- {
393
- ForceUncompressedSourceSprites(config);
394
- }
391
+ ForceUncompressedSourceSprites(config);
395
392
  }
396
393
  EditorGUI.EndDisabledGroup();
397
394
 
@@ -400,19 +397,15 @@
400
397
  GUILayout.Button(
401
398
  $"Generate/Update '{config.outputSpriteAtlasName}.spriteatlas' ONLY"
402
399
  )
400
+ && EditorUtility.DisplayDialog(
401
+ $"Generate Atlas: {config.name}",
402
+ $"This will create or update '{config.outputSpriteAtlasName}.spriteatlas'. Continue?",
403
+ "Yes",
404
+ "No"
405
+ )
403
406
  )
404
407
  {
405
- if (
406
- EditorUtility.DisplayDialog(
407
- $"Generate Atlas: {config.name}",
408
- $"This will create or update '{config.outputSpriteAtlasName}.spriteatlas'. Continue?",
409
- "Yes",
410
- "No"
411
- )
412
- )
413
- {
414
- GenerateSingleAtlas(config);
415
- }
408
+ GenerateSingleAtlas(config);
416
409
  }
417
410
  }
418
411
  EditorGUILayout.EndVertical();
@@ -478,18 +471,16 @@
478
471
  string assetPath = AssetDatabase.GUIDToAssetPath(guid);
479
472
  string fileName = Path.GetFileName(assetPath);
480
473
 
481
- bool matchesAllRegexesInEntry;
474
+ bool matchesAllRegexesInEntry = true;
482
475
  List<string> activeRegexPatterns = entry
483
476
  .regexes.Where(r => !string.IsNullOrWhiteSpace(r))
484
477
  .ToList();
485
478
 
486
- if (activeRegexPatterns.Count == 0)
487
- {
488
- matchesAllRegexesInEntry = true;
489
- }
490
- else
479
+ if (
480
+ entry.selectionMode.HasFlagNoAlloc(SpriteSelectionMode.Regex)
481
+ && activeRegexPatterns is { Count: > 0 }
482
+ )
491
483
  {
492
- matchesAllRegexesInEntry = true;
493
484
  foreach (string regexPattern in activeRegexPatterns)
494
485
  {
495
486
  try
@@ -511,7 +502,68 @@
511
502
  }
512
503
  }
513
504
 
514
- if (matchesAllRegexesInEntry)
505
+ bool matchesAllTagsInEntry = true;
506
+ if (
507
+ entry.selectionMode.HasFlagNoAlloc(SpriteSelectionMode.Labels)
508
+ && entry.labels is { Count: > 0 }
509
+ )
510
+ {
511
+ Object mainAsset = AssetDatabase.LoadMainAssetAtPath(assetPath);
512
+ if (mainAsset != null)
513
+ {
514
+ string[] labels = AssetDatabase.GetLabels(mainAsset);
515
+ switch (entry.labelSelectionMode)
516
+ {
517
+ case LabelSelectionMode.All:
518
+ {
519
+ matchesAllTagsInEntry = labels.All(label =>
520
+ entry.labels.Contains(label)
521
+ );
522
+ break;
523
+ }
524
+ case LabelSelectionMode.AnyOf:
525
+ {
526
+ matchesAllTagsInEntry = labels.Any(label =>
527
+ entry.labels.Contains(label)
528
+ );
529
+ break;
530
+ }
531
+ default:
532
+ {
533
+ throw new InvalidEnumArgumentException(
534
+ nameof(entry.labelSelectionMode),
535
+ (int)entry.labelSelectionMode,
536
+ typeof(LabelSelectionMode)
537
+ );
538
+ }
539
+ }
540
+ }
541
+ }
542
+
543
+ bool allMatch;
544
+ switch (entry.regexAndTagLogic)
545
+ {
546
+ case SpriteSelectionBooleanLogic.And:
547
+ {
548
+ allMatch = matchesAllRegexesInEntry && matchesAllTagsInEntry;
549
+ break;
550
+ }
551
+ case SpriteSelectionBooleanLogic.Or:
552
+ {
553
+ allMatch = matchesAllRegexesInEntry || matchesAllTagsInEntry;
554
+ break;
555
+ }
556
+ default:
557
+ {
558
+ throw new InvalidEnumArgumentException(
559
+ nameof(entry.regexAndTagLogic),
560
+ (int)entry.regexAndTagLogic,
561
+ typeof(SpriteSelectionBooleanLogic)
562
+ );
563
+ }
564
+ }
565
+
566
+ if (allMatch)
515
567
  {
516
568
  Object[] assets = AssetDatabase.LoadAllAssetsAtPath(assetPath);
517
569
  foreach (Object asset in assets)