Merge branch '4.0' into 4.1-beta

This commit is contained in:
Harald Csaszar 2022-06-09 18:14:07 +02:00
commit f48e32b70c

View File

@ -36,6 +36,10 @@
#define HAS_ON_POSTPROCESS_PREFAB #define HAS_ON_POSTPROCESS_PREFAB
#endif #endif
#if UNITY_2020_3_OR_NEWER
#define HAS_SAVE_ASSET_IF_DIRTY
#endif
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEditor.Build; using UnityEditor.Build;
@ -80,13 +84,18 @@ namespace Spine.Unity.Editor {
string assetPath = AssetDatabase.GUIDToAssetPath(asset); string assetPath = AssetDatabase.GUIDToAssetPath(asset);
GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath); GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) { if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) {
#if HAS_SAVE_ASSET_IF_DIRTY
AssetDatabase.SaveAssetIfDirty(prefabGameObject);
#endif
prefabsToRestore.Add(assetPath); prefabsToRestore.Add(assetPath);
} }
EditorUtility.UnloadUnusedAssetsImmediate(); EditorUtility.UnloadUnusedAssetsImmediate();
} }
AssetDatabase.StopAssetEditing(); AssetDatabase.StopAssetEditing();
#if !HAS_SAVE_ASSET_IF_DIRTY
if (prefabAssets.Length > 0) if (prefabAssets.Length > 0)
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
#endif
} finally { } finally {
BuildUtilities.IsInSkeletonAssetBuildPreProcessing = false; BuildUtilities.IsInSkeletonAssetBuildPreProcessing = false;
} }
@ -98,9 +107,14 @@ namespace Spine.Unity.Editor {
foreach (string assetPath in prefabsToRestore) { foreach (string assetPath in prefabsToRestore) {
GameObject g = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath); GameObject g = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
SpineEditorUtilities.SetupSpinePrefabMesh(g, null); SpineEditorUtilities.SetupSpinePrefabMesh(g, null);
#if HAS_SAVE_ASSET_IF_DIRTY
AssetDatabase.SaveAssetIfDirty(g);
#endif
} }
#if !HAS_SAVE_ASSET_IF_DIRTY
if (prefabsToRestore.Count > 0) if (prefabsToRestore.Count > 0)
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
#endif
prefabsToRestore.Clear(); prefabsToRestore.Clear();
} finally { } finally {
@ -121,11 +135,16 @@ namespace Spine.Unity.Editor {
spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture); spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture);
atlasAsset.materials[0].mainTexture = null; atlasAsset.materials[0].mainTexture = null;
} }
#if HAS_SAVE_ASSET_IF_DIRTY
AssetDatabase.SaveAssetIfDirty(atlasAsset);
#endif
EditorUtility.UnloadUnusedAssetsImmediate(); EditorUtility.UnloadUnusedAssetsImmediate();
} }
AssetDatabase.StopAssetEditing(); AssetDatabase.StopAssetEditing();
#if !HAS_SAVE_ASSET_IF_DIRTY
if (spriteAtlasAssets.Length > 0) if (spriteAtlasAssets.Length > 0)
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
#endif
} finally { } finally {
BuildUtilities.IsInSpriteAtlasBuildPreProcessing = false; BuildUtilities.IsInSpriteAtlasBuildPreProcessing = false;
} }
@ -141,9 +160,14 @@ namespace Spine.Unity.Editor {
Texture atlasTexture = AssetDatabase.LoadAssetAtPath<Texture>(pair.Value); Texture atlasTexture = AssetDatabase.LoadAssetAtPath<Texture>(pair.Value);
atlasAsset.materials[0].mainTexture = atlasTexture; atlasAsset.materials[0].mainTexture = atlasTexture;
} }
#if HAS_SAVE_ASSET_IF_DIRTY
AssetDatabase.SaveAssetIfDirty(atlasAsset);
#endif
} }
#if !HAS_SAVE_ASSET_IF_DIRTY
if (spriteAtlasTexturesToRestore.Count > 0) if (spriteAtlasTexturesToRestore.Count > 0)
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
#endif
spriteAtlasTexturesToRestore.Clear(); spriteAtlasTexturesToRestore.Clear();
} finally { } finally {
BuildUtilities.IsInSpriteAtlasBuildPostProcessing = false; BuildUtilities.IsInSpriteAtlasBuildPostProcessing = false;