From dc2bddd883bc07e6d26bad0ce34ab6fc7440879e Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 10 Feb 2022 17:04:52 +0100 Subject: [PATCH] [unity] Fixed import issue when suitable atlas found in multiple directories, wrong one could be assigned if named identically. Closes #2033. --- .../Editor/Utility/AssetUtility.cs | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs index 0d1944f96..f7d260373 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs @@ -206,6 +206,14 @@ namespace Spine.Unity.Editor { binary = null; } + internal static AtlasAssetBase GetMatchingAtlas (List requiredPaths, string skeletonName, + List atlasAssets) { + atlasAssets.Sort((a, b) => ( + string.CompareOrdinal(b.name, skeletonName) + - string.CompareOrdinal(a.name, skeletonName))); + return GetMatchingAtlas(requiredPaths, atlasAssets); + } + internal static AtlasAssetBase GetMatchingAtlas (List requiredPaths, List atlasAssets) { AtlasAssetBase atlasAssetMatch = null; @@ -353,13 +361,30 @@ namespace Spine.Unity.Editor { IngestSpineProject(loadedAsset, null); #else string skeletonName = Path.GetFileNameWithoutExtension(skeletonPath); - var atlasesForSkeleton = FindAtlasesAtPath(dir); + List requiredPaths = GetRequiredAtlasRegions(skeletonPath); + + List atlasesForSkeleton = FindAtlasesAtPath(dir); atlasesForSkeleton = atlasesForSkeleton.Union(newAtlases).ToList(); - var requiredPaths = GetRequiredAtlasRegions(skeletonPath); - atlasesForSkeleton.Sort((a, b) => ( - string.CompareOrdinal(b.name, skeletonName) - - string.CompareOrdinal(a.name, skeletonName))); - var atlasMatch = GetMatchingAtlas(requiredPaths, atlasesForSkeleton); + List atlasesInSameDir = atlasesForSkeleton.Where( + atlas => AssetDatabase.GetAssetPath(atlas).Contains(dir)).ToList(); + + AtlasAssetBase atlasMatch = GetMatchingAtlas(requiredPaths, skeletonName, atlasesInSameDir); + if (atlasMatch == null && atlasesInSameDir.Count > 0) { + AtlasAssetBase firstAtlas = atlasesInSameDir[0]; + Debug.LogWarning(string.Format( + "'{0}' atlas found in skeleton directory does not contain all required attachments", + firstAtlas.name), firstAtlas); + + List atlasesInOtherDir = atlasesForSkeleton.Except(atlasesInSameDir).ToList(); + atlasMatch = GetMatchingAtlas(requiredPaths, skeletonName, atlasesInOtherDir); + if (atlasMatch != null) { + Debug.Log(string.Format( + "Using suitable atlas '{0}' of other imported directory. If this is the " + + "wrong atlas asset, please assign the correct one at the SkeletonData asset.", + atlasMatch.name), atlasMatch); + } + } + if (atlasMatch != null || requiredPaths.Count == 0) { IngestSpineProject(loadedAsset, atlasMatch); } else {