diff --git a/CHANGELOG.md b/CHANGELOG.md index ed1be63129..f504cf4323 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -122,7 +122,7 @@ ### Unity -- **Officially supported Unity versions are 2017.1-2022.1**. +- **Officially supported Unity versions are 2017.1-2023.1**. - **Additions** @@ -161,6 +161,7 @@ - Added support for BlendModeMaterials at runtime instantiation from files via an additional method `SkeletonDataAsset.SetupRuntimeBlendModeMaterials`. See example scene `Spine Examples/Other Examples/Instantiate from Script` for a usage example. - SkeletonGraphic: You can now offset the skeleton mesh relative to the pivot via a newly added green circle handle. This allows you to e.g. frame only the face of a skeleton inside a masked frame. Previously offsetting the pivot downwards fails when `Layout Scale Mode` scales the mesh smaller and towards the pivot (e.g. the feet) and thus out of the frame. Now you can keep the pivot in the center of the `RectTransform` while offsetting only the mesh downwards, keeping the desired skeleton area (e.g. the face) centered while resizing. Moving the new larger green circle handle moves the mesh offset, while moving the blue pivot circle handle moves the pivot as usual. - `Universal Render Pipeline/Spine/Skeleton` shader now performs proper alpha-testing when `Depth Write` is enabled, using the existing `Shadow alpha cutoff` parameter. + - `SkeletonRootMotion` components now provide a public `Initialize()` method which is automatically called when calling `skeletonAnimation.Initialize(true)` to update the necessary skeleton references. If a different root bone shall be used, be sure to set `skeletonRootMotion.rootMotionBoneName` before calling `skeletonAnimation.Initialize(true)`. - **Breaking changes** @@ -173,6 +174,7 @@ - Inspector: String attribute `SpineSkin()` now allows to include `` in the list of parameters. Previously the `includeNone=true` parameter of the `SpineSkin()` attribute defaulted to `true` but was ignored. Now it defaults to `false` and has an effect on the list. Only the Inspector GUI is affected by this behaviour change. - `SkeletonGraphicRenderTexture` example component: `protected RawImage quadRawImage` was changed to `protected SkeletonSubmeshGraphic quadMaskableGraphic` for a bugfix. This is only relevant for subclasses of `SkeletonGraphicRenderTexture` or when querying the `RawImage` component via e.g. `skeletonGraphicRenderTexture.quad.GetComponent()`. - Fixed a bug where when Linear color space is used and `PMA vertex colors` enabled, additive slots add a too dark (too transparent) color value. If you want the old incorrect behaviour (darker additive slots) or are not using Linear but Gamma color space, you can comment-out the define `LINEAR_COLOR_SPACE_FIX_ADDITIVE_ALPHA` in `MeshGenerator.cs` to deactivate the fix or just to skip unnecessary instructions. + - Fixed SkeletonRootMotion components ignoring parent bone scale when set by transform constraints. Using applied scale of parent bone now. If you need the old behaviour, comment out the line `#define USE_APPLIED_PARENT_SCALE` in SkeletonRootMotionBase.cs. - **Changes of default values** diff --git a/spine-csharp/src/PhysicsConstraint.cs b/spine-csharp/src/PhysicsConstraint.cs index 4221b0aec0..1ab3000a9a 100644 --- a/spine-csharp/src/PhysicsConstraint.cs +++ b/spine-csharp/src/PhysicsConstraint.cs @@ -147,6 +147,7 @@ public void Update (Physics physics) { Reset(); goto case Physics.Update; // Fall through. case Physics.Update: + Skeleton skeleton = this.skeleton; float delta = Math.Max(skeleton.time - lastTime, 0); remaining += delta; lastTime = skeleton.time; @@ -157,21 +158,24 @@ public void Update (Physics physics) { ux = bx; uy = by; } else { - float a = this.remaining, i = inertia, q = data.limit * delta, t = data.step, f = skeleton.data.referenceScale; + float a = remaining, i = inertia, t = data.step, f = skeleton.data.referenceScale, d = -1; + float qx = data.limit * delta, qy = qx * Math.Abs(skeleton.ScaleY); + qx *= Math.Abs(skeleton.ScaleX); + if (x || y) { if (x) { float u = (ux - bx) * i; - xOffset += u > q ? q : u < -q ? -q : u; + xOffset += u > qx ? qx : u < -qx ? -qx : u; ux = bx; } if (y) { float u = (uy - by) * i; - yOffset += u > q ? q : u < -q ? -q : u; + yOffset += u > qy ? qy : u < -qy ? -qy : u; uy = by; } if (a >= t) { + d = (float)Math.Pow(damping, 60 * t); float m = massInverse * t, e = strength, w = wind * f, g = (Bone.yDown ? -gravity : gravity) * f; - float d = (float)Math.Pow(damping, 60 * t); do { if (x) { xVelocity += (w - xOffset * e) * m; @@ -192,14 +196,14 @@ public void Update (Physics physics) { if (rotateOrShearX || scaleX) { float ca = (float)Math.Atan2(bone.c, bone.a), c, s, mr = 0; float dx = cx - bone.worldX, dy = cy - bone.worldY; - if (dx > q) - dx = q; - else if (dx < -q) - dx = -q; - if (dy > q) - dy = q; - else if (dy < -q) - dy = -q; + if (dx > qx) + dx = qx; + else if (dx < -qx) + dx = -qx; + if (dy > qy) + dy = qy; + else if (dy < -qy) + dy = -qy; if (rotateOrShearX) { mr = (data.rotate + data.shearX) * mix; float r = (float)Math.Atan2(dy + ty, dx + tx) - ca - rotateOffset * mr; @@ -217,10 +221,10 @@ public void Update (Physics physics) { float r = l * bone.WorldScaleX; if (r > 0) scaleOffset += (dx * c + dy * s) * i / r; } - a = this.remaining; + a = remaining; if (a >= t) { - float m = massInverse * t, e = strength, w = wind, g = (Bone.yDown ? -gravity : gravity); - float d = (float)Math.Pow(damping, 60 * t), h = l / f; + if (d == -1) d = (float)Math.Pow(damping, 60 * t); + float m = massInverse * t, e = strength, w = wind, g = (Bone.yDown ? -gravity : gravity), h = l / f; while (true) { a -= t; if (scaleX) { @@ -241,7 +245,7 @@ public void Update (Physics physics) { } } } - this.remaining = a; + remaining = a; } cx = bone.worldX; cy = bone.worldY; @@ -295,7 +299,7 @@ public void Update (Physics physics) { } /// The bone constrained by this physics constraint. - public Bone Bone { get {return bone;} set { bone = value; } } + public Bone Bone { get { return bone; } set { bone = value; } } public float Inertia { get { return inertia; } set { inertia = value; } } public float Strength { get { return strength; } set { strength = value; } } public float Damping { get { return damping; } set { damping = value; } } diff --git a/spine-csharp/src/package.json b/spine-csharp/src/package.json index c52b7612f9..967424a880 100644 --- a/spine-csharp/src/package.json +++ b/spine-csharp/src/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.spine-csharp", "displayName": "spine-csharp Runtime", "description": "This plugin provides the spine-csharp core runtime.", - "version": "4.2.25", + "version": "4.2.27", "unity": "2018.3", "author": { "name": "Esoteric Software", diff --git a/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx b/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx index e660d15638..19d92c384f 100644 --- a/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx +++ b/spine-haxe/spine-haxe/spine/PhysicsConstraint.hx @@ -32,7 +32,7 @@ package spine; class PhysicsConstraint implements Updatable { private var _data:PhysicsConstraintData; private var _bone:Bone = null; - + public var inertia:Float = 0; public var strength:Float = 0; public var damping:Float = 0; @@ -63,7 +63,7 @@ class PhysicsConstraint implements Updatable { private var _skeleton:Skeleton; public var remaining:Float = 0; public var lastTime:Float = 0; - + public function new(data: PhysicsConstraintData, skeleton: Skeleton) { _data = data; _skeleton = skeleton; @@ -123,7 +123,7 @@ class PhysicsConstraint implements Updatable { return; case Physics.reset, Physics.update: if (physics == Physics.reset) reset(); - + var delta:Float = Math.max(skeleton.time - lastTime, 0); remaining += delta; lastTime = _skeleton.time; @@ -136,19 +136,22 @@ class PhysicsConstraint implements Updatable { } else { var a:Float = remaining, i:Float = inertia, - q:Float = _data.limit * delta, t:Float = _data.step, f:Float = skeleton.data.referenceScale, d:Float = -1; + + var qx:Float = _data.limit * delta, + qy:Float = qx * Math.abs(skeleton.scaleY); + qx *= Math.abs(skeleton.scaleX); if (x || y) { if (x) { var u:Float = (ux - bx) * i; - xOffset += u > q ? q : u < -q ? -q : u; + xOffset += u > qx ? qx : u < -qx ? -qx : u; ux = bx; } if (y) { var u:Float = (uy - by) * i; - yOffset += u > q ? q : u < -q ? -q : u; + yOffset += u > qy ? qy : u < -qy ? -qy : u; uy = by; } if (a >= t) { @@ -181,14 +184,14 @@ class PhysicsConstraint implements Updatable { mr:Float = 0; var dx:Float = cx - bone.worldX, dy:Float = cy - bone.worldY; - if (dx > q) - dx = q; - else if (dx < -q) // - dx = -q; - if (dy > q) - dy = q; - else if (dy < -q) // - dy = -q; + if (dx > qx) + dx = qx; + else if (dx < -qx) // + dx = -qx; + if (dy > qy) + dy = qy; + else if (dy < -qy) // + dy = -qy; if (rotateOrShearX) { mr = (_data.rotate + _data.shearX) * mix; var r:Float = Math.atan2(dy + ty, dx + tx) - ca - rotateOffset * mr; diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java index dcb28f6848..87fb116d5c 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java @@ -141,6 +141,7 @@ public void update (Physics physics) { reset(); // Fall through. case update: + Skeleton skeleton = this.skeleton; float delta = Math.max(skeleton.time - lastTime, 0); remaining += delta; lastTime = skeleton.time; @@ -151,16 +152,18 @@ public void update (Physics physics) { ux = bx; uy = by; } else { - float a = remaining, i = inertia, q = data.limit * delta, t = data.step, f = skeleton.data.referenceScale, d = -1; + float a = remaining, i = inertia, t = data.step, f = skeleton.data.referenceScale, d = -1; + float qx = data.limit * delta, qy = qx * Math.abs(skeleton.scaleY); + qx *= Math.abs(skeleton.scaleX); if (x || y) { if (x) { float u = (ux - bx) * i; - xOffset += u > q ? q : u < -q ? -q : u; + xOffset += u > qx ? qx : u < -qx ? -qx : u; ux = bx; } if (y) { float u = (uy - by) * i; - yOffset += u > q ? q : u < -q ? -q : u; + yOffset += u > qy ? qy : u < -qy ? -qy : u; uy = by; } if (a >= t) { @@ -186,14 +189,14 @@ public void update (Physics physics) { if (rotateOrShearX || scaleX) { float ca = atan2(bone.c, bone.a), c, s, mr = 0; float dx = cx - bone.worldX, dy = cy - bone.worldY; - if (dx > q) - dx = q; - else if (dx < -q) // - dx = -q; - if (dy > q) - dy = q; - else if (dy < -q) // - dy = -q; + if (dx > qx) + dx = qx; + else if (dx < -qx) // + dx = -qx; + if (dy > qy) + dy = qy; + else if (dy < -qy) // + dy = -qy; if (rotateOrShearX) { mr = (data.rotate + data.shearX) * mix; float r = atan2(dy + ty, dx + tx) - ca - rotateOffset * mr; diff --git a/spine-ts/spine-core/src/PhysicsConstraint.ts b/spine-ts/spine-core/src/PhysicsConstraint.ts index d90493e53a..2870ecbf7e 100644 --- a/spine-ts/spine-core/src/PhysicsConstraint.ts +++ b/spine-ts/spine-core/src/PhysicsConstraint.ts @@ -136,9 +136,10 @@ export class PhysicsConstraint implements Updatable { this.reset(); // Fall through. case Physics.update: + const skeleton = this.skeleton; const delta = Math.max(this.skeleton.time - this.lastTime, 0); this.remaining += delta; - this.lastTime = this.skeleton.time; + this.lastTime = skeleton.time; const bx = bone.worldX, by = bone.worldY; if (this._reset) { @@ -146,16 +147,18 @@ export class PhysicsConstraint implements Updatable { this.ux = bx; this.uy = by; } else { - let a = this.remaining, i = this.inertia, q = this.data.limit * delta, t = this.data.step, f = this.skeleton.data.referenceScale, d = -1; + let a = this.remaining, i = this.inertia, t = this.data.step, f = this.skeleton.data.referenceScale, d = -1; + let qx = this.data.limit * delta, qy = qx * Math.abs(skeleton.scaleY); + qx *= Math.abs(skeleton.scaleX); if (x || y) { if (x) { const u = (this.ux - bx) * i; - this.xOffset += u > q ? q : u < -q ? -q : u; + this.xOffset += u > qx ? qx : u < -qx ? -qx : u; this.ux = bx; } if (y) { const u = (this.uy - by) * i; - this.yOffset += u > q ? q : u < -q ? -q : u; + this.yOffset += u > qy ? qy : u < -qy ? -qy : u; this.uy = by; } if (a >= t) { @@ -181,14 +184,14 @@ export class PhysicsConstraint implements Updatable { if (rotateOrShearX || scaleX) { let ca = Math.atan2(bone.c, bone.a), c = 0, s = 0, mr = 0; let dx = this.cx - bone.worldX, dy = this.cy - bone.worldY; - if (dx > q) - dx = q; - else if (dx < -q) // - dx = -q; - if (dy > q) - dy = q; - else if (dy < -q) // - dy = -q; + if (dx > qx) + dx = qx; + else if (dx < -qx) // + dx = -qx; + if (dy > qy) + dy = qy; + else if (dy < -qy) // + dy = -qy; if (rotateOrShearX) { mr = (this.data.rotate + this.data.shearX) * mix; let r = Math.atan2(dy + this.ty, dx + this.tx) - ca - this.rotateOffset * mr; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs index 4dbc7d2f16..4e031166ee 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs @@ -88,8 +88,8 @@ protected override void Reset () { mecanimLayerFlags = DefaultMecanimLayerFlags; } - protected override void Start () { - base.Start(); + public override void Initialize () { + base.Initialize(); skeletonMecanim = GetComponent(); if (skeletonMecanim) { skeletonMecanim.Translator.OnClipApplied -= OnClipApplied; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs index 6bc6c0b602..2086c3e2a3 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs @@ -88,8 +88,8 @@ protected override void Reset () { animationTrackFlags = DefaultAnimationTrackFlags; } - protected override void Start () { - base.Start(); + public override void Initialize () { + base.Initialize(); IAnimationStateComponent animstateComponent = skeletonComponent as IAnimationStateComponent; this.animationState = (animstateComponent != null) ? animstateComponent.AnimationState : null; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs index a85b077ba0..7559a70390 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs @@ -27,6 +27,12 @@ * SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +// In order to respect TransformConstraints modifying the scale of parent bones, +// GetScaleAffectingRootMotion() now uses parentBone.AScaleX and AScaleY instead +// of previously used ScaleX and ScaleY. If you require the previous behaviour, +// comment out the define below. +#define USE_APPLIED_PARENT_SCALE + using Spine.Unity.AnimationTools; using System; using System.Collections.Generic; @@ -42,8 +48,7 @@ abstract public class SkeletonRootMotionBase : MonoBehaviour { #region Inspector [SpineBone] - [SerializeField] - protected string rootMotionBoneName = "root"; + public string rootMotionBoneName = "root"; public bool transformPositionX = true; public bool transformPositionY = true; public bool transformRotation = false; @@ -155,6 +160,14 @@ protected virtual void Reset () { } protected virtual void Start () { + Initialize(); + } + + protected void InitializeOnRebuild (ISkeletonAnimation animatedSkeletonComponent) { + Initialize(); + } + + public virtual void Initialize () { skeletonComponent = GetComponent(); GatherTopLevelBones(); SetRootMotionBone(rootMotionBoneName); @@ -167,6 +180,9 @@ protected virtual void Start () { if (skeletonAnimation != null) { skeletonAnimation.UpdateLocal -= HandleUpdateLocal; skeletonAnimation.UpdateLocal += HandleUpdateLocal; + + skeletonAnimation.OnAnimationRebuild -= InitializeOnRebuild; + skeletonAnimation.OnAnimationRebuild += InitializeOnRebuild; } } @@ -198,6 +214,13 @@ protected virtual void PhysicsUpdate (bool skeletonAnimationUsesFixedUpdate) { } Vector2 rigidbodyDisplacement2D = new Vector2(rigidbodyDisplacement.x, rigidbodyDisplacement.y); + // Note: MovePosition seems to be the only precise and reliable way to set movement delta, + // for both 2D and 3D rigidbodies. + // Setting velocity like "rigidBody2D.velocity = movement/deltaTime" works perfectly in mid-air + // without gravity and ground collision, unfortunately when on the ground, friction causes severe + // slowdown. Using a zero-friction PhysicsMaterial leads to sliding endlessly along the ground as + // soon as forces are applied. Additionally, there is no rigidBody2D.isGrounded, requiring our own + // checks. rigidBody2D.MovePosition(gravityAndVelocityMovement + new Vector2(rigidBody2D.position.x, rigidBody2D.position.y) + rigidbodyDisplacement2D + additionalRigidbody2DMovement); rigidBody2D.MoveRotation(rigidbody2DRotation + rigidBody2D.rotation); @@ -271,7 +294,8 @@ public void SetRootMotionBone (string name) { this.rootMotionBone = bone; FindTransformConstraintsAffectingBone(); } else { - Debug.Log("Bone named \"" + name + "\" could not be found."); + Debug.Log("Bone named \"" + name + "\" could not be found. " + + "Set 'skeletonRootMotion.rootMotionBoneName' before calling 'skeletonAnimation.Initialize(true)'."); this.rootMotionBoneIndex = 0; this.rootMotionBone = skeleton.RootBone; } @@ -623,8 +647,13 @@ Vector2 GetScaleAffectingRootMotion (out Vector2 parentBoneScale) { parentBoneScale = Vector2.one; Bone scaleBone = rootMotionBone; while ((scaleBone = scaleBone.Parent) != null) { +#if USE_APPLIED_PARENT_SCALE + parentBoneScale.x *= scaleBone.AScaleX; + parentBoneScale.y *= scaleBone.AScaleY; +#else parentBoneScale.x *= scaleBone.ScaleX; parentBoneScale.y *= scaleBone.ScaleY; +#endif } totalScale = Vector2.Scale(totalScale, parentBoneScale); totalScale *= AdditionalScale; diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index a94a81c489..4e722c65b2 100644 --- a/spine-unity/Assets/Spine/package.json +++ b/spine-unity/Assets/Spine/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.spine-unity", "displayName": "spine-unity Runtime", "description": "This plugin provides the spine-unity runtime core.", - "version": "4.2.76", + "version": "4.2.78", "unity": "2018.3", "author": { "name": "Esoteric Software",