com.wallstop-studios.unity-helpers 2.0.0-rc69 → 2.0.0-rc71
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/AnimationCopier.cs +875 -93
- package/Editor/AnimationCreator.cs +840 -137
- package/Editor/AnimationEventEditor.cs +4 -4
- package/Editor/AnimatorControllerCopier.cs +3 -3
- package/Editor/Extensions/UnityExtensions.cs +26 -0
- package/Editor/Extensions/UnityExtensions.cs.meta +3 -0
- package/Editor/Extensions.meta +3 -0
- package/Editor/FitTextureSizeWindow.cs +371 -0
- package/Editor/PrefabChecker.cs +722 -0
- package/Editor/SpriteAtlasGenerator.cs +598 -0
- package/Editor/SpriteAtlasGenerator.cs.meta +3 -0
- package/Editor/SpriteCropper.cs +407 -0
- package/Editor/SpriteCropper.cs.meta +3 -0
- package/Editor/SpriteSettingsApplier.cs +756 -92
- package/Editor/TextureResizerWizard.cs +3 -3
- package/Editor/TextureSettingsApplier.cs +9 -9
- package/Editor/WShowIfPropertyDrawer.cs +2 -2
- package/Runtime/Core/Attributes/EnumDisplayNameAttribute.cs +15 -0
- package/Runtime/Core/Attributes/EnumDisplayNameAttribute.cs.meta +3 -0
- package/Runtime/Core/Extension/EnumExtensions.cs +176 -1
- package/Runtime/Core/Extension/UnityExtensions.cs +1 -1
- package/Runtime/Tags/AttributeUtilities.cs +8 -7
- package/Runtime/Tags/EffectHandler.cs +2 -1
- package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +1 -1
- package/Tests/Runtime/DataStructures/CyclicBufferTests.cs +1 -1
- package/Tests/Runtime/DataStructures/QuadTreeTests.cs +1 -1
- package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +1 -1
- package/Tests/Runtime/Extensions/DictionaryExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/EnumExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/IListExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/LoggingExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/RandomExtensionTests.cs +1 -1
- package/Tests/Runtime/Extensions/StringExtensionTests.cs +1 -1
- package/Tests/Runtime/Helper/WallMathTests.cs +1 -1
- package/Tests/Runtime/Performance/KDTreePerformanceTests.cs +1 -1
- package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +1 -1
- package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +1 -1
- package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +1 -1
- package/Tests/Runtime/Random/RandomTestBase.cs +2 -2
- package/Tests/Runtime/Serialization/JsonSerializationTest.cs +1 -1
- package/package.json +1 -1
- package/Editor/FitTextureSizeWizard.cs +0 -147
- package/Editor/PrefabCheckWizard.cs +0 -167
- /package/Editor/{FitTextureSizeWizard.cs.meta → FitTextureSizeWindow.cs.meta} +0 -0
- /package/Editor/{PrefabCheckWizard.cs.meta → PrefabChecker.cs.meta} +0 -0
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
namespace WallstopStudios.UnityHelpers.Editor
|
|
2
|
-
{
|
|
3
|
-
using System.Collections.Generic;
|
|
4
|
-
using System.Linq;
|
|
5
|
-
using UnityEditor;
|
|
6
|
-
using UnityEngine;
|
|
7
|
-
using WallstopStudios.UnityHelpers.Core.Extension;
|
|
8
|
-
|
|
9
|
-
public enum FitMode
|
|
10
|
-
{
|
|
11
|
-
GrowAndShrink = 0,
|
|
12
|
-
GrowOnly = 1,
|
|
13
|
-
ShrinkOnly = 2,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public sealed class FitTextureSizeWizard : ScriptableWizard
|
|
17
|
-
{
|
|
18
|
-
public FitMode fitMode = FitMode.GrowAndShrink;
|
|
19
|
-
public List<Texture2D> textures = new();
|
|
20
|
-
|
|
21
|
-
public List<Object> textureSourcePaths = new();
|
|
22
|
-
|
|
23
|
-
[MenuItem("Tools/Unity Helpers/Fit Texture Size", priority = -1)]
|
|
24
|
-
public static void EnsureSizes()
|
|
25
|
-
{
|
|
26
|
-
_ = DisplayWizard<FitTextureSizeWizard>("Fit Texture Size", "Run");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private void OnWizardCreate()
|
|
30
|
-
{
|
|
31
|
-
textures ??= new List<Texture2D>();
|
|
32
|
-
textureSourcePaths ??= new List<Object>();
|
|
33
|
-
HashSet<string> texturePaths = new();
|
|
34
|
-
foreach (
|
|
35
|
-
string assetPath in textureSourcePaths
|
|
36
|
-
.Select(AssetDatabase.GetAssetPath)
|
|
37
|
-
.Where(assetPath => !string.IsNullOrWhiteSpace(assetPath))
|
|
38
|
-
)
|
|
39
|
-
{
|
|
40
|
-
_ = texturePaths.Add(assetPath);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!textures.Any() && !texturePaths.Any())
|
|
44
|
-
{
|
|
45
|
-
texturePaths.Add("Assets");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (texturePaths.Any())
|
|
49
|
-
{
|
|
50
|
-
foreach (
|
|
51
|
-
string assetGuid in AssetDatabase.FindAssets(
|
|
52
|
-
"t:texture2D",
|
|
53
|
-
texturePaths.ToArray()
|
|
54
|
-
)
|
|
55
|
-
)
|
|
56
|
-
{
|
|
57
|
-
string path = AssetDatabase.GUIDToAssetPath(assetGuid);
|
|
58
|
-
if (string.IsNullOrWhiteSpace(path))
|
|
59
|
-
{
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
Texture2D texture = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
|
|
64
|
-
if (texture != null)
|
|
65
|
-
{
|
|
66
|
-
textures.Add(texture);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
textures = textures.Distinct().OrderBy(texture => texture.name).ToList();
|
|
72
|
-
if (textures.Count <= 0)
|
|
73
|
-
{
|
|
74
|
-
this.Log($"Failed to find any texture paths.");
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
int changedCount = 0;
|
|
79
|
-
foreach (Texture2D texture in textures)
|
|
80
|
-
{
|
|
81
|
-
string assetPath = AssetDatabase.GetAssetPath(texture);
|
|
82
|
-
if (string.IsNullOrWhiteSpace(assetPath))
|
|
83
|
-
{
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
TextureImporter textureImporter =
|
|
88
|
-
AssetImporter.GetAtPath(assetPath) as TextureImporter;
|
|
89
|
-
if (textureImporter == null)
|
|
90
|
-
{
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
textureImporter.GetSourceTextureWidthAndHeight(out int width, out int height);
|
|
94
|
-
|
|
95
|
-
float size = Mathf.Max(width, height);
|
|
96
|
-
int textureSize = textureImporter.maxTextureSize;
|
|
97
|
-
int originalTextureSize = textureSize;
|
|
98
|
-
bool changed = false;
|
|
99
|
-
if (fitMode is FitMode.GrowAndShrink or FitMode.GrowOnly)
|
|
100
|
-
{
|
|
101
|
-
while (textureSize < size)
|
|
102
|
-
{
|
|
103
|
-
changed = true;
|
|
104
|
-
textureSize <<= 1;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (fitMode is FitMode.GrowAndShrink or FitMode.ShrinkOnly)
|
|
109
|
-
{
|
|
110
|
-
while (0 < textureSize && size <= (textureSize >> 1))
|
|
111
|
-
{
|
|
112
|
-
changed = true;
|
|
113
|
-
textureSize >>= 1;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
textureImporter.maxTextureSize = textureSize;
|
|
118
|
-
|
|
119
|
-
if (changed)
|
|
120
|
-
{
|
|
121
|
-
++changedCount;
|
|
122
|
-
textureImporter.SaveAndReimport();
|
|
123
|
-
if (textureImporter.maxTextureSize != textureSize)
|
|
124
|
-
{
|
|
125
|
-
this.LogError(
|
|
126
|
-
$"Failed to update {texture.name}, need texture size {textureSize} but got {textureImporter.maxTextureSize}. Path: '{assetPath}'."
|
|
127
|
-
);
|
|
128
|
-
if (originalTextureSize != textureImporter.maxTextureSize)
|
|
129
|
-
{
|
|
130
|
-
--changedCount;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (changedCount != 0)
|
|
137
|
-
{
|
|
138
|
-
this.Log($"Updated {changedCount} textures.");
|
|
139
|
-
AssetDatabase.Refresh();
|
|
140
|
-
}
|
|
141
|
-
else
|
|
142
|
-
{
|
|
143
|
-
this.Log($"No textures updated.");
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
namespace WallstopStudios.UnityHelpers.Editor
|
|
2
|
-
{
|
|
3
|
-
#if UNITY_EDITOR
|
|
4
|
-
using System;
|
|
5
|
-
using System.Collections;
|
|
6
|
-
using System.Collections.Generic;
|
|
7
|
-
using System.Linq;
|
|
8
|
-
using System.Reflection;
|
|
9
|
-
using UnityEditor;
|
|
10
|
-
using UnityEngine;
|
|
11
|
-
using Core.Attributes;
|
|
12
|
-
using Core.Extension;
|
|
13
|
-
using Core.Helper;
|
|
14
|
-
using WallstopStudios.UnityHelpers.Utils;
|
|
15
|
-
using Object = UnityEngine.Object;
|
|
16
|
-
|
|
17
|
-
public sealed class PrefabCheckWizard : ScriptableWizard
|
|
18
|
-
{
|
|
19
|
-
private static readonly Dictionary<Type, List<FieldInfo>> FieldsByType = new();
|
|
20
|
-
|
|
21
|
-
[Tooltip(
|
|
22
|
-
"Drag a folder from Unity here to validate all prefabs under it. Defaults to Assets/Prefabs and Assets/Resources if none specified."
|
|
23
|
-
)]
|
|
24
|
-
public List<Object> assetPaths = new();
|
|
25
|
-
|
|
26
|
-
[MenuItem("Tools/Unity Helpers/Prefab Check Wizard", priority = -1)]
|
|
27
|
-
public static void CreatePrefabCheckWizard()
|
|
28
|
-
{
|
|
29
|
-
_ = DisplayWizard<PrefabCheckWizard>("Prefab sanity check", "Run");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private void OnWizardCreate()
|
|
33
|
-
{
|
|
34
|
-
List<string> parsedAssetPaths;
|
|
35
|
-
if (assetPaths is { Count: > 0 })
|
|
36
|
-
{
|
|
37
|
-
parsedAssetPaths = assetPaths
|
|
38
|
-
.Where(Objects.NotNull)
|
|
39
|
-
.Select(AssetDatabase.GetAssetPath)
|
|
40
|
-
.ToList();
|
|
41
|
-
parsedAssetPaths.RemoveAll(string.IsNullOrEmpty);
|
|
42
|
-
if (parsedAssetPaths.Count <= 0)
|
|
43
|
-
{
|
|
44
|
-
parsedAssetPaths = null;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
else
|
|
48
|
-
{
|
|
49
|
-
parsedAssetPaths = null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
foreach (GameObject prefab in Helpers.EnumeratePrefabs(parsedAssetPaths))
|
|
53
|
-
{
|
|
54
|
-
List<MonoBehaviour> componentBuffer = Buffers<MonoBehaviour>.List;
|
|
55
|
-
prefab.GetComponentsInChildren(true, componentBuffer);
|
|
56
|
-
foreach (MonoBehaviour script in componentBuffer)
|
|
57
|
-
{
|
|
58
|
-
if (!script)
|
|
59
|
-
{
|
|
60
|
-
Type scriptType = script?.GetType();
|
|
61
|
-
if (scriptType == null)
|
|
62
|
-
{
|
|
63
|
-
prefab.LogError($"Detected missing script.");
|
|
64
|
-
}
|
|
65
|
-
else
|
|
66
|
-
{
|
|
67
|
-
prefab.LogError(
|
|
68
|
-
$"Detected missing script for script type {scriptType}."
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
ValidateNoNullsInLists(script);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private static void ValidateNoNullsInLists(Object component)
|
|
80
|
-
{
|
|
81
|
-
foreach (
|
|
82
|
-
FieldInfo field in FieldsByType.GetOrAdd(
|
|
83
|
-
component.GetType(),
|
|
84
|
-
type =>
|
|
85
|
-
type.GetFields(BindingFlags.Instance | BindingFlags.Public)
|
|
86
|
-
.Concat(
|
|
87
|
-
type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
|
|
88
|
-
.Where(field =>
|
|
89
|
-
field.GetCustomAttributes(typeof(SerializeField)).Any()
|
|
90
|
-
|| field
|
|
91
|
-
.GetCustomAttributes(
|
|
92
|
-
typeof(ValidateAssignmentAttribute)
|
|
93
|
-
)
|
|
94
|
-
.Any()
|
|
95
|
-
)
|
|
96
|
-
)
|
|
97
|
-
.Where(field =>
|
|
98
|
-
typeof(IEnumerable).IsAssignableFrom(field.FieldType)
|
|
99
|
-
|| field.FieldType.IsArray
|
|
100
|
-
)
|
|
101
|
-
.Where(field => !typeof(Transform).IsAssignableFrom(field.FieldType))
|
|
102
|
-
.Where(field => !typeof(Object).IsAssignableFrom(field.FieldType))
|
|
103
|
-
.ToList()
|
|
104
|
-
)
|
|
105
|
-
)
|
|
106
|
-
{
|
|
107
|
-
object fieldValue = field.GetValue(component);
|
|
108
|
-
|
|
109
|
-
if (field.FieldType.IsArray)
|
|
110
|
-
{
|
|
111
|
-
if (fieldValue == null)
|
|
112
|
-
{
|
|
113
|
-
component.LogError($"Field {field.Name} (array) was null.");
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
Array array = (Array)fieldValue;
|
|
118
|
-
foreach (object thing in array)
|
|
119
|
-
{
|
|
120
|
-
bool nullElement = LogIfNull(thing);
|
|
121
|
-
if (nullElement)
|
|
122
|
-
{
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (fieldValue is not IEnumerable list)
|
|
131
|
-
{
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
int position = 0;
|
|
136
|
-
foreach (object thing in list)
|
|
137
|
-
{
|
|
138
|
-
_ = LogIfNull(thing, position++);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
continue;
|
|
142
|
-
|
|
143
|
-
bool LogIfNull(object thing, int? elementIndex = null)
|
|
144
|
-
{
|
|
145
|
-
if (thing == null || (thing is Object unityThing && !unityThing))
|
|
146
|
-
{
|
|
147
|
-
if (elementIndex == null)
|
|
148
|
-
{
|
|
149
|
-
component.LogError($"Field {field.Name} has a null element in it.");
|
|
150
|
-
}
|
|
151
|
-
else
|
|
152
|
-
{
|
|
153
|
-
component.LogError(
|
|
154
|
-
$"Field {field.Name} has a null element at position {elementIndex}."
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
#endif
|
|
167
|
-
}
|
|
File without changes
|
|
File without changes
|