From 0991deb9dd22b46dc0febedc0ea047940d8fb965 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Fri, 6 Mar 2026 18:16:17 +0100 Subject: [PATCH] [unity] Refactored GetRemappedClone methods. See CHANGELOG.md. Be sure to re-import spine-unity samples. Closes #2072. `attachment.GetRemappedClone(params)` -> `attachment.Copy(); attachment.SetRegion(params).` `ToAtlasRegionPMAClone` -> `ToAtlasRegionWithNewPMATexture` `ToRegionAttachmentPMAClone` -> `ToRegionAttachmentWithNewPMATexture` --- CHANGELOG.md | 4 + .../spine-unity/Utility/AtlasUtilities.cs | 17 +-- .../Utility/AttachmentCloneExtensions.cs | 118 ------------------ .../Utility/AttachmentCloneExtensions.cs.meta | 12 -- .../Utility/AttachmentRegionExtensions.cs | 81 +++++++++++- .../EquipSystemExample.cs | 7 +- .../MixAndMatchSkinsExample.cs | 2 +- .../Spine Examples/Scripts/MixAndMatch.cs | 10 +- .../Scripts/MixAndMatchGraphic.cs | 10 +- .../Legacy/AtlasRegionAttacher.cs | 4 +- .../Legacy/SpriteAttacher.cs | 6 +- spine-unity/Assets/Spine/package.json | 2 +- 12 files changed, 113 insertions(+), 160 deletions(-) delete mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs delete mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index cc044ad8b..7059b3183 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -349,6 +349,10 @@ - When enabling `Threaded Animation` at `SkeletonAnimation` components, `SkeletonAnimation.AnimationState` callbacks and `TrackEntry` callbacks are not automatically called on the main thread. There are additional main thread callbacks provided to subscribe to instead, like `MainThreadComplete` for `Complete` and the like - see *Additions* below. Please note that this requires a change of user code to subscribe to these main thread delegate variants instead. - `SkeletonRenderer`: `maskInteraction` → `MaskInteraction`. - Removed rather useless old menu entries `GameObject - Spine - SkeletonRenderer` and the like which are spawning e.g. a GameObject with an empty `SkeletonRenderer` component without `SkeletonDataAsset` assigned and thus also not initialized properly. + - Removed `attachment.GetRemappedClone()` extension methods. Replace `attachment.GetRemappedClone(parameters)` with `attachment.Copy(); attachment.SetRegion(parameters)`. Removed `AttachmentCloneExtensions` class, `SetRegion` methods are now in `AttachmentRegionExtensions`. + - Renamed `ToAtlasRegionPMAClone` to `ToAtlasRegionWithNewPMATexture`. + - Renamed `ToRegionAttachmentPMAClone` to `ToRegionAttachmentWithNewPMATexture`. + - **Changes of default values** - Changed default atlas texture workflow from PMA to straight alpha textures. This move was done because straight alpha textures are compatible with both Gamma and Linear color space, with the latter being the default for quite some time now in Unity. Note that `PMA Vertex Color` is unaffected and shall be enabled as usual to allow for single-pass additive rendering. diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs index 557c4f38b..5123317b3 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AtlasUtilities.cs @@ -99,13 +99,13 @@ namespace Spine.Unity.AttachmentTools { /// /// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate of the Sprite's texture data. - public static AtlasRegion ToAtlasRegionPMAClone (this Texture2D t, Material materialPropertySource, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) { - return t.ToAtlasRegionPMAClone(materialPropertySource.shader, textureFormat, mipmaps, materialPropertySource); + public static AtlasRegion ToAtlasRegionWithNewPMATexture (this Texture2D t, Material materialPropertySource, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) { + return t.ToAtlasRegionWithNewPMATexture(materialPropertySource.shader, textureFormat, mipmaps, materialPropertySource); } /// /// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate of the Sprite's texture data. - public static AtlasRegion ToAtlasRegionPMAClone (this Texture2D t, Shader shader, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps, Material materialPropertySource = null) { + public static AtlasRegion ToAtlasRegionWithNewPMATexture (this Texture2D t, Shader shader, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps, Material materialPropertySource = null) { Material material = new Material(shader); if (materialPropertySource != null) { material.CopyPropertiesFromMaterial(materialPropertySource); @@ -159,13 +159,13 @@ namespace Spine.Unity.AttachmentTools { return region; } - public static AtlasRegion ToAtlasRegionPMAClone (this Sprite s, Material materialPropertySource, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) { - return s.ToAtlasRegionPMAClone(materialPropertySource.shader, textureFormat, mipmaps, materialPropertySource); + public static AtlasRegion ToAtlasRegionWithNewPMATexture (this Sprite s, Material materialPropertySource, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps) { + return s.ToAtlasRegionWithNewPMATexture(materialPropertySource.shader, textureFormat, mipmaps, materialPropertySource); } /// /// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate of the Sprite's texture data. - public static AtlasRegion ToAtlasRegionPMAClone (this Sprite s, Shader shader, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps, Material materialPropertySource = null) { + public static AtlasRegion ToAtlasRegionWithNewPMATexture (this Sprite s, Shader shader, TextureFormat textureFormat = SpineTextureFormat, bool mipmaps = UseMipMaps, Material materialPropertySource = null) { Material material = new Material(shader); if (materialPropertySource != null) { material.CopyPropertiesFromMaterial(materialPropertySource); @@ -962,14 +962,15 @@ namespace Spine.Unity.AttachmentTools { /// /// Frees up textures cached by repacking and remapping operations. /// - /// Calling with parameter premultiplyAlpha=true, + /// Calling + /// with parameter premultiplyAlpha=true, /// or will cache textures for later re-use, /// which might steadily increase the texture memory footprint when used excessively. /// You can clear this Texture cache by calling . /// You may also want to call Resources.UnloadUnusedAssets() after that. Be aware that while this cleanup /// frees up memory, it is also a costly operation and will likely cause a spike in the framerate. /// Thus it is recommended to perform costly repacking and cleanup operations after e.g. a character customization - /// screen has been exited, and if required additionally after a certain number of GetRemappedClone() calls. + /// screen has been exited, and if required additionally after a certain number of SetRegion() calls. /// public static void ClearCache () { foreach (Texture2D t in CachedRegionTexturesList) { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs deleted file mode 100644 index 180f5d5b9..000000000 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs +++ /dev/null @@ -1,118 +0,0 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated April 5, 2025. Replaces all prior versions. - * - * Copyright (c) 2013-2026, 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. - *****************************************************************************/ - -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace Spine.Unity.AttachmentTools { - - public static class AttachmentCloneExtensions { - - #region RemappedClone Convenience Methods - /// - /// Gets a clone of the attachment remapped with a sprite image. - /// The remapped clone. - /// The original attachment. - /// The sprite whose texture to use. - /// The source material used to copy the shader and material properties from. - /// If true, a premultiply alpha clone of the original texture will be created. - /// See remarks below for additional info. - /// If true MeshAttachments will be cloned as linked meshes and will inherit animation from the original attachment. - /// If true the size of the original attachment will be followed, instead of using the Sprite size. - /// If true and the original Attachment is a MeshAttachment, then - /// a non-central sprite pivot will shift uv coords in the opposite direction. Vertices will not be offset in - /// any case when the original Attachment is a MeshAttachment. - /// If true and the original Attachment is a RegionAttachment, then - /// the original region's scale value is used instead of the Sprite's pixels per unit property. Since uniform scale is used, - /// x scale of the original attachment (width scale) is used, scale in y direction (height scale) is ignored. - /// If premultiplyAlpha is true>, the TextureFormat of the - /// newly created PMA attachment Texture. - /// If premultiplyAlpha is , whether the newly created - /// PMA attachment Texture has mipmaps enabled. - /// When parameter premultiplyAlpha is set to true, a premultiply alpha clone of the - /// original texture will be created. Additionally, this PMA Texture clone is cached for later re-use, - /// which might steadily increase the Texture memory footprint when used excessively. - /// See on how to clear these cached textures. - public static Attachment GetRemappedClone (this Attachment o, Sprite sprite, Material sourceMaterial, - bool premultiplyAlpha = true, bool cloneMeshAsLinked = true, bool useOriginalRegionSize = false, - bool pivotShiftsMeshUVCoords = true, bool useOriginalRegionScale = false, - TextureFormat pmaCloneTextureFormat = AtlasUtilities.SpineTextureFormat, - bool pmaCloneMipmaps = AtlasUtilities.UseMipMaps) { - - AtlasRegion atlasRegion = premultiplyAlpha ? - sprite.ToAtlasRegionPMAClone(sourceMaterial, pmaCloneTextureFormat, pmaCloneMipmaps) : - sprite.ToAtlasRegion(new Material(sourceMaterial) { mainTexture = sprite.texture }); - if (!pivotShiftsMeshUVCoords && o is MeshAttachment) { - // prevent non-central sprite pivot setting offsetX/Y and shifting uv coords out of mesh bounds - atlasRegion.offsetX = 0; - atlasRegion.offsetY = 0; - } - float scale = 1f / sprite.pixelsPerUnit; - if (useOriginalRegionScale) { - RegionAttachment regionAttachment = o as RegionAttachment; - if (regionAttachment != null) - scale = regionAttachment.Width / regionAttachment.Region.OriginalWidth; - } - return o.GetRemappedClone(atlasRegion, cloneMeshAsLinked, useOriginalRegionSize, scale); - } - - /// - /// Gets a clone of the attachment remapped with an atlasRegion image. - /// The remapped clone. - /// The original attachment. - /// Atlas region. - /// If true MeshAttachments will be cloned as linked meshes and will inherit animation from the original attachment. - /// If true the size of the original attachment will be followed, instead of using the Sprite size. - /// Unity units per pixel scale used to scale the atlas region size when not using the original region size. - public static Attachment GetRemappedClone (this Attachment o, AtlasRegion atlasRegion, bool cloneMeshAsLinked = true, bool useOriginalRegionSize = false, float scale = 0.01f) { - RegionAttachment regionAttachment = o as RegionAttachment; - if (regionAttachment != null) { - RegionAttachment newAttachment = (RegionAttachment)regionAttachment.Copy(); - newAttachment.Region = atlasRegion; - if (!useOriginalRegionSize) { - newAttachment.Width = atlasRegion.width * scale; - newAttachment.Height = atlasRegion.height * scale; - } - newAttachment.UpdateRegion(); - return newAttachment; - } else { - MeshAttachment meshAttachment = o as MeshAttachment; - if (meshAttachment != null) { - MeshAttachment newAttachment = cloneMeshAsLinked ? meshAttachment.NewLinkedMesh() : (MeshAttachment)meshAttachment.Copy(); - newAttachment.Region = atlasRegion; - newAttachment.UpdateRegion(); - return newAttachment; - } - } - return o.Copy(); - } - #endregion - } -} diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs.meta deleted file mode 100644 index 4d6580e62..000000000 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentCloneExtensions.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 3431ed563b2c62f4c8c974a99365ba52 -timeCreated: 1563321428 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentRegionExtensions.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentRegionExtensions.cs index b61d8a921..b86bfb8f3 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentRegionExtensions.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/AttachmentRegionExtensions.cs @@ -54,17 +54,17 @@ namespace Spine.Unity.AttachmentTools { /// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate texture of the Sprite's texture data. /// Returns a RegionAttachment that uses it. Use this if you plan to use a premultiply alpha shader such as "Spine/Skeleton". /// The duplicate texture is cached for later re-use. See documentation of - /// for additional details. - public static RegionAttachment ToRegionAttachmentPMAClone (this Sprite sprite, Shader shader, TextureFormat textureFormat = AtlasUtilities.SpineTextureFormat, bool mipmaps = AtlasUtilities.UseMipMaps, Material materialPropertySource = null, float rotation = 0f) { + /// for additional details. + public static RegionAttachment ToRegionAttachmentWithNewPMATexture (this Sprite sprite, Shader shader, TextureFormat textureFormat = AtlasUtilities.SpineTextureFormat, bool mipmaps = AtlasUtilities.UseMipMaps, Material materialPropertySource = null, float rotation = 0f) { if (sprite == null) throw new System.ArgumentNullException("sprite"); if (shader == null) throw new System.ArgumentNullException("shader"); - AtlasRegion region = sprite.ToAtlasRegionPMAClone(shader, textureFormat, mipmaps, materialPropertySource); + AtlasRegion region = sprite.ToAtlasRegionWithNewPMATexture(shader, textureFormat, mipmaps, materialPropertySource); float unitsPerPixel = 1f / sprite.pixelsPerUnit; return region.ToRegionAttachment(sprite.name, unitsPerPixel, rotation); } - public static RegionAttachment ToRegionAttachmentPMAClone (this Sprite sprite, Material materialPropertySource, TextureFormat textureFormat = AtlasUtilities.SpineTextureFormat, bool mipmaps = AtlasUtilities.UseMipMaps, float rotation = 0f) { - return sprite.ToRegionAttachmentPMAClone(materialPropertySource.shader, textureFormat, mipmaps, materialPropertySource, rotation); + public static RegionAttachment ToRegionAttachmentWithNewPMATexture (this Sprite sprite, Material materialPropertySource, TextureFormat textureFormat = AtlasUtilities.SpineTextureFormat, bool mipmaps = AtlasUtilities.UseMipMaps, float rotation = 0f) { + return sprite.ToRegionAttachmentWithNewPMATexture(materialPropertySource.shader, textureFormat, mipmaps, materialPropertySource, rotation); } /// @@ -125,5 +125,76 @@ namespace Spine.Unity.AttachmentTools { regionAttachment.Rotation = rotation; } #endregion + + #region SetRegion + /// + /// Sets the region of an attachment to match a Sprite image. + /// The attachment to modify. + /// The sprite whose texture to use. + /// The source material used to copy the shader and material properties from. + /// If true, a premultiply alpha duplicate of the original texture will be created. + /// See remarks below for additional info. + /// If true the size of the original attachment will be followed, instead of using the Sprite size. + /// If true and the Attachment is a MeshAttachment, then + /// a non-central sprite pivot will shift uv coords in the opposite direction. Vertices will not be offset in + /// any case when the Attachment is a MeshAttachment. + /// If true and the Attachment is a RegionAttachment, then + /// the original region's scale value is used instead of the Sprite's pixels per unit property. Since uniform scale is used, + /// x scale of the original attachment (width scale) is used, scale in y direction (height scale) is ignored. + /// If premultiplyAlpha is true, the TextureFormat of the + /// newly created PMA attachment Texture. + /// If premultiplyAlpha is true, whether the newly created + /// PMA attachment Texture has mipmaps enabled. + /// When parameter premultiplyAlpha is set to true, a premultiply alpha duplicate of the + /// original texture will be created. Additionally, this PMA Texture duplicate is cached for later re-use, + /// which might steadily increase the Texture memory footprint when used excessively. + /// See on how to clear these cached textures. + public static void SetRegion (this Attachment attachment, Sprite sprite, Material sourceMaterial, + bool premultiplyAlpha = true, bool useOriginalRegionSize = false, + bool pivotShiftsMeshUVCoords = true, bool useOriginalRegionScale = false, + TextureFormat pmaTextureFormat = AtlasUtilities.SpineTextureFormat, + bool pmaMipmaps = AtlasUtilities.UseMipMaps) { + + AtlasRegion atlasRegion = premultiplyAlpha ? + sprite.ToAtlasRegionWithNewPMATexture(sourceMaterial, pmaTextureFormat, pmaMipmaps) : + sprite.ToAtlasRegion(new Material(sourceMaterial) { mainTexture = sprite.texture }); + if (!pivotShiftsMeshUVCoords && attachment is MeshAttachment) { + // prevent non-central sprite pivot setting offsetX/Y and shifting uv coords out of mesh bounds + atlasRegion.offsetX = 0; + atlasRegion.offsetY = 0; + } + float scale = 1f / sprite.pixelsPerUnit; + if (useOriginalRegionScale) { + RegionAttachment regionAttachment = attachment as RegionAttachment; + if (regionAttachment != null) + scale = regionAttachment.Width / regionAttachment.Region.OriginalWidth; + } + attachment.SetRegion(atlasRegion, useOriginalRegionSize, scale); + } + + /// + /// Sets the region of an attachment to use a new AtlasRegion. + /// The attachment to modify. + /// Atlas region. + /// If true the size of the original attachment will be followed, instead of using the atlas region size. + /// Unity units per pixel scale used to scale the atlas region size when not using the original region size. + public static void SetRegion (this Attachment attachment, AtlasRegion atlasRegion, bool useOriginalRegionSize = false, float scale = 0.01f) { + RegionAttachment regionAttachment = attachment as RegionAttachment; + if (regionAttachment != null) { + regionAttachment.Region = atlasRegion; + if (!useOriginalRegionSize) { + regionAttachment.Width = atlasRegion.width * scale; + regionAttachment.Height = atlasRegion.height * scale; + } + regionAttachment.UpdateRegion(); + } else { + MeshAttachment meshAttachment = attachment as MeshAttachment; + if (meshAttachment != null) { + meshAttachment.Region = atlasRegion; + meshAttachment.UpdateRegion(); + } + } + } + #endregion } } diff --git a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Mix and Match Character Customize/EquipSystemExample.cs b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Mix and Match Character Customize/EquipSystemExample.cs index 9fac035b9..3d44d9cb2 100644 --- a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Mix and Match Character Customize/EquipSystemExample.cs +++ b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Mix and Match Character Customize/EquipSystemExample.cs @@ -80,8 +80,9 @@ namespace Spine.Unity.Examples { SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(true); Skin templateSkin = skeletonData.FindSkin(templateSkinName); Attachment templateAttachment = templateSkin.GetAttachment(slotIndex, templateAttachmentName); - attachment = templateAttachment.GetRemappedClone(asset.sprite, sourceMaterial, premultiplyAlpha: this.applyPMA); - // Note: Each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` creates + attachment = templateAttachment.Copy(); + attachment.SetRegion(asset.sprite, sourceMaterial, premultiplyAlpha: this.applyPMA); + // Note: Each call to `SetRegion()` with parameter `premultiplyAlpha` set to `true` creates // a cached Texture copy which can be cleared by calling AtlasUtilities.ClearCache() as shown in the method below. cachedAttachments.Add(asset, attachment); // Cache this value for next time this asset is used. @@ -92,7 +93,7 @@ namespace Spine.Unity.Examples { public void Done () { target.OptimizeSkin(); - // `GetRepackedSkin()` and each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` + // `GetRepackedSkin()` and each call to `SetRegion()` with parameter `premultiplyAlpha` set to `true` // creates cached Texture copies which can be cleared by calling AtlasUtilities.ClearCache(). // You can optionally clear the textures cache after multiple repack operations. // Just be aware that while this cleanup frees up memory, it is also a costly operation diff --git a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Mix and Match Character Customize/MixAndMatchSkinsExample.cs b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Mix and Match Character Customize/MixAndMatchSkinsExample.cs index 3b235d760..0826e64be 100644 --- a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Mix and Match Character Customize/MixAndMatchSkinsExample.cs +++ b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Mix and Match Character Customize/MixAndMatchSkinsExample.cs @@ -155,7 +155,7 @@ namespace Spine.Unity.Examples { skeletonAnimation.Skeleton.SetupPoseSlots(); skeletonAnimation.AnimationState.Apply(skeletonAnimation.Skeleton); - // `GetRepackedSkin()` and each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` + // `GetRepackedSkin()` and each call to `SetRegion()` with parameter `premultiplyAlpha` set to `true` // cache necessarily created Texture copies which can be cleared by calling AtlasUtilities.ClearCache(). // You can optionally clear the textures cache after multiple repack operations. // Just be aware that while this cleanup frees up memory, it is also a costly operation diff --git a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/MixAndMatch.cs b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/MixAndMatch.cs index 543582ca4..eeede690b 100644 --- a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/MixAndMatch.cs +++ b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/MixAndMatch.cs @@ -97,15 +97,17 @@ namespace Spine.Unity.Examples { int visorSlotIndex = skeleton.Data.FindSlot(visorSlot).Index; // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster. Attachment templateAttachment = templateSkin.GetAttachment(visorSlotIndex, visorKey); // STEP 1.1 - // Note: Each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` creates + // Note: Each call to `SetRegion()` with parameter `premultiplyAlpha` set to `true` creates // a cached Texture copy which can be cleared by calling AtlasUtilities.ClearCache() as done in the method below. - Attachment newAttachment = templateAttachment.GetRemappedClone(visorSprite, sourceMaterial, pivotShiftsMeshUVCoords: false); // STEP 1.2 - 1.3 + Attachment newAttachment = templateAttachment.Copy(); // STEP 1.2 + newAttachment.SetRegion(visorSprite, sourceMaterial, pivotShiftsMeshUVCoords: false); // STEP 1.3 customSkin.SetAttachment(visorSlotIndex, visorKey, newAttachment); // STEP 1.4 // And now for the gun. int gunSlotIndex = skeleton.Data.FindSlot(gunSlot).Index; Attachment templateGun = templateSkin.GetAttachment(gunSlotIndex, gunKey); // STEP 1.1 - Attachment newGun = templateGun.GetRemappedClone(gunSprite, sourceMaterial, pivotShiftsMeshUVCoords: false); // STEP 1.2 - 1.3 + Attachment newGun = templateGun.Copy(); // STEP 1.2 + newGun.SetRegion(gunSprite, sourceMaterial, pivotShiftsMeshUVCoords: false); // STEP 1.3 if (newGun != null) customSkin.SetAttachment(gunSlotIndex, gunKey, newGun); // STEP 1.4 // customSkin.RemoveAttachment(gunSlotIndex, gunKey); // To remove an item. @@ -144,7 +146,7 @@ namespace Spine.Unity.Examples { skeleton.SetupPoseSlots(); // Use the pose from setup pose. skeletonAnimation.Update(0); // Use the pose in the currently active animation. - // `GetRepackedSkin()` and each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` + // `GetRepackedSkin()` and each call to `SetRegion()` with parameter `premultiplyAlpha` set to `true` // cache necessarily created Texture copies which can be cleared by calling AtlasUtilities.ClearCache(). // You can optionally clear the textures cache after multiple repack operations. // Just be aware that while this cleanup frees up memory, it is also a costly operation diff --git a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/MixAndMatchGraphic.cs b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/MixAndMatchGraphic.cs index 71ffe0964..ce29d8d4d 100644 --- a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/MixAndMatchGraphic.cs +++ b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/MixAndMatchGraphic.cs @@ -96,15 +96,17 @@ namespace Spine.Unity.Examples { int visorSlotIndex = skeleton.Data.FindSlot(visorSlot).Index; // You can access GetAttachment and SetAttachment via string, but caching the slotIndex is faster. Attachment baseAttachment = baseSkin.GetAttachment(visorSlotIndex, visorKey); // STEP 1.1 - // Note: Each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` creates + // Note: Each call to `SetRegion()` with parameter `premultiplyAlpha` set to `true` creates // a cached Texture copy which can be cleared by calling AtlasUtilities.ClearCache() as done below. - Attachment newAttachment = baseAttachment.GetRemappedClone(visorSprite, sourceMaterial); // STEP 1.2 - 1.3 + Attachment newAttachment = baseAttachment.Copy(); // STEP 1.2 + newAttachment.SetRegion(visorSprite, sourceMaterial); // STEP 1.3 customSkin.SetAttachment(visorSlotIndex, visorKey, newAttachment); // STEP 1.4 // And now for the gun. int gunSlotIndex = skeleton.Data.FindSlot(gunSlot).Index; Attachment baseGun = baseSkin.GetAttachment(gunSlotIndex, gunKey); // STEP 1.1 - Attachment newGun = baseGun.GetRemappedClone(gunSprite, sourceMaterial); // STEP 1.2 - 1.3 + Attachment newGun = baseGun.Copy(); // STEP 1.2 + newGun.SetRegion(gunSprite, sourceMaterial); // STEP 1.3 if (newGun != null) customSkin.SetAttachment(gunSlotIndex, gunKey, newGun); // STEP 1.4 // customSkin.RemoveAttachment(gunSlotIndex, gunKey); // To remove an item. @@ -138,7 +140,7 @@ namespace Spine.Unity.Examples { skeletonGraphic.Animation.Update(0); skeletonGraphic.OverrideTexture = runtimeAtlas; - // `GetRepackedSkin()` and each call to `GetRemappedClone()` with parameter `premultiplyAlpha` set to `true` + // `GetRepackedSkin()` and each call to `SetRegion()` with parameter `premultiplyAlpha` set to `true` // cache necessarily created Texture copies which can be cleared by calling AtlasUtilities.ClearCache(). // You can optionally clear the textures cache after multiple repack operations. // Just be aware that while this cleanup frees up memory, it is also a costly operation diff --git a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Sample Components/Legacy/AtlasRegionAttacher.cs b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Sample Components/Legacy/AtlasRegionAttacher.cs index de4480636..8b4f4fcbd 100644 --- a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Sample Components/Legacy/AtlasRegionAttacher.cs +++ b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Sample Components/Legacy/AtlasRegionAttacher.cs @@ -71,7 +71,9 @@ namespace Spine.Unity.Examples { if (region == null) { slotPose.Attachment = null; } else if (inheritProperties && originalAttachment != null) { - slotPose.Attachment = originalAttachment.GetRemappedClone(region, true, true, scale); + Attachment newAttachment = originalAttachment.Copy(); + newAttachment.SetRegion(region, true, scale); + slotPose.Attachment = newAttachment; } else { RegionAttachment newRegionAttachment = region.ToRegionAttachment(region.name, scale); slotPose.Attachment = newRegionAttachment; diff --git a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Sample Components/Legacy/SpriteAttacher.cs b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Sample Components/Legacy/SpriteAttacher.cs index c2b984793..5b897cbe9 100644 --- a/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Sample Components/Legacy/SpriteAttacher.cs +++ b/spine-unity/Assets/Spine/Samples~/Spine Examples/Scripts/Sample Components/Legacy/SpriteAttacher.cs @@ -119,7 +119,7 @@ namespace Spine.Unity.Examples { if (sprite == null) attachment = null; else - attachment = applyPMA ? sprite.ToRegionAttachmentPMAClone(attachmentShader) : sprite.ToRegionAttachment(SpriteAttacher.GetPageFor(sprite.texture, attachmentShader)); + attachment = applyPMA ? sprite.ToRegionAttachmentWithNewPMATexture(attachmentShader) : sprite.ToRegionAttachment(SpriteAttacher.GetPageFor(sprite.texture, attachmentShader)); } } @@ -151,14 +151,14 @@ namespace Spine.Unity.Examples { [System.Obsolete] public static RegionAttachment AttachUnitySprite (this Skeleton skeleton, string slotName, Sprite sprite, Shader shader, bool applyPMA, float rotation = 0f) { - RegionAttachment att = applyPMA ? sprite.ToRegionAttachmentPMAClone(shader, rotation: rotation) : sprite.ToRegionAttachment(new Material(shader), rotation: rotation); + RegionAttachment att = applyPMA ? sprite.ToRegionAttachmentWithNewPMATexture(shader, rotation: rotation) : sprite.ToRegionAttachment(new Material(shader), rotation: rotation); skeleton.FindSlot(slotName).AppliedPose.Attachment = att; return att; } [System.Obsolete] public static RegionAttachment AddUnitySprite (this SkeletonData skeletonData, string slotName, Sprite sprite, string skinName, Shader shader, bool applyPMA, float rotation = 0f) { - RegionAttachment att = applyPMA ? sprite.ToRegionAttachmentPMAClone(shader, rotation: rotation) : sprite.ToRegionAttachment(new Material(shader), rotation); + RegionAttachment att = applyPMA ? sprite.ToRegionAttachmentWithNewPMATexture(shader, rotation: rotation) : sprite.ToRegionAttachment(new Material(shader), rotation); int slotIndex = skeletonData.FindSlot(slotName).Index; Skin skin = skeletonData.DefaultSkin; diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index bd67fe8ef..139e04bab 100644 --- a/spine-unity/Assets/Spine/package.json +++ b/spine-unity/Assets/Spine/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.spine-unity", "displayName": "spine-unity Runtime", "description": "This plugin provides the spine-unity runtime core and examples. Spine Examples can be installed via the Samples tab.", - "version": "4.3.52", + "version": "4.3.53", "unity": "2018.3", "author": { "name": "Esoteric Software",