mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-25 22:23:42 +08:00
[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`
This commit is contained in:
parent
d43c9fc966
commit
0991deb9dd
@ -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.
|
||||
|
||||
|
||||
@ -99,13 +99,13 @@ namespace Spine.Unity.AttachmentTools {
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate of the Sprite's texture data.</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate of the Sprite's texture data.</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Spine.AtlasRegion that uses a premultiplied alpha duplicate of the Sprite's texture data.</summary>
|
||||
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 {
|
||||
/// <summary>
|
||||
/// Frees up textures cached by repacking and remapping operations.
|
||||
///
|
||||
/// Calling <see cref="AttachmentCloneExtensions.GetRemappedClone"/> with parameter <c>premultiplyAlpha=true</c>,
|
||||
/// Calling <see cref="AttachmentRegionExtensions.SetRegion(Attachment, Sprite, Material, bool, bool, bool, bool, TextureFormat, bool)"/>
|
||||
/// with parameter <c>premultiplyAlpha=true</c>,
|
||||
/// <see cref="GetRepackedAttachments"/> or <see cref="GetRepackedSkin"/> 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 <see cref="AtlasUtilities.ClearCache()"/>.
|
||||
/// You may also want to call <c>Resources.UnloadUnusedAssets()</c> 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 <c>GetRemappedClone()</c> calls.
|
||||
/// screen has been exited, and if required additionally after a certain number of <c>SetRegion()</c> calls.
|
||||
/// </summary>
|
||||
public static void ClearCache () {
|
||||
foreach (Texture2D t in CachedRegionTexturesList) {
|
||||
|
||||
@ -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
|
||||
/// <summary>
|
||||
/// Gets a clone of the attachment remapped with a sprite image.</summary>
|
||||
/// <returns>The remapped clone.</returns>
|
||||
/// <param name="o">The original attachment.</param>
|
||||
/// <param name="sprite">The sprite whose texture to use.</param>
|
||||
/// <param name="sourceMaterial">The source material used to copy the shader and material properties from.</param>
|
||||
/// <param name="premultiplyAlpha">If <c>true</c>, a premultiply alpha clone of the original texture will be created.
|
||||
/// See remarks below for additional info.</param>
|
||||
/// <param name="cloneMeshAsLinked">If <c>true</c> MeshAttachments will be cloned as linked meshes and will inherit animation from the original attachment.</param>
|
||||
/// <param name="useOriginalRegionSize">If <c>true</c> the size of the original attachment will be followed, instead of using the Sprite size.</param>
|
||||
/// <param name="pivotShiftsMeshUVCoords">If <c>true</c> 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.</param>
|
||||
/// <param name="useOriginalRegionScale">If <c>true</c> 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.</param>
|
||||
/// <param name="pmaCloneTextureFormat">If <c>premultiplyAlpha</c> is <c>true></c>, the TextureFormat of the
|
||||
/// newly created PMA attachment Texture.</param>
|
||||
/// <param name="pmaCloneMipmaps">If <c>premultiplyAlpha</c> is <ctrue></c>, whether the newly created
|
||||
/// PMA attachment Texture has mipmaps enabled.</param>
|
||||
/// <remarks>When parameter <c>premultiplyAlpha</c> is set to <c>true</c>, 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 <see cref="AtlasUtilities.ClearCache()"/> on how to clear these cached textures.</remarks>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a clone of the attachment remapped with an atlasRegion image.</summary>
|
||||
/// <returns>The remapped clone.</returns>
|
||||
/// <param name="o">The original attachment.</param>
|
||||
/// <param name="atlasRegion">Atlas region.</param>
|
||||
/// <param name="cloneMeshAsLinked">If <c>true</c> MeshAttachments will be cloned as linked meshes and will inherit animation from the original attachment.</param>
|
||||
/// <param name="useOriginalRegionSize">If <c>true</c> the size of the original attachment will be followed, instead of using the Sprite size.</param>
|
||||
/// <param name="scale">Unity units per pixel scale used to scale the atlas region size when not using the original region size.</param>
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3431ed563b2c62f4c8c974a99365ba52
|
||||
timeCreated: 1563321428
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -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".</summary>
|
||||
/// <remarks>The duplicate texture is cached for later re-use. See documentation of
|
||||
/// <see cref="AttachmentCloneExtensions.GetRemappedClone"/> for additional details.</remarks>
|
||||
public static RegionAttachment ToRegionAttachmentPMAClone (this Sprite sprite, Shader shader, TextureFormat textureFormat = AtlasUtilities.SpineTextureFormat, bool mipmaps = AtlasUtilities.UseMipMaps, Material materialPropertySource = null, float rotation = 0f) {
|
||||
/// <see cref="SetRegion(Attachment, Sprite, Material, bool, bool, bool, bool, TextureFormat, bool)"/> for additional details.</remarks>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -125,5 +125,76 @@ namespace Spine.Unity.AttachmentTools {
|
||||
regionAttachment.Rotation = rotation;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SetRegion
|
||||
/// <summary>
|
||||
/// Sets the region of an attachment to match a Sprite image.</summary>
|
||||
/// <param name="attachment">The attachment to modify.</param>
|
||||
/// <param name="sprite">The sprite whose texture to use.</param>
|
||||
/// <param name="sourceMaterial">The source material used to copy the shader and material properties from.</param>
|
||||
/// <param name="premultiplyAlpha">If <c>true</c>, a premultiply alpha duplicate of the original texture will be created.
|
||||
/// See remarks below for additional info.</param>
|
||||
/// <param name="useOriginalRegionSize">If <c>true</c> the size of the original attachment will be followed, instead of using the Sprite size.</param>
|
||||
/// <param name="pivotShiftsMeshUVCoords">If <c>true</c> 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.</param>
|
||||
/// <param name="useOriginalRegionScale">If <c>true</c> 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.</param>
|
||||
/// <param name="pmaTextureFormat">If <c>premultiplyAlpha</c> is <c>true</c>, the TextureFormat of the
|
||||
/// newly created PMA attachment Texture.</param>
|
||||
/// <param name="pmaMipmaps">If <c>premultiplyAlpha</c> is <c>true</c>, whether the newly created
|
||||
/// PMA attachment Texture has mipmaps enabled.</param>
|
||||
/// <remarks>When parameter <c>premultiplyAlpha</c> is set to <c>true</c>, 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 <see cref="AtlasUtilities.ClearCache()"/> on how to clear these cached textures.</remarks>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the region of an attachment to use a new AtlasRegion.</summary>
|
||||
/// <param name="attachment">The attachment to modify.</param>
|
||||
/// <param name="atlasRegion">Atlas region.</param>
|
||||
/// <param name="useOriginalRegionSize">If <c>true</c> the size of the original attachment will be followed, instead of using the atlas region size.</param>
|
||||
/// <param name="scale">Unity units per pixel scale used to scale the atlas region size when not using the original region size.</param>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user