Quellcode durchsuchen

[unity] Fixed SpineBuildProcessor potentially trying to modifying a readonly prefab asset. Closes #2223.

Harald Csaszar vor 2 Jahren
Ursprung
Commit
042a6dfd1d

+ 15 - 0
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 };
 

+ 4 - 0
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<GameObject>(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<SpineSpriteAtlasAsset>(assetPath);
 					if (atlasAsset && atlasAsset.materials.Length > 0) {
 						spriteAtlasTexturesToRestore[assetPath] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture);