diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs index 611cb993b..a7161872a 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineBuildProcessor.cs @@ -51,7 +51,7 @@ namespace Spine.Unity.Editor { #if HAS_ON_POSTPROCESS_PREFAB static List prefabsToRestore = new List(); #endif - static Dictionary spriteAtlasTexturesToRestore = new Dictionary(); + static Dictionary spriteAtlasTexturesToRestore = new Dictionary(); internal static void PreprocessBuild () { isBuilding = true; @@ -71,19 +71,24 @@ namespace Spine.Unity.Editor { #if HAS_ON_POSTPROCESS_PREFAB internal static void PreprocessSpinePrefabMeshes () { + AssetDatabase.StartAssetEditing(); + prefabsToRestore.Clear(); var prefabAssets = AssetDatabase.FindAssets("t:Prefab"); foreach (var asset in prefabAssets) { string assetPath = AssetDatabase.GUIDToAssetPath(asset); - GameObject g = AssetDatabase.LoadAssetAtPath(assetPath); - if (SpineEditorUtilities.CleanupSpinePrefabMesh(g)) { + GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath(assetPath); + if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) { prefabsToRestore.Add(assetPath); } + EditorUtility.UnloadUnusedAssetsImmediate(); } + AssetDatabase.StopAssetEditing(); if (prefabAssets.Length > 0) AssetDatabase.SaveAssets(); } internal static void PostprocessSpinePrefabMeshes () { + Debug.Log("PostprocessSpinePrefabMeshes called"); foreach (string assetPath in prefabsToRestore) { GameObject g = AssetDatabase.LoadAssetAtPath(assetPath); SpineEditorUtilities.SetupSpinePrefabMesh(g, null); @@ -94,15 +99,19 @@ namespace Spine.Unity.Editor { } #endif internal static void PreprocessSpriteAtlases () { + AssetDatabase.StartAssetEditing(); + spriteAtlasTexturesToRestore.Clear(); var spriteAtlasAssets = AssetDatabase.FindAssets("t:SpineSpriteAtlasAsset"); foreach (var asset in spriteAtlasAssets) { string assetPath = AssetDatabase.GUIDToAssetPath(asset); SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath(assetPath); if (atlasAsset && atlasAsset.materials.Length > 0) { - spriteAtlasTexturesToRestore[assetPath] = atlasAsset.materials[0].mainTexture; + spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture); atlasAsset.materials[0].mainTexture = null; } + EditorUtility.UnloadUnusedAssetsImmediate(); } + AssetDatabase.StopAssetEditing(); if (spriteAtlasAssets.Length > 0) AssetDatabase.SaveAssets(); } @@ -112,7 +121,8 @@ namespace Spine.Unity.Editor { string assetPath = pair.Key; SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath(assetPath); if (atlasAsset && atlasAsset.materials.Length > 0) { - atlasAsset.materials[0].mainTexture = pair.Value; + Texture atlasTexture = AssetDatabase.LoadAssetAtPath(pair.Value); + atlasAsset.materials[0].mainTexture = atlasTexture; } } if (spriteAtlasTexturesToRestore.Count > 0) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs index 55fb9331b..d8ebdbf21 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs @@ -108,8 +108,7 @@ namespace Spine.Unity.Editor { SetupSpinePrefabMesh(g, context); } - public static bool SetupSpinePrefabMesh(GameObject g, UnityEditor.AssetImporters.AssetImportContext context) - { + public static bool SetupSpinePrefabMesh (GameObject g, UnityEditor.AssetImporters.AssetImportContext context) { Dictionary nameUsageCount = new Dictionary(); bool wasModified = false; var skeletonRenderers = g.GetComponentsInChildren(true); @@ -124,7 +123,7 @@ namespace Spine.Unity.Editor { renderer.LateUpdateMesh(); var mesh = meshFilter.sharedMesh; if (mesh == null) continue; - + string meshName = string.Format("Skeleton Prefab Mesh \"{0}\"", renderer.name); if (nameUsageCount.ContainsKey(meshName)) { nameUsageCount[meshName]++; @@ -140,8 +139,7 @@ namespace Spine.Unity.Editor { return wasModified; } - public static bool CleanupSpinePrefabMesh(GameObject g) - { + public static bool CleanupSpinePrefabMesh (GameObject g) { bool wasModified = false; var skeletonRenderers = g.GetComponentsInChildren(true); foreach (SkeletonRenderer renderer in skeletonRenderers) {