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 d5b3a48e8..924cc3850 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 @@ -956,7 +956,8 @@ namespace Spine.Unity.Editor { skeletonDataAsset.Clear(); } var skeletonData = skeletonDataAsset.GetSkeletonData(true); - BlendModeMaterialsUtility.UpdateBlendModeMaterials(skeletonDataAsset, ref skeletonData); + if (skeletonData != null) + BlendModeMaterialsUtility.UpdateBlendModeMaterials(skeletonDataAsset, ref skeletonData); AssetDatabase.SaveAssets(); return skeletonDataAsset; @@ -1006,9 +1007,9 @@ namespace Spine.Unity.Editor { ); switch (result) { - case -1: - //Debug.Log("Select Atlas"); - AtlasAssetBase selectedAtlas = BrowseAtlasDialog(Path.GetDirectoryName(skeletonPath).Replace('\\', '/')); + case -1: { // Select Atlas + string pathForwardSlash = Path.GetDirectoryName(skeletonPath).Replace('\\', '/'); + AtlasAssetBase selectedAtlas = BrowseAtlasDialog(pathForwardSlash, localAtlases); if (selectedAtlas != null) { localAtlases.Clear(); localAtlases.Add(selectedAtlas); @@ -1019,14 +1020,17 @@ namespace Spine.Unity.Editor { } } break; - case 0: // Resolve AtlasAssets... - var atlasList = MultiAtlasDialog(requiredPaths, Path.GetDirectoryName(skeletonPath).Replace('\\', '/'), - Path.GetFileNameWithoutExtension(skeletonPath)); + } + case 0: { // Resolve AtlasAssets... + string pathForwardSlash = Path.GetDirectoryName(skeletonPath).Replace('\\', '/'); + var atlasList = MultiAtlasDialog(requiredPaths, pathForwardSlash, + localAtlases, filename); if (atlasList != null) AssetUtility.IngestSpineProject(AssetDatabase.LoadAssetAtPath(skeletonPath), atlasList.ToArray()); resolved = true; break; + } case 1: // Import without atlas Debug.LogWarning("Imported with missing atlases. Skeleton will not render: " + Path.GetFileName(skeletonPath)); AssetUtility.IngestSpineProject(AssetDatabase.LoadAssetAtPath(skeletonPath), new AtlasAssetBase[] { }); @@ -1040,7 +1044,9 @@ namespace Spine.Unity.Editor { } } - public static List MultiAtlasDialog (List requiredPaths, string initialDirectory, string filename = "") { + public static List MultiAtlasDialog (List requiredPaths, string initialDirectory, + List localAtlases, string filename = "") { + List atlasAssets = new List(); bool resolved = false; string lastAtlasPath = initialDirectory; @@ -1095,7 +1101,7 @@ namespace Spine.Unity.Editor { switch (result) { case 0: // Browse... - AtlasAssetBase selectedAtlasAsset = BrowseAtlasDialog(lastAtlasPath); + AtlasAssetBase selectedAtlasAsset = BrowseAtlasDialog(lastAtlasPath, localAtlases); if (selectedAtlasAsset != null) { if (!atlasAssets.Contains(selectedAtlasAsset)) { var atlas = selectedAtlasAsset.GetAtlas(); @@ -1123,7 +1129,7 @@ namespace Spine.Unity.Editor { return atlasAssets; } - public static AtlasAssetBase BrowseAtlasDialog (string dirPath) { + public static AtlasAssetBase BrowseAtlasDialog (string dirPath, List localAtlases) { string path = EditorUtility.OpenFilePanel("Select AtlasAsset...", dirPath, "asset"); if (path == "") return null; // Canceled or closed by user. @@ -1131,12 +1137,20 @@ namespace Spine.Unity.Editor { int subLen = Application.dataPath.Length - 6; string assetRelativePath = path.Substring(subLen, path.Length - subLen).Replace("\\", "/"); - var obj = AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(AtlasAssetBase)); + UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(AtlasAssetBase)); + if (obj == null) { + // atlas assets that were just created fail to load, search localAtlases + foreach (AtlasAssetBase localAtlas in localAtlases) { + string newAtlasPath = AssetDatabase.GetAssetPath(localAtlas); + if (newAtlasPath == assetRelativePath) + return localAtlas; + } + } + if (obj == null || !(obj is AtlasAssetBase)) { Debug.Log("Chosen asset was not of type AtlasAssetBase"); return null; } - return (AtlasAssetBase)obj; } #endregion