Initial commit: Client Doc docs Server Tools
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25ceef568a3dad448bf8a14fcc326964
|
||||
timeCreated: 1563321428
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,200 @@
|
||||
/******************************************************************************
|
||||
* 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 AttachmentRegionExtensions {
|
||||
#region Runtime RegionAttachments
|
||||
/// <summary>
|
||||
/// Creates a RegionAttachment based on a sprite. This method creates a real, usable AtlasRegion. That AtlasRegion uses a new AtlasPage with the Material provided./// </summary>
|
||||
public static RegionAttachment ToRegionAttachment (this Sprite sprite, Material material, float rotation = 0f) {
|
||||
return sprite.ToRegionAttachment(material.ToSpineAtlasPage(), rotation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a RegionAttachment based on a sprite. This method creates a real, usable AtlasRegion. That AtlasRegion uses the AtlasPage provided./// </summary>
|
||||
public static RegionAttachment ToRegionAttachment (this Sprite sprite, AtlasPage page, float rotation = 0f) {
|
||||
if (sprite == null) throw new System.ArgumentNullException("sprite");
|
||||
if (page == null) throw new System.ArgumentNullException("page");
|
||||
AtlasRegion region = sprite.ToAtlasRegion(page);
|
||||
float unitsPerPixel = 1f / sprite.pixelsPerUnit;
|
||||
return region.ToRegionAttachment(sprite.name, unitsPerPixel, rotation);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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="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.ToAtlasRegionWithNewPMATexture(shader, textureFormat, mipmaps, materialPropertySource);
|
||||
float unitsPerPixel = 1f / sprite.pixelsPerUnit;
|
||||
return region.ToRegionAttachment(sprite.name, unitsPerPixel, 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>
|
||||
/// Creates a new RegionAttachment from a given AtlasRegion.</summary>
|
||||
public static RegionAttachment ToRegionAttachment (this AtlasRegion region, string attachmentName, float scale = 0.01f, float rotation = 0f) {
|
||||
if (string.IsNullOrEmpty(attachmentName)) throw new System.ArgumentException("attachmentName can't be null or empty.", "attachmentName");
|
||||
if (region == null) throw new System.ArgumentNullException("region");
|
||||
|
||||
// (AtlasAttachmentLoader.cs)
|
||||
Sequence sequence = new Sequence(1, false);
|
||||
sequence.Regions[0] = region;
|
||||
RegionAttachment attachment = new RegionAttachment(attachmentName, sequence);
|
||||
|
||||
attachment.Path = region.name;
|
||||
attachment.ScaleX = 1;
|
||||
attachment.ScaleY = 1;
|
||||
attachment.Rotation = rotation;
|
||||
attachment.SetColor(Color.white);
|
||||
|
||||
// pass OriginalWidth and OriginalHeight because UpdateOffset uses it in its calculation.
|
||||
attachment.Width = region.originalWidth * scale;
|
||||
attachment.Height = region.originalHeight * scale;
|
||||
|
||||
attachment.SetColor(Color.white);
|
||||
attachment.UpdateSequence();
|
||||
return attachment;
|
||||
}
|
||||
|
||||
/// <summary> Sets the scale. Call regionAttachment.UpdateOffset to apply the change.</summary>
|
||||
public static void SetScale (this RegionAttachment regionAttachment, Vector2 scale) {
|
||||
regionAttachment.ScaleX = scale.x;
|
||||
regionAttachment.ScaleY = scale.y;
|
||||
}
|
||||
|
||||
/// <summary> Sets the scale. Call regionAttachment.UpdateOffset to apply the change.</summary>
|
||||
public static void SetScale (this RegionAttachment regionAttachment, float x, float y) {
|
||||
regionAttachment.ScaleX = x;
|
||||
regionAttachment.ScaleY = y;
|
||||
}
|
||||
|
||||
/// <summary> Sets the position offset. Call regionAttachment.UpdateOffset to apply the change.</summary>
|
||||
public static void SetPositionOffset (this RegionAttachment regionAttachment, Vector2 offset) {
|
||||
regionAttachment.X = offset.x;
|
||||
regionAttachment.Y = offset.y;
|
||||
}
|
||||
|
||||
/// <summary> Sets the position offset. Call regionAttachment.UpdateOffset to apply the change.</summary>
|
||||
public static void SetPositionOffset (this RegionAttachment regionAttachment, float x, float y) {
|
||||
regionAttachment.X = x;
|
||||
regionAttachment.Y = y;
|
||||
}
|
||||
|
||||
/// <summary> Sets the rotation. Call regionAttachment.UpdateOffset to apply the change.</summary>
|
||||
public static void SetRotation (this RegionAttachment regionAttachment, float rotation) {
|
||||
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) {
|
||||
var firstRegion = regionAttachment.Sequence.GetRegion(0);
|
||||
scale = regionAttachment.Width / firstRegion.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.Sequence.Regions[0] = atlasRegion;
|
||||
if (!useOriginalRegionSize) {
|
||||
regionAttachment.Width = atlasRegion.width * scale;
|
||||
regionAttachment.Height = atlasRegion.height * scale;
|
||||
}
|
||||
regionAttachment.UpdateSequence();
|
||||
} else {
|
||||
MeshAttachment meshAttachment = attachment as MeshAttachment;
|
||||
if (meshAttachment != null) {
|
||||
meshAttachment.Sequence.Regions[0] = atlasRegion;
|
||||
meshAttachment.UpdateSequence();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e7eac783deea004e9bc403eca68a7dc
|
||||
timeCreated: 1563321428
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
#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
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2f1169aaf0063f4da1c2b6033bbc13f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
namespace Spine.Unity {
|
||||
/// <summary>
|
||||
/// Allocation-free IEnumerator alternative for manual iteration.
|
||||
/// </summary>
|
||||
public struct CoroutineIterator {
|
||||
readonly uint state;
|
||||
|
||||
const uint DoneState = uint.MaxValue;
|
||||
public static readonly CoroutineIterator Done = new CoroutineIterator(DoneState);
|
||||
|
||||
public bool IsDone { get { return state == DoneState; } }
|
||||
public bool IsInitialState { get { return state == 0; } }
|
||||
|
||||
public CoroutineIterator (uint state = 0) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public uint State (uint mask) {
|
||||
return state & mask;
|
||||
}
|
||||
|
||||
public CoroutineIterator NextState () {
|
||||
return new CoroutineIterator(state + 1);
|
||||
}
|
||||
|
||||
public CoroutineIterator YieldReturnAtState (uint callerState, uint mask) {
|
||||
return new CoroutineIterator((state & ~mask) | callerState);
|
||||
}
|
||||
|
||||
public CoroutineIterator ToNestedCall (int numCallerMaskBits) {
|
||||
return new CoroutineIterator(state >> numCallerMaskBits);
|
||||
}
|
||||
|
||||
public CoroutineIterator FromNestedCall (uint callerState, int numCallerMaskBits) {
|
||||
return new CoroutineIterator(state << numCallerMaskBits | callerState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77d255700a6ba9d4f82263ff498ebba9
|
||||
timeCreated: 1752007001
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
|
||||
public static class EditorBridge {
|
||||
/// <summary>For editor script to subscribe.</summary>
|
||||
public static event Action<GameObject> OnRequestMarkDirty;
|
||||
|
||||
public static void RequestMarkDirty (GameObject go) {
|
||||
if (OnRequestMarkDirty != null)
|
||||
OnRequestMarkDirty.Invoke(go);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5edab187969d1f84d866247775a4e1aa
|
||||
timeCreated: 1759780987
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,354 @@
|
||||
/******************************************************************************
|
||||
* 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.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
namespace Spine.Unity {
|
||||
/// <summary>Utility class providing methods to check material settings for incorrect combinations.</summary>
|
||||
public class MaterialChecks {
|
||||
|
||||
static readonly int STRAIGHT_ALPHA_PARAM_ID = Shader.PropertyToID("_StraightAlphaInput");
|
||||
static readonly string ALPHAPREMULTIPLY_ON_KEYWORD = "_ALPHAPREMULTIPLY_ON";
|
||||
static readonly string ALPHAPREMULTIPLY_VERTEX_ONLY_ON_KEYWORD = "_ALPHAPREMULTIPLY_VERTEX_ONLY";
|
||||
static readonly string ALPHABLEND_ON_KEYWORD = "_ALPHABLEND_ON";
|
||||
static readonly string STRAIGHT_ALPHA_KEYWORD = "_STRAIGHT_ALPHA_INPUT";
|
||||
static readonly string[] FIXED_NORMALS_KEYWORDS = {
|
||||
"_FIXED_NORMALS_VIEWSPACE",
|
||||
"_FIXED_NORMALS_VIEWSPACE_BACKFACE",
|
||||
"_FIXED_NORMALS_MODELSPACE",
|
||||
"_FIXED_NORMALS_MODELSPACE_BACKFACE",
|
||||
"_FIXED_NORMALS_WORLDSPACE"
|
||||
};
|
||||
static readonly string NORMALMAP_KEYWORD = "_NORMALMAP";
|
||||
static readonly string CANVAS_GROUP_COMPATIBLE_KEYWORD = "_CANVAS_GROUP_COMPATIBLE";
|
||||
|
||||
public static readonly string kPMANotSupportedLinearMessage =
|
||||
"\nWarning: Premultiply-alpha atlas textures not supported in Linear color space!"
|
||||
+ "You can use a straight alpha texture with 'PMA Vertex Color' by choosing blend mode 'PMA Vertex, Straight Texture'.\n\n"
|
||||
+ "If you have a PMA Texture, please\n"
|
||||
+ "a) re-export atlas as straight alpha texture with 'premultiply alpha' unchecked\n"
|
||||
+ " (if you have already done this, please set the 'Straight Alpha Texture' Material parameter to 'true') or\n"
|
||||
+ "b) switch to Gamma color space via\nProject Settings - Player - Other Settings - Color Space.\n";
|
||||
public static readonly string kZSpacingRequiredMessage =
|
||||
"\nWarning: Z Spacing required on selected shader! Otherwise you will receive incorrect results.\n\nPlease\n"
|
||||
+ "1) make sure at least minimal 'Z Spacing' is set at the SkeletonRenderer/SkeletonAnimation component under 'Advanced' and\n"
|
||||
+ "2) ensure that the skeleton has overlapping parts on different Z depth. You can adjust this in Spine via draw order.\n";
|
||||
public static readonly string kZSpacingRecommendedMessage =
|
||||
"\nWarning: Z Spacing recommended on selected shader configuration!\n\nPlease\n"
|
||||
+ "1) make sure at least minimal 'Z Spacing' is set at the SkeletonRenderer/SkeletonAnimation component under 'Advanced' and\n"
|
||||
+ "2) ensure that the skeleton has overlapping parts on different Z depth. You can adjust this in Spine via draw order.\n";
|
||||
public static readonly string kAddNormalsMessage =
|
||||
"\nWarning: 'Add Normals' required when not using 'Fixed Normals'!\n\nPlease\n"
|
||||
+ "a) enable 'Add Normals' at the SkeletonRenderer/SkeletonAnimation component under 'Advanced' or\n"
|
||||
+ "b) enable 'Fixed Normals' at the Material.\n";
|
||||
public static readonly string kSolveTangentsMessage =
|
||||
"\nWarning: 'Solve Tangents' required when using a Normal Map!\n\nPlease\n"
|
||||
+ "a) enable 'Solve Tangents' at the SkeletonRenderer/SkeletonAnimation component under 'Advanced' or\n"
|
||||
+ "b) clear the 'Normal Map' parameter at the Material.\n";
|
||||
public static readonly string kNoSkeletonGraphicMaterialMessage =
|
||||
"\nWarning: Normal non-UI shaders other than 'Spine/SkeletonGraphic *' are not compatible with 'SkeletonGraphic' components! "
|
||||
+ "This will lead to incorrect rendering on some devices.\n\n"
|
||||
+ "Please change the assigned Material to e.g. 'SkeletonGraphicDefault' or change the used shader to one of the 'Spine/SkeletonGraphic *' shaders.\n\n"
|
||||
+ "Note that 'Spine/SkeletonGraphic *' shall still be used when using URP.\n";
|
||||
public static readonly string kSkeletonGraphicTintBlackMaterialRequiredMessage =
|
||||
"\nWarning: Only enable 'Tint Black' when using a 'SkeletonGraphic Tint Black' shader!\n"
|
||||
+ "Otherwise this will lead to incorrect rendering.\n\nPlease\n"
|
||||
+ "a) disable 'Tint Black' under 'Advanced' or\n"
|
||||
+ "b) use a 'SkeletonGraphic Tint Black' Material if you need Tint Black on a CanvasGroup.\n";
|
||||
|
||||
public static readonly string kTintBlackRequiredMessage =
|
||||
"\nWarning: 'Advanced - Tint Black' required when using any 'Tint Black' shader!\n\nPlease\n"
|
||||
+ "a) enable 'Tint Black' at the SkeletonRenderer/SkeletonGraphic component under 'Advanced' or\n"
|
||||
+ "b) use a different shader at the Material.\n";
|
||||
public static readonly string kCanvasTintBlackMessage =
|
||||
"\nWarning: Canvas 'Additional Shader Channels' 'uv1' and 'uv2' are required when 'Advanced - Tint Black' is enabled!\n\n"
|
||||
+ "Please enable both 'uv1' and 'uv2' channels at the parent Canvas component parameter 'Additional Shader Channels'.\n";
|
||||
public static readonly string kCanvasGroupCompatibleMaterialRequiredMessage =
|
||||
"\nWarning: 'CanvasGroup Compatible' is enabled at SkeletonGraphic but not at the Material!\n\nPlease\n"
|
||||
+ "a) use a Material with 'CanvasGroup Compatible' enabled or\n"
|
||||
+ "b) disable 'CanvasGroup Compatible' at the SkeletonGraphic component under 'Advanced'.\n"
|
||||
+ "You can find CanvasGroup Compatible 'SkeletonGraphicTintBlack' materials in the\n"
|
||||
+ "'CanvasGroupCompatible' subfolder of 'SkeletonGraphic-PMATexture' or 'SkeletonGraphic-StraightAlphaTexture'.";
|
||||
public static readonly string kCanvasGroupRequiredMessage =
|
||||
"\nWarning: 'CanvasGroup Compatible' is enabled at the Material but disabled at SkeletonGraphic!\n\nPlease\n"
|
||||
+ "a) disable 'CanvasGroup Compatible' at the Material or\n"
|
||||
+ "b) enable 'CanvasGroup Compatible' at the SkeletonGraphic component under 'Advanced'.\n"
|
||||
+ "You can find CanvasGroup Compatible 'SkeletonGraphicTintBlack' materials in the\n"
|
||||
+ "'CanvasGroupCompatible' subfolder of 'SkeletonGraphic-PMATexture' or 'SkeletonGraphic-StraightAlphaTexture'.";
|
||||
public static readonly string kCanvasGroupCompatiblePMAVertexMessage =
|
||||
"\nWarning: 'CanvasGroup Compatible' is enabled at the Material and 'PMA Vertex Colors' is enabled at SkeletonGraphic!\n\nPlease\n"
|
||||
+ "a) disable 'CanvasGroup Compatible' at the Material or\n"
|
||||
+ "b) disable 'PMA Vertex Colors' at the SkeletonGraphic component under 'Advanced'.";
|
||||
|
||||
public static bool IsMaterialSetupProblematic (SkeletonRenderer renderer, ref string errorMessage) {
|
||||
Material[] materials = renderer.GetComponent<Renderer>().sharedMaterials;
|
||||
bool isProblematic = false;
|
||||
foreach (Material material in materials) {
|
||||
if (material == null) continue;
|
||||
isProblematic |= IsMaterialSetupProblematic(material, ref errorMessage);
|
||||
if (renderer.zSpacing == 0) {
|
||||
isProblematic |= IsZSpacingRequired(material, ref errorMessage);
|
||||
}
|
||||
if (renderer.addNormals == false && RequiresMeshNormals(material)) {
|
||||
isProblematic = true;
|
||||
errorMessage += kAddNormalsMessage;
|
||||
}
|
||||
if (renderer.calculateTangents == false && RequiresTangents(material)) {
|
||||
isProblematic = true;
|
||||
errorMessage += kSolveTangentsMessage;
|
||||
}
|
||||
if (renderer.tintBlack == false && RequiresTintBlack(material)) {
|
||||
isProblematic = true;
|
||||
errorMessage += kTintBlackRequiredMessage;
|
||||
}
|
||||
}
|
||||
return isProblematic;
|
||||
}
|
||||
|
||||
public static bool IsMaterialSetupProblematic (SkeletonGraphic skeletonGraphic, ref string errorMessage) {
|
||||
Material material = skeletonGraphic.material;
|
||||
bool isProblematic = false;
|
||||
if (material) {
|
||||
isProblematic |= IsMaterialSetupProblematic(material, ref errorMessage);
|
||||
MeshGenerator.Settings settings = skeletonGraphic.MeshSettings;
|
||||
if (settings.zSpacing == 0) {
|
||||
isProblematic |= IsZSpacingRequired(material, ref errorMessage);
|
||||
}
|
||||
if (IsSpineNonSkeletonGraphicMaterial(material)) {
|
||||
isProblematic = true;
|
||||
errorMessage += kNoSkeletonGraphicMaterialMessage;
|
||||
}
|
||||
bool isTintBlackMaterial = IsSkeletonGraphicTintBlackMaterial(material);
|
||||
if (settings.tintBlack != isTintBlackMaterial) {
|
||||
isProblematic = true;
|
||||
errorMessage += (settings.tintBlack == false) ?
|
||||
kTintBlackRequiredMessage : kSkeletonGraphicTintBlackMaterialRequiredMessage;
|
||||
}
|
||||
|
||||
if (settings.tintBlack == true && CanvasNotSetupForTintBlack(skeletonGraphic)) {
|
||||
isProblematic = true;
|
||||
errorMessage += kCanvasTintBlackMessage;
|
||||
}
|
||||
|
||||
bool isCanvasGroupCompatible = IsCanvasGroupCompatible(material);
|
||||
if (settings.canvasGroupCompatible != isCanvasGroupCompatible) {
|
||||
isProblematic = true;
|
||||
errorMessage += (settings.canvasGroupCompatible == false) ?
|
||||
kCanvasGroupRequiredMessage : kCanvasGroupCompatibleMaterialRequiredMessage;
|
||||
}
|
||||
|
||||
if (settings.pmaVertexColors == true && settings.canvasGroupCompatible == true && settings.tintBlack == false) {
|
||||
isProblematic = true;
|
||||
errorMessage += kCanvasGroupCompatiblePMAVertexMessage;
|
||||
}
|
||||
}
|
||||
return isProblematic;
|
||||
}
|
||||
|
||||
public static bool IsMaterialSetupProblematic (Material material, ref string errorMessage) {
|
||||
return !IsColorSpaceSupported(material, ref errorMessage);
|
||||
}
|
||||
|
||||
public static bool IsZSpacingRequired (Material material, ref string errorMessage) {
|
||||
bool hasForwardAddPass = material.FindPass("FORWARD_DELTA") >= 0;
|
||||
if (hasForwardAddPass) {
|
||||
errorMessage += kZSpacingRequiredMessage;
|
||||
return true;
|
||||
}
|
||||
bool zWrite = material.HasProperty("_ZWrite") && material.GetFloat("_ZWrite") > 0.0f;
|
||||
if (zWrite) {
|
||||
errorMessage += kZSpacingRecommendedMessage;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsColorSpaceSupported (Material material, ref string errorMessage) {
|
||||
if (QualitySettings.activeColorSpace == ColorSpace.Linear) {
|
||||
if (IsPMATextureMaterial(material)) {
|
||||
errorMessage += kPMANotSupportedLinearMessage;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool UsesSpineShader (Material material) {
|
||||
return material.shader.name.Contains("Spine/");
|
||||
}
|
||||
|
||||
public static bool IsTextureSetupProblematic (Material material, ColorSpace colorSpace,
|
||||
bool sRGBTexture, bool mipmapEnabled, bool alphaIsTransparency,
|
||||
string texturePath, string materialPath,
|
||||
ref string errorMessage) {
|
||||
|
||||
if (material == null || !UsesSpineShader(material)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isProblematic = false;
|
||||
if (IsPMATextureMaterial(material)) {
|
||||
// 'sRGBTexture = true' generates incorrectly weighted mipmaps at PMA textures,
|
||||
// causing white borders due to undesired custom weighting.
|
||||
if (sRGBTexture && mipmapEnabled && colorSpace == ColorSpace.Gamma) {
|
||||
errorMessage += string.Format("`{0}` : Problematic Texture Settings found: " +
|
||||
"When enabling `Generate Mip Maps` in Gamma color space, it is recommended " +
|
||||
"to disable `sRGB (Color Texture)` on `Premultiply alpha` textures. Otherwise " +
|
||||
"you will receive white border artifacts on an atlas exported with default " +
|
||||
"`Premultiply alpha` settings.\n" +
|
||||
"(You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath);
|
||||
isProblematic = true;
|
||||
}
|
||||
if (alphaIsTransparency) {
|
||||
string materialName = System.IO.Path.GetFileName(materialPath);
|
||||
errorMessage += string.Format("`{0}` and material `{1}` : Problematic " +
|
||||
"Texture / Material Settings found: It is recommended to disable " +
|
||||
"`Alpha Is Transparency` on `Premultiply alpha` textures.\n" +
|
||||
"Assuming `Premultiply alpha` texture because `Straight Alpha Texture` " +
|
||||
"is disabled at material). " +
|
||||
"(You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath, materialName);
|
||||
isProblematic = true;
|
||||
}
|
||||
} else { // straight alpha texture
|
||||
if (!alphaIsTransparency) {
|
||||
string materialName = System.IO.Path.GetFileName(materialPath);
|
||||
errorMessage += string.Format("`{0}` and material `{1}` : Incorrect" +
|
||||
"Texture / Material Settings found: It is strongly recommended " +
|
||||
"to enable `Alpha Is Transparency` on `Straight alpha` textures.\n" +
|
||||
"Assuming `Straight alpha` texture because `Straight Alpha Texture` " +
|
||||
"is enabled at material). " +
|
||||
"(You can disable this warning in `Edit - Preferences - Spine`)\n", texturePath, materialName);
|
||||
isProblematic = true;
|
||||
}
|
||||
}
|
||||
return isProblematic;
|
||||
}
|
||||
|
||||
public static void EnablePMATextureAtMaterial (Material material, bool enablePMATexture) {
|
||||
if (material.HasProperty(STRAIGHT_ALPHA_PARAM_ID)) {
|
||||
material.SetInt(STRAIGHT_ALPHA_PARAM_ID, enablePMATexture ? 0 : 1);
|
||||
if (enablePMATexture)
|
||||
material.DisableKeyword(STRAIGHT_ALPHA_KEYWORD);
|
||||
else
|
||||
material.EnableKeyword(STRAIGHT_ALPHA_KEYWORD);
|
||||
} else {
|
||||
if (enablePMATexture) {
|
||||
material.DisableKeyword(ALPHAPREMULTIPLY_ON_KEYWORD);
|
||||
material.DisableKeyword(ALPHABLEND_ON_KEYWORD);
|
||||
material.EnableKeyword(ALPHAPREMULTIPLY_VERTEX_ONLY_ON_KEYWORD);
|
||||
} else {
|
||||
material.DisableKeyword(ALPHAPREMULTIPLY_ON_KEYWORD);
|
||||
material.DisableKeyword(ALPHAPREMULTIPLY_VERTEX_ONLY_ON_KEYWORD);
|
||||
material.EnableKeyword(ALPHABLEND_ON_KEYWORD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsPMATextureMaterial (Material material) {
|
||||
bool usesAlphaPremultiplyKeyword = IsSpriteShader(material);
|
||||
if (usesAlphaPremultiplyKeyword)
|
||||
return material.IsKeywordEnabled(ALPHAPREMULTIPLY_ON_KEYWORD);
|
||||
else
|
||||
return material.HasProperty(STRAIGHT_ALPHA_PARAM_ID) && material.GetInt(STRAIGHT_ALPHA_PARAM_ID) == 0;
|
||||
}
|
||||
|
||||
static bool IsURP3DMaterial (Material material) {
|
||||
return material.shader.name.Contains("Universal Render Pipeline/Spine");
|
||||
}
|
||||
|
||||
static bool IsSpineNonSkeletonGraphicMaterial (Material material) {
|
||||
return material.shader.name.Contains("Spine") && !material.shader.name.Contains("SkeletonGraphic");
|
||||
}
|
||||
|
||||
static bool IsSkeletonGraphicTintBlackMaterial (Material material) {
|
||||
return material.shader.name.Contains("Spine") && material.shader.name.Contains("SkeletonGraphic")
|
||||
&& material.shader.name.Contains("Black");
|
||||
}
|
||||
|
||||
static bool AreShadowsDisabled (Material material) {
|
||||
return material.IsKeywordEnabled("_RECEIVE_SHADOWS_OFF");
|
||||
}
|
||||
|
||||
static bool RequiresMeshNormals (Material material) {
|
||||
bool anyFixedNormalSet = false;
|
||||
foreach (string fixedNormalKeyword in FIXED_NORMALS_KEYWORDS) {
|
||||
if (material.IsKeywordEnabled(fixedNormalKeyword)) {
|
||||
anyFixedNormalSet = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool isShaderWithMeshNormals = IsLitSpriteShader(material);
|
||||
return isShaderWithMeshNormals && !anyFixedNormalSet;
|
||||
}
|
||||
|
||||
static bool IsLitSpriteShader (Material material) {
|
||||
string shaderName = material.shader.name;
|
||||
return shaderName.Contains("Spine/Sprite/Pixel Lit") ||
|
||||
shaderName.Contains("Spine/Sprite/Vertex Lit") ||
|
||||
shaderName.Contains("2D/Spine/Sprite") || // covers both URP and LWRP
|
||||
shaderName.Contains("Pipeline/Spine/Sprite"); // covers both URP and LWRP
|
||||
}
|
||||
|
||||
static bool IsSpriteShader (Material material) {
|
||||
if (IsLitSpriteShader(material))
|
||||
return true;
|
||||
string shaderName = material.shader.name;
|
||||
return shaderName.Contains("Spine/Sprite/Unlit");
|
||||
}
|
||||
|
||||
static bool RequiresTintBlack (Material material) {
|
||||
bool isTintBlackShader =
|
||||
material.shader.name.Contains("Spine") &&
|
||||
material.shader.name.Contains("Tint Black");
|
||||
return isTintBlackShader;
|
||||
}
|
||||
|
||||
static bool RequiresTangents (Material material) {
|
||||
return material.IsKeywordEnabled(NORMALMAP_KEYWORD);
|
||||
}
|
||||
static bool IsCanvasGroupCompatible (Material material) {
|
||||
return material.IsKeywordEnabled(CANVAS_GROUP_COMPATIBLE_KEYWORD);
|
||||
}
|
||||
|
||||
static bool CanvasNotSetupForTintBlack (SkeletonGraphic skeletonGraphic) {
|
||||
Canvas canvas = skeletonGraphic.canvas;
|
||||
if (!canvas)
|
||||
return false;
|
||||
AdditionalCanvasShaderChannels requiredChannels =
|
||||
AdditionalCanvasShaderChannels.TexCoord1 |
|
||||
AdditionalCanvasShaderChannels.TexCoord2;
|
||||
return (canvas.additionalShaderChannels & requiredChannels) != requiredChannels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // UNITY_EDITOR
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e68fa8db689084946adce454b83e6d4a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,71 @@
|
||||
/******************************************************************************
|
||||
* 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 UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
public static class MathUtilities {
|
||||
public static float InverseLerp (float a, float b, float value) {
|
||||
return (value - a) / (b - a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the linear interpolation ratio of <c>a</c> to <c>b</c> that <c>value</c> lies on.
|
||||
/// This is the t value that fulfills <c>value = lerp(a, b, t)</c>.
|
||||
/// </summary>
|
||||
public static Vector2 InverseLerp (Vector2 a, Vector2 b, Vector2 value) {
|
||||
return new Vector2(
|
||||
(value.x - a.x) / (b.x - a.x),
|
||||
(value.y - a.y) / (b.y - a.y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the linear interpolation ratio of <c>a</c> to <c>b</c> that <c>value</c> lies on.
|
||||
/// This is the t value that fulfills <c>value = lerp(a, b, t)</c>.
|
||||
/// </summary>
|
||||
public static Vector3 InverseLerp (Vector3 a, Vector3 b, Vector3 value) {
|
||||
return new Vector3(
|
||||
(value.x - a.x) / (b.x - a.x),
|
||||
(value.y - a.y) / (b.y - a.y),
|
||||
(value.z - a.z) / (b.z - a.z));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the linear interpolation ratio of <c>a</c> to <c>b</c> that <c>value</c> lies on.
|
||||
/// This is the t value that fulfills <c>value = lerp(a, b, t)</c>.
|
||||
/// </summary>
|
||||
public static Vector4 InverseLerp (Vector4 a, Vector4 b, Vector4 value) {
|
||||
return new Vector4(
|
||||
(value.x - a.x) / (b.x - a.x),
|
||||
(value.y - a.y) / (b.y - a.y),
|
||||
(value.z - a.z) / (b.z - a.z),
|
||||
(value.w - a.w) / (b.w - a.w));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef2b5da9383ed474d895b702a9baf79e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
/******************************************************************************
|
||||
* 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.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
|
||||
/// <summary>
|
||||
/// Project settings stored in a ScriptableObject for use in the build at runtime.
|
||||
/// Writing the ScriptableObject asset is performed by <see cref="RuntimeSettingsEditor"/>,
|
||||
/// triggered by preferences setting changes.
|
||||
/// </summary>
|
||||
public class RuntimeSettings : ScriptableObject {
|
||||
|
||||
public bool useThreadedMeshGeneration = false;
|
||||
public static bool UseThreadedMeshGeneration {
|
||||
get { return Instance.useThreadedMeshGeneration; }
|
||||
set { Instance.useThreadedMeshGeneration = value; }
|
||||
}
|
||||
|
||||
public bool useThreadedAnimation = false;
|
||||
public static bool UseThreadedAnimation{
|
||||
get { return Instance.useThreadedAnimation; }
|
||||
set { Instance.useThreadedAnimation = value; }
|
||||
}
|
||||
|
||||
/// <summary>Path relative to "Assets/Resources".</summary>
|
||||
public const string ResourcePath = "SpineRuntimeSettings";
|
||||
|
||||
private static RuntimeSettings singletonInstance;
|
||||
public static RuntimeSettings Instance {
|
||||
get {
|
||||
if (singletonInstance == null) {
|
||||
singletonInstance = Resources.Load<RuntimeSettings>(ResourcePath);
|
||||
}
|
||||
if (singletonInstance == null) {
|
||||
singletonInstance = CreateInstance<RuntimeSettings>();
|
||||
}
|
||||
return singletonInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a6a3378dfca7914d8ba2b337350cab8
|
||||
timeCreated: 1752096299
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,43 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
namespace Spine.Unity {
|
||||
|
||||
/// <summary>
|
||||
/// TriState enum which can be used to replace and extend a bool variable by
|
||||
/// a third <c>UseGlobalSettings</c> state. Automatically maps serialized
|
||||
/// bool values to corresponding <c>Disable</c> and <c>Enable</c> states.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public enum SettingsTriState {
|
||||
Disable,
|
||||
Enable,
|
||||
UseGlobalSetting
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f6692d1b45ac11459207a012cafeb03
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,482 @@
|
||||
/******************************************************************************
|
||||
* 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 UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
public static class SkeletonExtensions {
|
||||
|
||||
#region Colors
|
||||
const float ByteToFloat = 1f / 255f;
|
||||
public static Color GetColor (this Slot s) { return s.AppliedPose.GetColor(); }
|
||||
public static Color GetColorTintBlack (this Slot s) {
|
||||
Color? darkColor = s.AppliedPose.GetDarkColor();
|
||||
if (!darkColor.HasValue) return Color.black;
|
||||
return darkColor.Value;
|
||||
}
|
||||
|
||||
public static void SetColor (this Slot slot, Color color) {
|
||||
slot.AppliedPose.SetColor(color);
|
||||
}
|
||||
|
||||
public static void SetColor (this Slot slot, Color32 color) {
|
||||
slot.AppliedPose.SetColor(color);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Skeleton
|
||||
/// <summary>Sets the Skeleton's local scale using a UnityEngine.Vector2. If only individual components need to be set, set Skeleton.ScaleX or Skeleton.ScaleY.</summary>
|
||||
public static void SetLocalScale (this Skeleton skeleton, Vector2 scale) {
|
||||
skeleton.ScaleX = scale.x;
|
||||
skeleton.ScaleY = scale.y;
|
||||
}
|
||||
|
||||
/// <summary>Gets the internal bone matrix as a Unity bonespace-to-skeletonspace transformation matrix.</summary>
|
||||
public static Matrix4x4 GetMatrix4x4 (this Bone bone) {
|
||||
return bone.AppliedPose.GetMatrix4x4();
|
||||
}
|
||||
|
||||
/// <summary>Gets the internal bone matrix as a Unity bonespace-to-skeletonspace transformation matrix.</summary>
|
||||
public static Matrix4x4 GetMatrix4x4 (this BonePose bonePose) {
|
||||
return new Matrix4x4 {
|
||||
m00 = bonePose.A,
|
||||
m01 = bonePose.B,
|
||||
m03 = bonePose.WorldX,
|
||||
m10 = bonePose.C,
|
||||
m11 = bonePose.D,
|
||||
m13 = bonePose.WorldY,
|
||||
m33 = 1
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Bone
|
||||
/// <summary>Sets the bone's (local) X and Y according to a Vector2</summary>
|
||||
public static void SetLocalPosition (this Bone bone, Vector2 position) {
|
||||
bone.Pose.SetLocalPosition(position);
|
||||
}
|
||||
|
||||
/// <summary>Sets the bone's (local) X and Y according to a Vector2</summary>
|
||||
public static void SetLocalPosition (this BonePose bonePose, Vector2 position) {
|
||||
bonePose.X = position.x;
|
||||
bonePose.Y = position.y;
|
||||
}
|
||||
|
||||
/// <summary>Sets the bone's (local) X and Y according to a Vector3. The z component is ignored.</summary>
|
||||
public static void SetLocalPosition (this Bone bone, Vector3 position) {
|
||||
bone.Pose.SetLocalPosition(position);
|
||||
}
|
||||
|
||||
/// <summary>Sets the bone's (local) X and Y according to a Vector3. The z component is ignored.</summary>
|
||||
public static void SetLocalPosition (this BonePose bonePose, Vector3 position) {
|
||||
bonePose.X = position.x;
|
||||
bonePose.Y = position.y;
|
||||
}
|
||||
|
||||
/// <summary>Gets the bone's local X and Y as a Vector2.</summary>
|
||||
public static Vector2 GetLocalPosition (this Bone bone) {
|
||||
return bone.Pose.GetLocalPosition();
|
||||
}
|
||||
|
||||
/// <summary>Gets the bone's local X and Y as a Vector2.</summary>
|
||||
public static Vector2 GetLocalPosition (this BonePose bonePose) {
|
||||
return new Vector2(bonePose.X, bonePose.Y);
|
||||
}
|
||||
|
||||
/// <summary>Gets the position of the bone in Skeleton-space.</summary>
|
||||
public static Vector2 GetSkeletonSpacePosition (this Bone bone) {
|
||||
return bone.GetSkeletonSpacePosition();
|
||||
}
|
||||
|
||||
/// <summary>Gets the position of the bone in Skeleton-space.</summary>
|
||||
public static Vector2 GetSkeletonSpacePosition (this BonePose bonePose) {
|
||||
return new Vector2(bonePose.WorldX, bonePose.WorldY);
|
||||
}
|
||||
|
||||
/// <summary>Gets a local offset from the bone and converts it into Skeleton-space.</summary>
|
||||
public static Vector2 GetSkeletonSpacePosition (this Bone bone, Vector2 boneLocal) {
|
||||
Vector2 o;
|
||||
bone.AppliedPose.LocalToWorld(boneLocal.x, boneLocal.y, out o.x, out o.y);
|
||||
return o;
|
||||
}
|
||||
|
||||
/// <summary>Gets the bone's Unity World position using its Spine GameObject Transform.
|
||||
/// UpdateWorldTransform needs to have been called for this to return the correct, updated value.</summary>
|
||||
public static Vector3 GetWorldPosition (this Bone bone, UnityEngine.Transform spineGameObjectTransform) {
|
||||
return GetWorldPosition(bone.AppliedPose, spineGameObjectTransform);
|
||||
}
|
||||
|
||||
public static Vector3 GetWorldPosition (this Bone bone, UnityEngine.Transform spineGameObjectTransform, float positionScale) {
|
||||
return GetWorldPosition(bone.AppliedPose, spineGameObjectTransform, positionScale);
|
||||
}
|
||||
|
||||
public static Vector3 GetWorldPosition (this Bone bone, UnityEngine.Transform spineGameObjectTransform, float positionScale, Vector2 positionOffset) {
|
||||
return GetWorldPosition(bone.AppliedPose, spineGameObjectTransform, positionScale, positionOffset);
|
||||
}
|
||||
|
||||
/// <summary>Gets the bone's Unity World position using its Spine GameObject Transform.
|
||||
/// UpdateWorldTransform needs to have been called for this to return the correct, updated value.</summary>
|
||||
public static Vector3 GetWorldPosition (this BonePose bonePose, UnityEngine.Transform spineGameObjectTransform) {
|
||||
return spineGameObjectTransform.TransformPoint(new Vector3(
|
||||
bonePose.WorldX, bonePose.WorldY));
|
||||
}
|
||||
|
||||
public static Vector3 GetWorldPosition (this BonePose bonePose, UnityEngine.Transform spineGameObjectTransform, float positionScale) {
|
||||
return spineGameObjectTransform.TransformPoint(new Vector3(
|
||||
bonePose.WorldX * positionScale, bonePose.WorldY * positionScale));
|
||||
}
|
||||
|
||||
public static Vector3 GetWorldPosition (this BonePose bonePose, UnityEngine.Transform spineGameObjectTransform, float positionScale, Vector2 positionOffset) {
|
||||
return spineGameObjectTransform.TransformPoint(new Vector3(
|
||||
bonePose.WorldX * positionScale + positionOffset.x, bonePose.WorldY * positionScale + positionOffset.y));
|
||||
}
|
||||
|
||||
/// <summary>Gets a skeleton space UnityEngine.Quaternion representation of bone.WorldRotationX.</summary>
|
||||
public static Quaternion GetQuaternion (this Bone bone) {
|
||||
return bone.AppliedPose.GetQuaternion();
|
||||
}
|
||||
|
||||
/// <summary>Gets a skeleton space UnityEngine.Quaternion representation of bone.WorldRotationX.</summary>
|
||||
public static Quaternion GetQuaternion (this BonePose bonePose) {
|
||||
float halfRotation = Mathf.Atan2(bonePose.C, bonePose.A) * 0.5f;
|
||||
return new Quaternion(0, 0, Mathf.Sin(halfRotation), Mathf.Cos(halfRotation));
|
||||
}
|
||||
|
||||
/// <summary>Gets a bone-local space UnityEngine.Quaternion representation of bone.rotation.</summary>
|
||||
public static Quaternion GetLocalQuaternion (this Bone bone) {
|
||||
return bone.Pose.GetLocalQuaternion();
|
||||
}
|
||||
|
||||
/// <summary>Gets a bone-local space UnityEngine.Quaternion representation of bone.rotation.</summary>
|
||||
public static Quaternion GetLocalQuaternion (this BonePose bonePose) {
|
||||
float halfRotation = bonePose.Rotation * Mathf.Deg2Rad * 0.5f;
|
||||
return new Quaternion(0, 0, Mathf.Sin(halfRotation), Mathf.Cos(halfRotation));
|
||||
}
|
||||
|
||||
/// <summary>Returns the Skeleton's local scale as a UnityEngine.Vector2. If only individual components are needed, use Skeleton.ScaleX or Skeleton.ScaleY.</summary>
|
||||
public static Vector2 GetLocalScale (this Skeleton skeleton) {
|
||||
return new Vector2(skeleton.ScaleX, skeleton.ScaleY);
|
||||
}
|
||||
|
||||
/// <summary>Calculates a 2x2 Transformation Matrix that can convert a skeleton-space position to a bone-local position.</summary>
|
||||
public static void GetWorldToLocalMatrix (this Bone bone, out float ia, out float ib, out float ic, out float id) {
|
||||
bone.AppliedPose.GetWorldToLocalMatrix(out ia, out ib, out ic, out id);
|
||||
}
|
||||
|
||||
/// <summary>Calculates a 2x2 Transformation Matrix that can convert a skeleton-space position to a bone-local position.</summary>
|
||||
public static void GetWorldToLocalMatrix (this BonePose bonePose, out float ia, out float ib, out float ic, out float id) {
|
||||
float a = bonePose.A, b = bonePose.B, c = bonePose.C, d = bonePose.D;
|
||||
float invDet = 1 / (a * d - b * c);
|
||||
ia = invDet * d;
|
||||
ib = invDet * -b;
|
||||
ic = invDet * -c;
|
||||
id = invDet * a;
|
||||
}
|
||||
|
||||
/// <summary>UnityEngine.Vector2 override of Bone.WorldToLocal. This converts a skeleton-space position into a bone local position.</summary>
|
||||
public static Vector2 WorldToLocal (this Bone bone, Vector2 worldPosition) {
|
||||
return bone.AppliedPose.WorldToLocal(worldPosition);
|
||||
}
|
||||
|
||||
/// <summary>UnityEngine.Vector2 override of Bone.WorldToLocal. This converts a skeleton-space position into a bone local position.</summary>
|
||||
public static Vector2 WorldToLocal (this BonePose bonePose, Vector2 worldPosition) {
|
||||
Vector2 o;
|
||||
bonePose.WorldToLocal(worldPosition.x, worldPosition.y, out o.x, out o.y);
|
||||
return o;
|
||||
}
|
||||
|
||||
/// <summary>Sets the skeleton-space position of a bone.</summary>
|
||||
/// <returns>The local position in its parent bone space, or in skeleton space if it is the root bone.</returns>
|
||||
public static Vector2 SetPositionSkeletonSpace (this Bone bone, Vector2 skeletonSpacePosition) {
|
||||
if (bone.Parent == null) { // root bone
|
||||
bone.SetLocalPosition(skeletonSpacePosition);
|
||||
return skeletonSpacePosition;
|
||||
} else {
|
||||
Bone parent = bone.Parent;
|
||||
Vector2 parentLocal = parent.WorldToLocal(skeletonSpacePosition);
|
||||
bone.SetLocalPosition(parentLocal);
|
||||
return parentLocal;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Attachments
|
||||
public static Material GetMaterial (this Attachment a) {
|
||||
object rendererObject = null;
|
||||
IHasSequence renderableAttachment = a as IHasSequence;
|
||||
if (renderableAttachment != null) {
|
||||
rendererObject = renderableAttachment.Sequence.Regions[0];
|
||||
}
|
||||
|
||||
if (rendererObject == null)
|
||||
return null;
|
||||
|
||||
return (Material)((AtlasRegion)rendererObject).page.rendererObject;
|
||||
}
|
||||
|
||||
/// <summary>Fills a Vector2 buffer with local vertices.</summary>
|
||||
/// <param name="va">The VertexAttachment</param>
|
||||
/// <param name="slot">Slot where the attachment belongs.</param>
|
||||
/// <param name="buffer">Correctly-sized buffer. Use attachment's .WorldVerticesLength to get the correct size.
|
||||
/// If null, a new Vector2[] of the correct size will be allocated.</param>
|
||||
public static Vector2[] GetLocalVertices (this VertexAttachment va, Skeleton skeleton, Slot slot, Vector2[] buffer) {
|
||||
int floatsCount = va.WorldVerticesLength;
|
||||
int bufferTargetSize = floatsCount >> 1;
|
||||
buffer = buffer ?? new Vector2[bufferTargetSize];
|
||||
if (buffer.Length < bufferTargetSize) throw new System.ArgumentException(
|
||||
string.Format("Vector2 buffer too small. {0} requires an array of size {1}. " +
|
||||
"Use the attachment's .WorldVerticesLength to get the correct size.", va.Name, floatsCount), "buffer");
|
||||
|
||||
if (va.Bones == null && slot.Pose.Deform.Count == 0) {
|
||||
float[] localVerts = va.Vertices;
|
||||
for (int i = 0; i < bufferTargetSize; i++) {
|
||||
int j = i * 2;
|
||||
buffer[i] = new Vector2(localVerts[j], localVerts[j + 1]);
|
||||
}
|
||||
} else {
|
||||
float[] floats = new float[floatsCount];
|
||||
va.ComputeWorldVertices(skeleton, slot, floats);
|
||||
|
||||
Bone sb = slot.Bone;
|
||||
BonePose pose = slot.Bone.AppliedPose;
|
||||
float ia, ib, ic, id, bwx = pose.WorldX, bwy = pose.WorldY;
|
||||
sb.GetWorldToLocalMatrix(out ia, out ib, out ic, out id);
|
||||
for (int i = 0; i < bufferTargetSize; i++) {
|
||||
int j = i * 2;
|
||||
float x = floats[j] - bwx, y = floats[j + 1] - bwy;
|
||||
buffer[i] = new Vector2(x * ia + y * ib, x * ic + y * id);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary>Calculates world vertices and fills a Vector2 buffer.</summary>
|
||||
/// <param name="a">The VertexAttachment</param>
|
||||
/// <param name="slot">Slot where the attachment belongs.</param>
|
||||
/// <param name="buffer">Correctly-sized buffer. Use attachment's .WorldVerticesLength to get the correct size. If null, a new Vector2[] of the correct size will be allocated.</param>
|
||||
public static Vector2[] GetWorldVertices (this VertexAttachment a, Skeleton skeleton, Slot slot, Vector2[] buffer) {
|
||||
int worldVertsLength = a.WorldVerticesLength;
|
||||
int bufferTargetSize = worldVertsLength >> 1;
|
||||
buffer = buffer ?? new Vector2[bufferTargetSize];
|
||||
if (buffer.Length < bufferTargetSize) throw new System.ArgumentException(string.Format("Vector2 buffer too small. {0} requires an array of size {1}. Use the attachment's .WorldVerticesLength to get the correct size.", a.Name, worldVertsLength), "buffer");
|
||||
|
||||
float[] floats = new float[worldVertsLength];
|
||||
a.ComputeWorldVertices(skeleton, slot, floats);
|
||||
|
||||
for (int i = 0, n = worldVertsLength >> 1; i < n; i++) {
|
||||
int j = i * 2;
|
||||
buffer[i] = new Vector2(floats[j], floats[j + 1]);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// <summary>Gets the PointAttachment's Unity World position using its Spine GameObject Transform.</summary>
|
||||
public static Vector3 GetWorldPosition (this PointAttachment attachment, Slot slot, Transform spineGameObjectTransform) {
|
||||
Vector3 skeletonSpacePosition;
|
||||
skeletonSpacePosition.z = 0;
|
||||
attachment.ComputeWorldPosition(slot.Bone.AppliedPose, out skeletonSpacePosition.x, out skeletonSpacePosition.y);
|
||||
return spineGameObjectTransform.TransformPoint(skeletonSpacePosition);
|
||||
}
|
||||
|
||||
/// <summary>Gets the PointAttachment's Unity World position using its Spine GameObject Transform.</summary>
|
||||
public static Vector3 GetWorldPosition (this PointAttachment attachment, Bone bone, Transform spineGameObjectTransform) {
|
||||
Vector3 skeletonSpacePosition;
|
||||
skeletonSpacePosition.z = 0;
|
||||
attachment.ComputeWorldPosition(bone.AppliedPose, out skeletonSpacePosition.x, out skeletonSpacePosition.y);
|
||||
return spineGameObjectTransform.TransformPoint(skeletonSpacePosition);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
namespace Spine {
|
||||
using System;
|
||||
|
||||
public struct BoneMatrix {
|
||||
public float a, b, c, d, x, y;
|
||||
|
||||
/// <summary>Recursively calculates a worldspace bone matrix based on BoneData.</summary>
|
||||
public static BoneMatrix CalculateSetupWorld (BoneData boneData) {
|
||||
if (boneData == null)
|
||||
return default(BoneMatrix);
|
||||
|
||||
// End condition: isRootBone
|
||||
if (boneData.Parent == null)
|
||||
return GetInheritedInternal(boneData, default(BoneMatrix));
|
||||
|
||||
BoneMatrix result = CalculateSetupWorld(boneData.Parent);
|
||||
return GetInheritedInternal(boneData, result);
|
||||
}
|
||||
|
||||
static BoneMatrix GetInheritedInternal (BoneData boneData, BoneMatrix parentMatrix) {
|
||||
BoneData parent = boneData.Parent;
|
||||
if (parent == null) return new BoneMatrix(boneData); // isRootBone
|
||||
|
||||
float pa = parentMatrix.a, pb = parentMatrix.b, pc = parentMatrix.c, pd = parentMatrix.d;
|
||||
BoneMatrix result = default(BoneMatrix);
|
||||
var setup = boneData.GetSetupPose();
|
||||
result.x = pa * setup.X + pb * setup.Y + parentMatrix.x;
|
||||
result.y = pc * setup.X + pd * setup.Y + parentMatrix.y;
|
||||
|
||||
switch (setup.Inherit) {
|
||||
case Inherit.Normal: {
|
||||
float rotationY = setup.Rotation + 90 + setup.ShearY;
|
||||
float la = MathUtils.CosDeg(setup.Rotation + setup.ShearX) * setup.ScaleX;
|
||||
float lb = MathUtils.CosDeg(rotationY) * setup.ScaleY;
|
||||
float lc = MathUtils.SinDeg(setup.Rotation + setup.ShearX) * setup.ScaleX;
|
||||
float ld = MathUtils.SinDeg(rotationY) * setup.ScaleY;
|
||||
result.a = pa * la + pb * lc;
|
||||
result.b = pa * lb + pb * ld;
|
||||
result.c = pc * la + pd * lc;
|
||||
result.d = pc * lb + pd * ld;
|
||||
break;
|
||||
}
|
||||
case Inherit.OnlyTranslation: {
|
||||
float rotationY = setup.Rotation + 90 + setup.ShearY;
|
||||
result.a = MathUtils.CosDeg(setup.Rotation + setup.ShearX) * setup.ScaleX;
|
||||
result.b = MathUtils.CosDeg(rotationY) * setup.ScaleY;
|
||||
result.c = MathUtils.SinDeg(setup.Rotation + setup.ShearX) * setup.ScaleX;
|
||||
result.d = MathUtils.SinDeg(rotationY) * setup.ScaleY;
|
||||
break;
|
||||
}
|
||||
case Inherit.NoRotationOrReflection: {
|
||||
float s = pa * pa + pc * pc, prx;
|
||||
if (s > 0.0001f) {
|
||||
s = Math.Abs(pa * pd - pb * pc) / s;
|
||||
pb = pc * s;
|
||||
pd = pa * s;
|
||||
prx = MathUtils.Atan2(pc, pa) * MathUtils.RadDeg;
|
||||
} else {
|
||||
pa = 0;
|
||||
pc = 0;
|
||||
prx = 90 - MathUtils.Atan2(pd, pb) * MathUtils.RadDeg;
|
||||
}
|
||||
float rx = setup.Rotation + setup.ShearX - prx;
|
||||
float ry = setup.Rotation + setup.ShearY - prx + 90;
|
||||
float la = MathUtils.CosDeg(rx) * setup.ScaleX;
|
||||
float lb = MathUtils.CosDeg(ry) * setup.ScaleY;
|
||||
float lc = MathUtils.SinDeg(rx) * setup.ScaleX;
|
||||
float ld = MathUtils.SinDeg(ry) * setup.ScaleY;
|
||||
result.a = pa * la - pb * lc;
|
||||
result.b = pa * lb - pb * ld;
|
||||
result.c = pc * la + pd * lc;
|
||||
result.d = pc * lb + pd * ld;
|
||||
break;
|
||||
}
|
||||
case Inherit.NoScale:
|
||||
case Inherit.NoScaleOrReflection: {
|
||||
float cos = MathUtils.CosDeg(setup.Rotation), sin = MathUtils.SinDeg(setup.Rotation);
|
||||
float za = pa * cos + pb * sin;
|
||||
float zc = pc * cos + pd * sin;
|
||||
float s = (float)Math.Sqrt(za * za + zc * zc);
|
||||
if (s > 0.00001f)
|
||||
s = 1 / s;
|
||||
za *= s;
|
||||
zc *= s;
|
||||
s = (float)Math.Sqrt(za * za + zc * zc);
|
||||
float r = MathUtils.PI / 2 + MathUtils.Atan2(zc, za);
|
||||
float zb = MathUtils.Cos(r) * s;
|
||||
float zd = MathUtils.Sin(r) * s;
|
||||
float la = MathUtils.CosDeg(setup.ShearX) * setup.ScaleX;
|
||||
float lb = MathUtils.CosDeg(90 + setup.ShearY) * setup.ScaleY;
|
||||
float lc = MathUtils.SinDeg(setup.ShearX) * setup.ScaleX;
|
||||
float ld = MathUtils.SinDeg(90 + setup.ShearY) * setup.ScaleY;
|
||||
if (setup.Inherit != Inherit.NoScaleOrReflection ? pa * pd - pb * pc < 0 : false) {
|
||||
zb = -zb;
|
||||
zd = -zd;
|
||||
}
|
||||
result.a = za * la + zb * lc;
|
||||
result.b = za * lb + zb * ld;
|
||||
result.c = zc * la + zd * lc;
|
||||
result.d = zc * lb + zd * ld;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>Constructor for a local bone matrix based on Setup Pose BoneData.</summary>
|
||||
public BoneMatrix (BoneData boneData) {
|
||||
var setup = boneData.GetSetupPose();
|
||||
float rotationY = setup.Rotation + 90 + setup.ShearY;
|
||||
float rotationX = setup.Rotation + setup.ShearX;
|
||||
|
||||
a = MathUtils.CosDeg(rotationX) * setup.ScaleX;
|
||||
c = MathUtils.SinDeg(rotationX) * setup.ScaleX;
|
||||
b = MathUtils.CosDeg(rotationY) * setup.ScaleY;
|
||||
d = MathUtils.SinDeg(rotationY) * setup.ScaleY;
|
||||
x = setup.X;
|
||||
y = setup.Y;
|
||||
}
|
||||
|
||||
/// <summary>Constructor for a local bone matrix based on a bone instance's current pose.</summary>
|
||||
public BoneMatrix (Bone bone) {
|
||||
var bonePose = bone.Pose;
|
||||
float rotationY = bonePose.Rotation + 90 + bonePose.ShearY;
|
||||
float rotationX = bonePose.Rotation + bonePose.ShearX;
|
||||
|
||||
a = MathUtils.CosDeg(rotationX) * bonePose.ScaleX;
|
||||
c = MathUtils.SinDeg(rotationX) * bonePose.ScaleX;
|
||||
b = MathUtils.CosDeg(rotationY) * bonePose.ScaleY;
|
||||
d = MathUtils.SinDeg(rotationY) * bonePose.ScaleY;
|
||||
x = bonePose.X;
|
||||
y = bonePose.Y;
|
||||
}
|
||||
|
||||
public BoneMatrix TransformMatrix (BoneMatrix local) {
|
||||
return new BoneMatrix {
|
||||
a = this.a * local.a + this.b * local.c,
|
||||
b = this.a * local.b + this.b * local.d,
|
||||
c = this.c * local.a + this.d * local.c,
|
||||
d = this.c * local.b + this.d * local.d,
|
||||
x = this.a * local.x + this.b * local.y + this.x,
|
||||
y = this.c * local.x + this.d * local.y + this.y
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpineSkeletonExtensions {
|
||||
public static bool IsWeighted (this VertexAttachment va) {
|
||||
return va.Bones != null && va.Bones.Length > 0;
|
||||
}
|
||||
|
||||
#region Inherit Modes
|
||||
public static bool InheritsRotation (this Inherit mode) {
|
||||
return mode == Inherit.Normal || mode == Inherit.NoScale || mode == Inherit.NoScaleOrReflection;
|
||||
}
|
||||
|
||||
public static bool InheritsScale (this Inherit mode) {
|
||||
return mode == Inherit.Normal || mode == Inherit.NoRotationOrReflection;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea85c8f6a91a6ab45881b0dbdaabb7d0
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
@@ -0,0 +1,159 @@
|
||||
/******************************************************************************
|
||||
* 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.AnimationTools {
|
||||
public static class TimelineExtensions {
|
||||
|
||||
/// <summary>Evaluates the resulting value of a TranslateTimeline at a given time.
|
||||
/// SkeletonData can be accessed from Skeleton.Data or from SkeletonDataAsset.GetSkeletonData.
|
||||
/// If no SkeletonData is provided, values are returned as difference to setup pose
|
||||
/// instead of absolute values.</summary>
|
||||
public static Vector2 Evaluate (this TranslateTimeline timeline, float time, SkeletonData skeletonData = null) {
|
||||
if (time < timeline.Frames[0]) return Vector2.zero;
|
||||
|
||||
float x, y;
|
||||
timeline.GetCurveValue(out x, out y, time);
|
||||
|
||||
if (skeletonData == null) {
|
||||
return new Vector2(x, y);
|
||||
} else {
|
||||
BoneData boneData = skeletonData.Bones.Items[timeline.BoneIndex];
|
||||
var setup = boneData.GetSetupPose();
|
||||
return new Vector2(setup.X + x, setup.Y + y);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Evaluates the resulting value of a pair of split translate timelines at a given time.
|
||||
/// SkeletonData can be accessed from Skeleton.Data or from SkeletonDataAsset.GetSkeletonData.
|
||||
/// If no SkeletonData is given, values are returned as difference to setup pose
|
||||
/// instead of absolute values.</summary>
|
||||
public static Vector2 Evaluate (TranslateXTimeline xTimeline, TranslateYTimeline yTimeline,
|
||||
float time, SkeletonData skeletonData = null) {
|
||||
|
||||
float x = 0, y = 0;
|
||||
if (xTimeline != null && time > xTimeline.Frames[0]) x = xTimeline.GetCurveValue(time);
|
||||
if (yTimeline != null && time > yTimeline.Frames[0]) y = yTimeline.GetCurveValue(time);
|
||||
|
||||
if (skeletonData == null) {
|
||||
return new Vector2(x, y);
|
||||
} else {
|
||||
BoneData[] bonesItems = skeletonData.Bones.Items;
|
||||
BoneData boneDataX = bonesItems[xTimeline.BoneIndex];
|
||||
BoneData boneDataY = bonesItems[yTimeline.BoneIndex];
|
||||
return new Vector2(boneDataX.GetSetupPose().X + x, boneDataY.GetSetupPose().Y + y);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Evaluates the resulting value of a RotateTimeline at a given time.
|
||||
/// SkeletonData can be accessed from Skeleton.Data or from SkeletonDataAsset.GetSkeletonData.
|
||||
/// If no SkeletonData is given, values are returned as difference to setup pose
|
||||
/// instead of absolute values.</summary>
|
||||
public static float Evaluate (this RotateTimeline timeline, float time, SkeletonData skeletonData = null) {
|
||||
if (time < timeline.Frames[0]) return 0f;
|
||||
|
||||
float rotation = timeline.GetCurveValue(time);
|
||||
if (skeletonData == null) {
|
||||
return rotation;
|
||||
} else {
|
||||
BoneData boneData = skeletonData.Bones.Items[timeline.BoneIndex];
|
||||
return (boneData.GetSetupPose().Rotation + rotation);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Evaluates the resulting X and Y translate mix values of a
|
||||
/// TransformConstraintTimeline at a given time.</summary>
|
||||
public static Vector2 EvaluateTranslateXYMix (this TransformConstraintTimeline timeline, float time) {
|
||||
if (time < timeline.Frames[0]) return Vector2.zero;
|
||||
|
||||
float rotate, mixX, mixY, scaleX, scaleY, shearY;
|
||||
timeline.GetCurveValue(out rotate, out mixX, out mixY, out scaleX, out scaleY, out shearY, time);
|
||||
return new Vector2(mixX, mixY);
|
||||
}
|
||||
|
||||
/// <summary>Evaluates the resulting rotate mix values of a
|
||||
/// TransformConstraintTimeline at a given time.</summary>
|
||||
public static float EvaluateRotateMix (this TransformConstraintTimeline timeline, float time) {
|
||||
if (time < timeline.Frames[0]) return 0;
|
||||
|
||||
float rotate, mixX, mixY, scaleX, scaleY, shearY;
|
||||
timeline.GetCurveValue(out rotate, out mixX, out mixY, out scaleX, out scaleY, out shearY, time);
|
||||
return rotate;
|
||||
}
|
||||
|
||||
/// <summary>Gets the translate timeline for a given boneIndex.
|
||||
/// You can get the boneIndex using SkeletonData.FindBone().Index.
|
||||
/// The root bone is always boneIndex 0.
|
||||
/// This will return null if a TranslateTimeline is not found.</summary>
|
||||
public static TranslateTimeline FindTranslateTimelineForBone (this Animation a, int boneIndex) {
|
||||
foreach (Timeline timeline in a.Timelines) {
|
||||
if (timeline.GetType().IsSubclassOf(typeof(TranslateTimeline)))
|
||||
continue;
|
||||
|
||||
TranslateTimeline translateTimeline = timeline as TranslateTimeline;
|
||||
if (translateTimeline != null && translateTimeline.BoneIndex == boneIndex)
|
||||
return translateTimeline;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Gets the IBoneTimeline timeline of a given type for a given boneIndex.
|
||||
/// You can get the boneIndex using SkeletonData.FindBoneIndex.
|
||||
/// The root bone is always boneIndex 0.
|
||||
/// This will return null if a timeline of the given type is not found.</summary>
|
||||
public static T FindTimelineForBone<T> (this Animation a, int boneIndex) where T : class, IBoneTimeline {
|
||||
foreach (Timeline timeline in a.Timelines) {
|
||||
T translateTimeline = timeline as T;
|
||||
if (translateTimeline != null && translateTimeline.BoneIndex == boneIndex)
|
||||
return translateTimeline;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Gets the transform constraint timeline for a given boneIndex.
|
||||
/// You can get the boneIndex using SkeletonData.FindBone().Index.
|
||||
/// The root bone is always boneIndex 0.
|
||||
/// This will return null if a TranslateTimeline is not found.</summary>
|
||||
public static TransformConstraintTimeline FindTransformConstraintTimeline (this Animation a, int transformConstraintIndex) {
|
||||
foreach (Timeline timeline in a.Timelines) {
|
||||
if (timeline.GetType().IsSubclassOf(typeof(TransformConstraintTimeline)))
|
||||
continue;
|
||||
|
||||
TransformConstraintTimeline transformConstraintTimeline = timeline as TransformConstraintTimeline;
|
||||
if (transformConstraintTimeline != null &&
|
||||
transformConstraintTimeline.ConstraintIndex == transformConstraintIndex)
|
||||
return transformConstraintTimeline;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07807fefbff25484ba41b1d16911fb0e
|
||||
timeCreated: 1591974498
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15ac4befbee15d845ac289de3ab6d3d4
|
||||
folderAsset: yes
|
||||
timeCreated: 1455486167
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/******************************************************************************
|
||||
* 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;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
/// <summary>
|
||||
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
|
||||
/// The routine will pause until the AnimationState.TrackEntry fires any of the
|
||||
/// configured events.
|
||||
/// <p/>
|
||||
/// See the <see cref="http://esotericsoftware.com/spine-unity-events">Spine Unity Events documentation page</see>
|
||||
/// and <see cref="http://esotericsoftware.com/spine-api-reference#AnimationStateListener"/>
|
||||
/// for more information on when track events will be triggered.</summary>
|
||||
public class WaitForSpineAnimation : IEnumerator {
|
||||
|
||||
[Flags]
|
||||
public enum AnimationEventTypes {
|
||||
Start = 1,
|
||||
Interrupt = 2,
|
||||
End = 4,
|
||||
Dispose = 8,
|
||||
Complete = 16
|
||||
}
|
||||
|
||||
bool m_WasFired = false;
|
||||
|
||||
public WaitForSpineAnimation (Spine.TrackEntry trackEntry, AnimationEventTypes eventsToWaitFor) {
|
||||
SafeSubscribe(trackEntry, eventsToWaitFor);
|
||||
}
|
||||
|
||||
#region Reuse
|
||||
/// <summary>
|
||||
/// One optimization high-frequency YieldInstruction returns is to cache instances to minimize GC pressure.
|
||||
/// Use NowWaitFor to reuse the same instance of WaitForSpineAnimationComplete.</summary>
|
||||
public WaitForSpineAnimation NowWaitFor (Spine.TrackEntry trackEntry, AnimationEventTypes eventsToWaitFor) {
|
||||
SafeSubscribe(trackEntry, eventsToWaitFor);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IEnumerator
|
||||
bool IEnumerator.MoveNext () {
|
||||
if (m_WasFired) {
|
||||
((IEnumerator)this).Reset(); // auto-reset for YieldInstruction reuse
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void IEnumerator.Reset () { m_WasFired = false; }
|
||||
object IEnumerator.Current { get { return null; } }
|
||||
#endregion
|
||||
|
||||
protected void SafeSubscribe (Spine.TrackEntry trackEntry, AnimationEventTypes eventsToWaitFor) {
|
||||
if (trackEntry == null) {
|
||||
// Break immediately if trackEntry is null.
|
||||
Debug.LogWarning("TrackEntry was null. Coroutine will continue immediately.");
|
||||
m_WasFired = true;
|
||||
} else {
|
||||
if ((eventsToWaitFor & AnimationEventTypes.Start) != 0)
|
||||
trackEntry.Start += HandleComplete;
|
||||
if ((eventsToWaitFor & AnimationEventTypes.Interrupt) != 0)
|
||||
trackEntry.Interrupt += HandleComplete;
|
||||
if ((eventsToWaitFor & AnimationEventTypes.End) != 0)
|
||||
trackEntry.End += HandleComplete;
|
||||
if ((eventsToWaitFor & AnimationEventTypes.Dispose) != 0)
|
||||
trackEntry.Dispose += HandleComplete;
|
||||
if ((eventsToWaitFor & AnimationEventTypes.Complete) != 0)
|
||||
trackEntry.Complete += HandleComplete;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleComplete (TrackEntry trackEntry) {
|
||||
m_WasFired = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9be5adcaf0003849a1d181173c19635
|
||||
timeCreated: 1566289729
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
/******************************************************************************
|
||||
* 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 Spine;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
/// <summary>
|
||||
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
|
||||
/// The routine will pause until the AnimationState.TrackEntry fires its Complete event.
|
||||
/// It can be configured to trigger on the End event as well to cover interruption.
|
||||
/// <p/>
|
||||
/// See the <see cref="http://esotericsoftware.com/spine-unity-events">Spine Unity Events documentation page</see>
|
||||
/// and <see cref="http://esotericsoftware.com/spine-api-reference#AnimationStateListener"/>
|
||||
/// for more information on when track events will be triggered.</summary>
|
||||
public class WaitForSpineAnimationComplete : WaitForSpineAnimation, IEnumerator {
|
||||
|
||||
public WaitForSpineAnimationComplete (Spine.TrackEntry trackEntry, bool includeEndEvent = false) :
|
||||
base(trackEntry,
|
||||
includeEndEvent ? (AnimationEventTypes.Complete | AnimationEventTypes.End) : AnimationEventTypes.Complete) {
|
||||
}
|
||||
|
||||
#region Reuse
|
||||
/// <summary>
|
||||
/// One optimization high-frequency YieldInstruction returns is to cache instances to minimize GC pressure.
|
||||
/// Use NowWaitFor to reuse the same instance of WaitForSpineAnimationComplete.</summary>
|
||||
public WaitForSpineAnimationComplete NowWaitFor (Spine.TrackEntry trackEntry, bool includeEndEvent = false) {
|
||||
SafeSubscribe(trackEntry,
|
||||
includeEndEvent ? (AnimationEventTypes.Complete | AnimationEventTypes.End) : AnimationEventTypes.Complete);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a807dd9fb79db3545b6c2859a2bbfc0b
|
||||
timeCreated: 1449704018
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/******************************************************************************
|
||||
* 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 Spine;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
/// <summary>
|
||||
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
|
||||
/// The routine will pause until the AnimationState.TrackEntry fires its End event.
|
||||
/// <p/>
|
||||
/// See the <see cref="http://esotericsoftware.com/spine-unity-events">Spine Unity Events documentation page</see>
|
||||
/// and <see cref="http://esotericsoftware.com/spine-api-reference#AnimationStateListener"/>
|
||||
/// for more information on when track events will be triggered.</summary>
|
||||
public class WaitForSpineAnimationEnd : WaitForSpineAnimation, IEnumerator {
|
||||
|
||||
public WaitForSpineAnimationEnd (Spine.TrackEntry trackEntry) :
|
||||
base(trackEntry, AnimationEventTypes.End) {
|
||||
}
|
||||
|
||||
#region Reuse
|
||||
/// <summary>
|
||||
/// One optimization high-frequency YieldInstruction returns is to cache instances to minimize GC pressure.
|
||||
/// Use NowWaitFor to reuse the same instance of WaitForSpineAnimationComplete.</summary>
|
||||
public WaitForSpineAnimationEnd NowWaitFor (Spine.TrackEntry trackEntry) {
|
||||
SafeSubscribe(trackEntry, AnimationEventTypes.End);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c5a5fe930d1ab24da154d76b24c2747
|
||||
timeCreated: 1566288961
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
/******************************************************************************
|
||||
* 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 Spine;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
/// <summary>
|
||||
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
|
||||
/// The routine will pause until the AnimationState fires an event matching the given event name or EventData reference.</summary>
|
||||
public class WaitForSpineEvent : IEnumerator {
|
||||
|
||||
Spine.EventData m_TargetEvent;
|
||||
string m_EventName;
|
||||
Spine.AnimationState m_AnimationState;
|
||||
|
||||
bool m_WasFired = false;
|
||||
bool m_unsubscribeAfterFiring = false;
|
||||
|
||||
#region Constructors
|
||||
void Subscribe (Spine.AnimationState state, Spine.EventData eventDataReference, bool unsubscribe) {
|
||||
if (state == null) {
|
||||
Debug.LogWarning("AnimationState argument was null. Coroutine will continue immediately.");
|
||||
m_WasFired = true;
|
||||
return;
|
||||
} else if (eventDataReference == null) {
|
||||
Debug.LogWarning("eventDataReference argument was null. Coroutine will continue immediately.");
|
||||
m_WasFired = true;
|
||||
return;
|
||||
}
|
||||
|
||||
m_AnimationState = state;
|
||||
m_TargetEvent = eventDataReference;
|
||||
state.Event += HandleAnimationStateEvent;
|
||||
|
||||
m_unsubscribeAfterFiring = unsubscribe;
|
||||
|
||||
}
|
||||
|
||||
void SubscribeByName (Spine.AnimationState state, string eventName, bool unsubscribe) {
|
||||
if (state == null) {
|
||||
Debug.LogWarning("AnimationState argument was null. Coroutine will continue immediately.");
|
||||
m_WasFired = true;
|
||||
return;
|
||||
} else if (string.IsNullOrEmpty(eventName)) {
|
||||
Debug.LogWarning("eventName argument was null. Coroutine will continue immediately.");
|
||||
m_WasFired = true;
|
||||
return;
|
||||
}
|
||||
|
||||
m_AnimationState = state;
|
||||
m_EventName = eventName;
|
||||
state.Event += HandleAnimationStateEventByName;
|
||||
|
||||
m_unsubscribeAfterFiring = unsubscribe;
|
||||
}
|
||||
|
||||
public WaitForSpineEvent (Spine.AnimationState state, Spine.EventData eventDataReference, bool unsubscribeAfterFiring = true) {
|
||||
Subscribe(state, eventDataReference, unsubscribeAfterFiring);
|
||||
}
|
||||
|
||||
public WaitForSpineEvent (SkeletonAnimation skeletonAnimation, Spine.EventData eventDataReference, bool unsubscribeAfterFiring = true) {
|
||||
// If skeletonAnimation is invalid, its state will be null. Subscribe handles null states just fine.
|
||||
Subscribe(skeletonAnimation.AnimationState, eventDataReference, unsubscribeAfterFiring);
|
||||
}
|
||||
|
||||
public WaitForSpineEvent (Spine.AnimationState state, string eventName, bool unsubscribeAfterFiring = true) {
|
||||
SubscribeByName(state, eventName, unsubscribeAfterFiring);
|
||||
}
|
||||
|
||||
public WaitForSpineEvent (SkeletonAnimation skeletonAnimation, string eventName, bool unsubscribeAfterFiring = true) {
|
||||
// If skeletonAnimation is invalid, its state will be null. Subscribe handles null states just fine.
|
||||
SubscribeByName(skeletonAnimation.AnimationState, eventName, unsubscribeAfterFiring);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Event Handlers
|
||||
void HandleAnimationStateEventByName (Spine.TrackEntry trackEntry, Spine.Event e) {
|
||||
m_WasFired |= (e.Data.Name == m_EventName); // Check event name string match.
|
||||
if (m_WasFired && m_unsubscribeAfterFiring)
|
||||
m_AnimationState.Event -= HandleAnimationStateEventByName; // Unsubscribe after correct event fires.
|
||||
}
|
||||
|
||||
void HandleAnimationStateEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
|
||||
m_WasFired |= (e.Data == m_TargetEvent); // Check event data reference match.
|
||||
if (m_WasFired && m_unsubscribeAfterFiring)
|
||||
m_AnimationState.Event -= HandleAnimationStateEvent; // Usubscribe after correct event fires.
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Reuse
|
||||
/// <summary>
|
||||
/// By default, WaitForSpineEvent will unsubscribe from the event immediately after it fires a correct matching event.
|
||||
/// If you want to reuse this WaitForSpineEvent instance on the same event, you can set this to false.</summary>
|
||||
public bool WillUnsubscribeAfterFiring { get { return m_unsubscribeAfterFiring; } set { m_unsubscribeAfterFiring = value; } }
|
||||
|
||||
public WaitForSpineEvent NowWaitFor (Spine.AnimationState state, Spine.EventData eventDataReference, bool unsubscribeAfterFiring = true) {
|
||||
((IEnumerator)this).Reset();
|
||||
Clear(state);
|
||||
Subscribe(state, eventDataReference, unsubscribeAfterFiring);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public WaitForSpineEvent NowWaitFor (Spine.AnimationState state, string eventName, bool unsubscribeAfterFiring = true) {
|
||||
((IEnumerator)this).Reset();
|
||||
Clear(state);
|
||||
SubscribeByName(state, eventName, unsubscribeAfterFiring);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void Clear (Spine.AnimationState state) {
|
||||
state.Event -= HandleAnimationStateEvent;
|
||||
state.Event -= HandleAnimationStateEventByName;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IEnumerator
|
||||
bool IEnumerator.MoveNext () {
|
||||
if (m_WasFired) {
|
||||
((IEnumerator)this).Reset(); // auto-reset for YieldInstruction reuse
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void IEnumerator.Reset () { m_WasFired = false; }
|
||||
object IEnumerator.Current { get { return null; } }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc166d883db083e469872998172f2d38
|
||||
timeCreated: 1449701857
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
/******************************************************************************
|
||||
* 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 Spine;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity {
|
||||
/// <summary>
|
||||
/// Use this as a condition-blocking yield instruction for Unity Coroutines.
|
||||
/// The routine will pause until the AnimationState.TrackEntry fires its End event.</summary>
|
||||
public class WaitForSpineTrackEntryEnd : IEnumerator {
|
||||
|
||||
bool m_WasFired = false;
|
||||
|
||||
public WaitForSpineTrackEntryEnd (Spine.TrackEntry trackEntry) {
|
||||
SafeSubscribe(trackEntry);
|
||||
}
|
||||
|
||||
void HandleEnd (TrackEntry trackEntry) {
|
||||
m_WasFired = true;
|
||||
}
|
||||
|
||||
void SafeSubscribe (Spine.TrackEntry trackEntry) {
|
||||
if (trackEntry == null) {
|
||||
// Break immediately if trackEntry is null.
|
||||
Debug.LogWarning("TrackEntry was null. Coroutine will continue immediately.");
|
||||
m_WasFired = true;
|
||||
} else {
|
||||
trackEntry.End += HandleEnd;
|
||||
}
|
||||
}
|
||||
|
||||
#region Reuse
|
||||
/// <summary>
|
||||
/// One optimization high-frequency YieldInstruction returns is to cache instances to minimize GC pressure.
|
||||
/// Use NowWaitFor to reuse the same instance of WaitForSpineAnimationEnd.</summary>
|
||||
public WaitForSpineTrackEntryEnd NowWaitFor (Spine.TrackEntry trackEntry) {
|
||||
SafeSubscribe(trackEntry);
|
||||
return this;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IEnumerator
|
||||
bool IEnumerator.MoveNext () {
|
||||
if (m_WasFired) {
|
||||
((IEnumerator)this).Reset(); // auto-reset for YieldInstruction reuse
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void IEnumerator.Reset () { m_WasFired = false; }
|
||||
object IEnumerator.Current { get { return null; } }
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8036c6c2897d2764db92f632d2aef568
|
||||
timeCreated: 1480672707
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user