From 042a6dfd1d4c366864cb78c649e312c70b57393c Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 11 Jan 2023 21:26:01 +0100 Subject: [PATCH] [unity] Fixed SpineBuildProcessor potentially trying to modifying a readonly prefab asset. Closes #2223. --- .../spine-unity/Editor/Utility/AssetUtility.cs | 15 +++++++++++++++ .../Editor/Utility/SpineBuildProcessor.cs | 4 ++++ 2 files changed, 19 insertions(+) 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 2904bbdb2..6955c2ccb 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 @@ -51,6 +51,10 @@ #define PROBLEMATIC_PACKAGE_ASSET_MODIFICATION #endif +#if UNITY_2017_3_OR_NEWER +#define HAS_PACKAGE_INFO +#endif + using System.Collections.Generic; using System.IO; using System.Linq; @@ -114,6 +118,17 @@ namespace Spine.Unity.Editor { } } + public static bool AssetCanBeModified (string assetPath) { +#if HAS_PACKAGE_INFO + UnityEditor.PackageManager.PackageInfo packageInfo = UnityEditor.PackageManager.PackageInfo.FindForAssetPath(assetPath); + return (packageInfo == null || + packageInfo.source == UnityEditor.PackageManager.PackageSource.Embedded || + packageInfo.source == UnityEditor.PackageManager.PackageSource.Local); +#else + return assetPath.StartsWith("Assets"); +#endif + } + #region Match SkeletonData with Atlases static readonly AttachmentType[] AtlasTypes = { AttachmentType.Region, AttachmentType.Linkedmesh, AttachmentType.Mesh }; 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 2ec196184..16d60d47f 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 @@ -91,6 +91,8 @@ namespace Spine.Unity.Editor { string[] prefabAssets = AssetDatabase.FindAssets("t:Prefab"); foreach (string asset in prefabAssets) { string assetPath = AssetDatabase.GUIDToAssetPath(asset); + if (!AssetUtility.AssetCanBeModified(assetPath)) continue; + GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath(assetPath); if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) { #if HAS_SAVE_ASSET_IF_DIRTY @@ -139,6 +141,8 @@ namespace Spine.Unity.Editor { string[] spriteAtlasAssets = AssetDatabase.FindAssets("t:SpineSpriteAtlasAsset"); foreach (string asset in spriteAtlasAssets) { string assetPath = AssetDatabase.GUIDToAssetPath(asset); + if (!AssetUtility.AssetCanBeModified(assetPath)) continue; + SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath(assetPath); if (atlasAsset && atlasAsset.materials.Length > 0) { spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture);