From ec539646036859cf49fad7c5c402f7a7a7af778e Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 18 Mar 2022 15:43:51 +0100 Subject: [PATCH 1/3] [unity] Hopefully fixed some occurrances of a build crash when building many prefabs and textures. See #2047. --- .../Editor/Utility/SpineBuildProcessor.cs | 101 +++++++++++------- .../Asset Types/SpineAtlasAsset.cs | 5 + .../Components/SkeletonAnimation.cs | 4 + .../spine-unity/Components/SkeletonGraphic.cs | 12 ++- .../spine-unity/Components/SkeletonMecanim.cs | 10 +- .../Components/SkeletonRenderer.cs | 5 +- .../spine-unity/Utility/BuildUtilities.cs | 42 ++++++++ .../Utility/BuildUtilities.cs.meta | 11 ++ 8 files changed, 140 insertions(+), 50 deletions(-) create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Utility/BuildUtilities.cs create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Utility/BuildUtilities.cs.meta 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 b42b45f88..6b994b4cd 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 @@ -71,62 +71,83 @@ 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 prefabGameObject = AssetDatabase.LoadAssetAtPath(assetPath); - if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) { - prefabsToRestore.Add(assetPath); + BuildUtilities.IsInSkeletonAssetBuildPreProcessing = true; + try { + AssetDatabase.StartAssetEditing(); + prefabsToRestore.Clear(); + var prefabAssets = AssetDatabase.FindAssets("t:Prefab"); + foreach (var asset in prefabAssets) { + string assetPath = AssetDatabase.GUIDToAssetPath(asset); + GameObject prefabGameObject = AssetDatabase.LoadAssetAtPath(assetPath); + if (SpineEditorUtilities.CleanupSpinePrefabMesh(prefabGameObject)) { + prefabsToRestore.Add(assetPath); + } + EditorUtility.UnloadUnusedAssetsImmediate(); } - EditorUtility.UnloadUnusedAssetsImmediate(); + AssetDatabase.StopAssetEditing(); + if (prefabAssets.Length > 0) + AssetDatabase.SaveAssets(); + } finally { + BuildUtilities.IsInSkeletonAssetBuildPreProcessing = false; } - AssetDatabase.StopAssetEditing(); - if (prefabAssets.Length > 0) - AssetDatabase.SaveAssets(); } internal static void PostprocessSpinePrefabMeshes () { - foreach (string assetPath in prefabsToRestore) { - GameObject g = AssetDatabase.LoadAssetAtPath(assetPath); - SpineEditorUtilities.SetupSpinePrefabMesh(g, null); + BuildUtilities.IsInSkeletonAssetBuildPostProcessing = true; + try { + foreach (string assetPath in prefabsToRestore) { + GameObject g = AssetDatabase.LoadAssetAtPath(assetPath); + SpineEditorUtilities.SetupSpinePrefabMesh(g, null); + } + if (prefabsToRestore.Count > 0) + AssetDatabase.SaveAssets(); + prefabsToRestore.Clear(); + + } finally { + BuildUtilities.IsInSkeletonAssetBuildPostProcessing = false; } - if (prefabsToRestore.Count > 0) - AssetDatabase.SaveAssets(); - prefabsToRestore.Clear(); } #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] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture); - atlasAsset.materials[0].mainTexture = null; + BuildUtilities.IsInSpriteAtlasBuildPreProcessing = true; + try { + 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] = AssetDatabase.GetAssetPath(atlasAsset.materials[0].mainTexture); + atlasAsset.materials[0].mainTexture = null; + } + EditorUtility.UnloadUnusedAssetsImmediate(); } - EditorUtility.UnloadUnusedAssetsImmediate(); + AssetDatabase.StopAssetEditing(); + if (spriteAtlasAssets.Length > 0) + AssetDatabase.SaveAssets(); + } finally { + BuildUtilities.IsInSpriteAtlasBuildPreProcessing = false; } - AssetDatabase.StopAssetEditing(); - if (spriteAtlasAssets.Length > 0) - AssetDatabase.SaveAssets(); } internal static void PostprocessSpriteAtlases () { - foreach (var pair in spriteAtlasTexturesToRestore) { - string assetPath = pair.Key; - SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath(assetPath); - if (atlasAsset && atlasAsset.materials.Length > 0) { - Texture atlasTexture = AssetDatabase.LoadAssetAtPath(pair.Value); - atlasAsset.materials[0].mainTexture = atlasTexture; + BuildUtilities.IsInSpriteAtlasBuildPostProcessing = true; + try { + foreach (var pair in spriteAtlasTexturesToRestore) { + string assetPath = pair.Key; + SpineSpriteAtlasAsset atlasAsset = AssetDatabase.LoadAssetAtPath(assetPath); + if (atlasAsset && atlasAsset.materials.Length > 0) { + Texture atlasTexture = AssetDatabase.LoadAssetAtPath(pair.Value); + atlasAsset.materials[0].mainTexture = atlasTexture; + } } + if (spriteAtlasTexturesToRestore.Count > 0) + AssetDatabase.SaveAssets(); + spriteAtlasTexturesToRestore.Clear(); + } finally { + BuildUtilities.IsInSpriteAtlasBuildPostProcessing = false; } - if (spriteAtlasTexturesToRestore.Count > 0) - AssetDatabase.SaveAssets(); - spriteAtlasTexturesToRestore.Clear(); } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs index 41354b957..6afda5aba 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs @@ -238,6 +238,11 @@ namespace Spine.Unity { } public void Load (AtlasPage page, string path) { +#if UNITY_EDITOR + if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing || + BuildUtilities.IsInSkeletonAssetBuildPostProcessing) + return; +#endif String name = Path.GetFileNameWithoutExtension(path); Material material = null; foreach (Material other in atlasAsset.materials) { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs index e60746008..54467ea67 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs @@ -166,6 +166,10 @@ namespace Spine.Unity { public override void Initialize (bool overwrite, bool quiet = false) { if (valid && !overwrite) return; +#if UNITY_EDITOR + if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing) + return; +#endif base.Initialize(overwrite, quiet); if (!valid) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs index e796cd3de..96f35d3a2 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -102,7 +102,7 @@ namespace Spine.Unity { #if UNITY_EDITOR protected override void OnValidate () { // This handles Scene View preview. - base.OnValidate (); + base.OnValidate(); if (this.IsValid) { if (skeletonDataAsset == null) { Clear(); @@ -360,8 +360,7 @@ namespace Spine.Unity { separatorSlots.Add(slot); } #if UNITY_EDITOR - else - { + else { Debug.LogWarning(slotName + " is not a slot in " + skeletonDataAsset.skeletonJSON.name); } #endif @@ -521,7 +520,10 @@ namespace Spine.Unity { public void Initialize (bool overwrite) { if (this.IsValid && !overwrite) return; - +#if UNITY_EDITOR + if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing) + return; +#endif if (this.skeletonDataAsset == null) return; var skeletonData = this.skeletonDataAsset.GetSkeletonData(false); if (skeletonData == null) return; @@ -839,7 +841,7 @@ namespace Spine.Unity { #if UNITY_EDITOR if (Application.isEditor && !Application.isPlaying) { - for (int i = separatorParts.Count-1; i >= 0; --i) { + for (int i = separatorParts.Count - 1; i >= 0; --i) { if (separatorParts[i] == null) { separatorParts.RemoveAt(i); } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs index c32f0fa55..c58d0abc5 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs @@ -72,7 +72,10 @@ namespace Spine.Unity { public override void Initialize (bool overwrite, bool quiet = false) { if (valid && !overwrite) return; - +#if UNITY_EDITOR + if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing) + return; +#endif base.Initialize(overwrite, quiet); if (!valid) @@ -104,8 +107,7 @@ namespace Spine.Unity { if (Application.isPlaying) { translator.Apply(skeleton); - } - else { + } else { if (translatorAnimator != null && translatorAnimator.isInitialized && translatorAnimator.isActiveAndEnabled && translatorAnimator.runtimeAnimatorController != null) { // Note: Rebind is required to prevent warning "Animator is not playing an AnimatorController" with prefabs @@ -535,7 +537,7 @@ namespace Spine.Unity { } #if UNITY_EDITOR - void GetLayerBlendModes() { + void GetLayerBlendModes () { if (layerBlendModes.Length < animator.layerCount) { System.Array.Resize(ref layerBlendModes, animator.layerCount); } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs index 730bd7f67..63617cd79 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs @@ -367,7 +367,10 @@ namespace Spine.Unity { public virtual void Initialize (bool overwrite, bool quiet = false) { if (valid && !overwrite) return; - +#if UNITY_EDITOR + if (BuildUtilities.IsInSkeletonAssetBuildPreProcessing) + return; +#endif // Clear { // Note: do not reset meshFilter.sharedMesh or meshRenderer.sharedMaterial to null, diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/BuildUtilities.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/BuildUtilities.cs new file mode 100644 index 000000000..0d3c1b408 --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/BuildUtilities.cs @@ -0,0 +1,42 @@ +/****************************************************************************** + * Spine Runtimes License Agreement + * Last updated January 1, 2020. Replaces all prior versions. + * + * Copyright (c) 2013-2022, Esoteric Software LLC + * + * Integration of the Spine Runtimes into software or otherwise creating + * derivative works of the Spine Runtimes is permitted under the terms and + * conditions of Section 2 of the Spine Editor License Agreement: + * http://esotericsoftware.com/spine-editor-license + * + * Otherwise, it is permitted to integrate the Spine Runtimes into software + * or otherwise create derivative works of the Spine Runtimes (collectively, + * "Products"), provided that each user of the Products must obtain their own + * Spine Editor license and redistribution of the Products in any form must + * include this license and copyright notice. + * + * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, + * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#if UNITY_EDITOR + +namespace Spine.Unity { + + public static class BuildUtilities { + public static bool IsInSkeletonAssetBuildPreProcessing = false; + public static bool IsInSkeletonAssetBuildPostProcessing = false; + public static bool IsInSpriteAtlasBuildPreProcessing = false; + public static bool IsInSpriteAtlasBuildPostProcessing = false; + } +} + +#endif diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/BuildUtilities.cs.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/BuildUtilities.cs.meta new file mode 100644 index 000000000..074be476c --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/BuildUtilities.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2f1169aaf0063f4da1c2b6033bbc13f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 5365d661b68b608db0459736542ef6a80a3a8fb4 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Mon, 21 Mar 2022 19:26:29 +0100 Subject: [PATCH 2/3] [ts][threejs] Update to latest THREE, fix shader compilation error in THREE 138. --- spine-ts/package-lock.json | 32 +++++++++++----------- spine-ts/spine-threejs/example/index.html | 2 +- spine-ts/spine-threejs/package.json | 4 +-- spine-ts/spine-threejs/src/SkeletonMesh.ts | 6 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/spine-ts/package-lock.json b/spine-ts/package-lock.json index f6c616669..d25c26233 100644 --- a/spine-ts/package-lock.json +++ b/spine-ts/package-lock.json @@ -53,9 +53,9 @@ "dev": true }, "node_modules/@types/three": { - "version": "0.133.1", - "resolved": "https://registry.npmjs.org/@types/three/-/three-0.133.1.tgz", - "integrity": "sha512-XqBrP/+kbs+o0CYRhCVVE95v7FaL2bO5Z7+3VQJE0nEyjo+9LoLfeNgZITOnndKHxM+7ltEciAIR7uE0SZlsOg==" + "version": "0.138.0", + "resolved": "https://registry.npmjs.org/@types/three/-/three-0.138.0.tgz", + "integrity": "sha512-D8AoV7h2kbCfrv/DcebHOFh1WDwyus3HdooBkAwcBikXArdqnsQ38PQ85JCunnvun160oA9jz53GszF3zch3tg==" }, "node_modules/accepts": { "version": "1.3.8", @@ -7553,9 +7553,9 @@ } }, "node_modules/three": { - "version": "0.133.1", - "resolved": "https://registry.npmjs.org/three/-/three-0.133.1.tgz", - "integrity": "sha512-WydohO8ll949B0FTD6MGz59Yv2Lwj8hvObg/0Heh2r42S6+tQC1WByfCNRdmG4D7+odfGod+n8JPV1I2xrboWw==" + "version": "0.138.3", + "resolved": "https://registry.npmjs.org/three/-/three-0.138.3.tgz", + "integrity": "sha512-4t1cKC8gimNyJChJbaklg8W/qj3PpsLJUIFm5LIuAy/hVxxNm1ru2FGTSfbTSsuHmC/7ipsyuGKqrSAKLNtkzg==" }, "node_modules/through": { "version": "2.3.8", @@ -7976,8 +7976,8 @@ "license": "LicenseRef-LICENSE", "dependencies": { "@esotericsoftware/spine-core": "^4.0.24", - "@types/three": "^0.133.1", - "three": "^0.133.1" + "@types/three": "^0.138.0", + "three": "^0.138.3" } }, "spine-webgl": { @@ -8009,8 +8009,8 @@ "version": "file:spine-threejs", "requires": { "@esotericsoftware/spine-core": "^4.0.24", - "@types/three": "^0.133.1", - "three": "^0.133.1" + "@types/three": "^0.138.0", + "three": "^0.138.3" } }, "@esotericsoftware/spine-webgl": { @@ -8026,9 +8026,9 @@ "dev": true }, "@types/three": { - "version": "0.133.1", - "resolved": "https://registry.npmjs.org/@types/three/-/three-0.133.1.tgz", - "integrity": "sha512-XqBrP/+kbs+o0CYRhCVVE95v7FaL2bO5Z7+3VQJE0nEyjo+9LoLfeNgZITOnndKHxM+7ltEciAIR7uE0SZlsOg==" + "version": "0.138.0", + "resolved": "https://registry.npmjs.org/@types/three/-/three-0.138.0.tgz", + "integrity": "sha512-D8AoV7h2kbCfrv/DcebHOFh1WDwyus3HdooBkAwcBikXArdqnsQ38PQ85JCunnvun160oA9jz53GszF3zch3tg==" }, "accepts": { "version": "1.3.8", @@ -13938,9 +13938,9 @@ } }, "three": { - "version": "0.133.1", - "resolved": "https://registry.npmjs.org/three/-/three-0.133.1.tgz", - "integrity": "sha512-WydohO8ll949B0FTD6MGz59Yv2Lwj8hvObg/0Heh2r42S6+tQC1WByfCNRdmG4D7+odfGod+n8JPV1I2xrboWw==" + "version": "0.138.3", + "resolved": "https://registry.npmjs.org/three/-/three-0.138.3.tgz", + "integrity": "sha512-4t1cKC8gimNyJChJbaklg8W/qj3PpsLJUIFm5LIuAy/hVxxNm1ru2FGTSfbTSsuHmC/7ipsyuGKqrSAKLNtkzg==" }, "through": { "version": "2.3.8", diff --git a/spine-ts/spine-threejs/example/index.html b/spine-ts/spine-threejs/example/index.html index fdeda06d3..f63dd8ac3 100644 --- a/spine-ts/spine-threejs/example/index.html +++ b/spine-ts/spine-threejs/example/index.html @@ -3,7 +3,7 @@ spine-threejs - +