From be84904181b80a5b43ba14966ca240443f4bc584 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Sat, 2 Jan 2021 18:41:51 -0800 Subject: [PATCH 1/6] Fixed Skeleton Viewer for libgdx TextureAtlas changes. --- .../src/com/esotericsoftware/spine/SkeletonViewer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java index 2b55d006e..c73d638d9 100644 --- a/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java +++ b/spine-libgdx/spine-skeletonviewer/src/com/esotericsoftware/spine/SkeletonViewer.java @@ -178,8 +178,10 @@ public class SkeletonViewer extends ApplicationAdapter { final AtlasRegion fake = new AtlasRegion(new Texture(pixmap), 0, 0, 32, 32); pixmap.dispose(); - TextureAtlasData atlasData = null; - if (atlasFile != null) { + TextureAtlasData atlasData; + if (atlasFile == null) + atlasData = new TextureAtlasData(); + else { atlasData = new TextureAtlasData(atlasFile, atlasFile.parent(), false); boolean linear = true; for (int i = 0, n = atlasData.getPages().size; i < n; i++) { From a7f629f5045960b61a0d7b4bee7271d6ff9dd897 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 7 Jan 2021 16:18:01 +0100 Subject: [PATCH 2/6] [unity] Fixed BoneFollowerGraphic silently failing at Transform instead of RectTransform by requiring component RectTransform. Closes #1828. --- .../spine-unity/Components/Following/BoneFollowerGraphic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollowerGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollowerGraphic.cs index b8336cbf8..54bdb8b7d 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollowerGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoneFollowerGraphic.cs @@ -40,7 +40,7 @@ namespace Spine.Unity { #else [ExecuteInEditMode] #endif - [DisallowMultipleComponent] + [RequireComponent(typeof(RectTransform)), DisallowMultipleComponent] [AddComponentMenu("Spine/UI/BoneFollowerGraphic")] [HelpURL("http://esotericsoftware.com/spine-unity#BoneFollowerGraphic")] public class BoneFollowerGraphic : MonoBehaviour { From ab91a3539df205462b90610678ce194849cf9ea7 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 7 Jan 2021 20:25:01 +0100 Subject: [PATCH 3/6] [unity] Fixed Editor error messages upon startup, most likely due to AssetDatabase not being fully initialized (Unity 2020.2). Closes #1779. --- .../spine-unity/Editor/Utility/SpineEditorUtilities.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 7efdc414b..dccc65417 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 @@ -69,6 +69,7 @@ namespace Spine.Unity.Editor { public static string editorPath = ""; public static string editorGUIPath = ""; public static bool initialized; + private static int numFramesToDelayInit = 1; private static List texturesWithoutMetaFile = new List(); // Auto-import entry point for textures @@ -96,11 +97,16 @@ namespace Spine.Unity.Editor { } #region Initialization + static SpineEditorUtilities () { - Initialize(); + EditorApplication.update += Initialize; // delayed so that AssetDatabase is ready. } static void Initialize () { + if (numFramesToDelayInit-- > 0) + return; + EditorApplication.update -= Initialize; + // Note: Preferences need to be loaded when changing play mode // to initialize handle scale correctly. #if !NEW_PREFERENCES_SETTINGS_PROVIDER From e95e130e9bce6104dabb37c9e02139e8b696af64 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Thu, 7 Jan 2021 20:52:14 +0100 Subject: [PATCH 4/6] [unity] Changed implementation of previous bugfix commit ab91a35 of Editor error messages upon startup. Uses less code and executes a bit earlier. See #1779. --- .../spine-unity/Editor/Utility/SpineEditorUtilities.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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 dccc65417..5c8016b0d 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 @@ -69,7 +69,6 @@ namespace Spine.Unity.Editor { public static string editorPath = ""; public static string editorGUIPath = ""; public static bool initialized; - private static int numFramesToDelayInit = 1; private static List texturesWithoutMetaFile = new List(); // Auto-import entry point for textures @@ -97,16 +96,11 @@ namespace Spine.Unity.Editor { } #region Initialization - static SpineEditorUtilities () { - EditorApplication.update += Initialize; // delayed so that AssetDatabase is ready. + EditorApplication.delayCall += Initialize; // delayed so that AssetDatabase is ready. } static void Initialize () { - if (numFramesToDelayInit-- > 0) - return; - EditorApplication.update -= Initialize; - // Note: Preferences need to be loaded when changing play mode // to initialize handle scale correctly. #if !NEW_PREFERENCES_SETTINGS_PROVIDER From 82a0de85bc8feea2179461eac4d4de8ed259a9a5 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 8 Jan 2021 17:59:18 +0100 Subject: [PATCH 5/6] [unity] Fixed SkeletonGraphic with multiple materials displaying white square and issuing error when number of renderers changes in SkeletonGraphic.Rebuild. Closes #1826. --- .../spine-unity/Components/SkeletonGraphic.cs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) 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 457ba3124..0950505c0 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -72,6 +72,8 @@ namespace Spine.Unity { public bool unscaledTime; public bool allowMultipleCanvasRenderers = false; public List canvasRenderers = new List(); + protected List rawImages = new List(); + protected int usedRenderersCount = 0; // Submesh Separation public const string SeparatorPartGameObjectName = "Part"; @@ -200,6 +202,7 @@ namespace Spine.Unity { protected override void Awake () { base.Awake (); + SyncRawImagesWithCanvasRenderers(); if (!this.IsValid) { #if UNITY_EDITOR // workaround for special import case of open scene where OnValidate and Awake are @@ -217,7 +220,7 @@ namespace Spine.Unity { public override void Rebuild (CanvasUpdate update) { base.Rebuild(update); if (canvasRenderer.cull) return; - if (update == CanvasUpdate.PreRender) UpdateMesh(); + if (update == CanvasUpdate.PreRender) UpdateMesh(keepRendererCount : true); if (allowMultipleCanvasRenderers) canvasRenderer.Clear(); } @@ -253,6 +256,12 @@ namespace Spine.Unity { ApplyAnimation(); } + protected void SyncRawImagesWithCanvasRenderers () { + rawImages.Clear(); + foreach (var canvasRenderer in canvasRenderers) + rawImages.Add(canvasRenderer.GetComponent()); + } + protected void UpdateAnimationStatus (float deltaTime) { deltaTime *= timeScale; skeleton.Update(deltaTime); @@ -264,7 +273,7 @@ namespace Spine.Unity { BeforeApply(this); if (updateMode != UpdateMode.OnlyEventTimelines) - state.Apply(skeleton); + state.Apply(skeleton); else state.ApplyEventTimelinesOnly(skeleton); @@ -452,6 +461,7 @@ namespace Spine.Unity { } } canvasRenderers = newList; + SyncRawImagesWithCanvasRenderers(); } public void Initialize (bool overwrite) { @@ -503,7 +513,7 @@ namespace Spine.Unity { OnRebuild(this); } - public void UpdateMesh () { + public void UpdateMesh (bool keepRendererCount = false) { if (!this.IsValid) return; skeleton.SetColor(this.color); @@ -513,7 +523,7 @@ namespace Spine.Unity { UpdateMeshSingleCanvasRenderer(); } else { - UpdateMeshMultipleCanvasRenderers(currentInstructions); + UpdateMeshMultipleCanvasRenderers(currentInstructions, keepRendererCount); } if (OnMeshAndMaterialsUpdated != null) @@ -574,15 +584,18 @@ namespace Spine.Unity { } //this.UpdateMaterial(); // note: This would allocate memory. + usedRenderersCount = 0; } - protected void UpdateMeshMultipleCanvasRenderers (SkeletonRendererInstruction currentInstructions) { + protected void UpdateMeshMultipleCanvasRenderers (SkeletonRendererInstruction currentInstructions, bool keepRendererCount) { MeshGenerator.GenerateSkeletonRendererInstruction(currentInstructions, skeleton, null, enableSeparatorSlots ? separatorSlots : null, enableSeparatorSlots ? separatorSlots.Count > 0 : false, false); int submeshCount = currentInstructions.submeshInstructions.Count; + if (keepRendererCount && submeshCount != usedRenderersCount) + return; EnsureCanvasRendererCount(submeshCount); EnsureMeshesCount(submeshCount); EnsureSeparatorPartCount(); @@ -618,7 +631,10 @@ namespace Spine.Unity { var submeshMaterial = submeshInstructionItem.material; var canvasRenderer = canvasRenderers[i]; - canvasRenderer.gameObject.SetActive(true); + if (i >= usedRenderersCount) { + canvasRenderer.gameObject.SetActive(true); + rawImages[i].Rebuild(CanvasUpdate.PreRender); + } canvasRenderer.SetMesh(targetMesh); canvasRenderer.materialCount = 1; @@ -647,6 +663,7 @@ namespace Spine.Unity { } DisableUnusedCanvasRenderers(usedCount : submeshCount); + usedRenderersCount = submeshCount; } protected void EnsureCanvasRendererCount (int targetCount) { @@ -663,6 +680,7 @@ namespace Spine.Unity { var rawImage = go.AddComponent(); rawImage.maskable = this.maskable; rawImage.raycastTarget = false; + rawImages.Add(rawImage); } } From 2039efc5b754735b7ac998ad1ea4197b044e5bb0 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 8 Jan 2021 19:28:32 +0100 Subject: [PATCH 6/6] [unity] Fixed a bug introduced in previous commit 82a0de8, was not handling not-yet added RawImage components at additional CanvasRenderers. See #1826. --- .../Runtime/spine-unity/Components/SkeletonGraphic.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 0950505c0..9e4f43f42 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -258,8 +258,15 @@ namespace Spine.Unity { protected void SyncRawImagesWithCanvasRenderers () { rawImages.Clear(); - foreach (var canvasRenderer in canvasRenderers) - rawImages.Add(canvasRenderer.GetComponent()); + foreach (var canvasRenderer in canvasRenderers) { + var rawImage = canvasRenderer.GetComponent(); + if (rawImage == null) { + rawImage = canvasRenderer.gameObject.AddComponent(); + rawImage.maskable = this.maskable; + rawImage.raycastTarget = false; + } + rawImages.Add(rawImage); + } } protected void UpdateAnimationStatus (float deltaTime) {