diff --git a/spine-unity/Assets/Spine Examples/Scripts/RaggedySpineboy.cs b/spine-unity/Assets/Spine Examples/Scripts/RaggedySpineboy.cs index 025c4c029..4ae8eb3ec 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/RaggedySpineboy.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/RaggedySpineboy.cs @@ -27,6 +27,10 @@ * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +#if UNITY_2023_1_OR_NEWER +#define USE_COLLIDER_COMPOSITE_OPERATION +#endif + using Spine.Unity; using System.Collections; using UnityEngine; @@ -65,7 +69,7 @@ namespace Spine.Unity.Examples { void Launch () { RemoveRigidbody(); ragdoll.Apply(); - ragdoll.RootRigidbody.velocity = new Vector2(Random.Range(-launchVelocity.x, launchVelocity.x), launchVelocity.y); + ragdoll.RootRigidbody.linearVelocity = new Vector2(Random.Range(-launchVelocity.x, launchVelocity.x), launchVelocity.y); StartCoroutine(WaitUntilStopped()); } @@ -78,7 +82,11 @@ namespace Spine.Unity.Examples { if (hit.collider != null) skeletonPoint = hit.point; +#if USE_COLLIDER_COMPOSITE_OPERATION + ragdoll.RootRigidbody.bodyType = RigidbodyType2D.Kinematic; +#else ragdoll.RootRigidbody.isKinematic = true; +#endif ragdoll.SetSkeletonPosition(skeletonPoint); yield return ragdoll.SmoothMix(0, restoreDuration); @@ -92,7 +100,7 @@ namespace Spine.Unity.Examples { float t = 0; while (t < 0.5f) { - t = (ragdoll.RootRigidbody.velocity.magnitude > 0.09f) ? 0 : t + Time.deltaTime; + t = (ragdoll.RootRigidbody.linearVelocity.magnitude > 0.09f) ? 0 : t + Time.deltaTime; yield return null; } diff --git a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonUtility Modules/SkeletonRagdoll2D.cs b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonUtility Modules/SkeletonRagdoll2D.cs index de07a7851..29038cf64 100644 --- a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonUtility Modules/SkeletonRagdoll2D.cs +++ b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/SkeletonUtility Modules/SkeletonRagdoll2D.cs @@ -33,6 +33,10 @@ #define HINGE_JOINT_2019_BEHAVIOUR #endif +#if UNITY_2023_1_OR_NEWER +#define USE_COLLIDER_COMPOSITE_OPERATION +#endif + using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -140,7 +144,11 @@ namespace Spine.Unity.Examples { RecursivelyCreateBoneProxies(startingBone); RootRigidbody = boneTable[startingBone].GetComponent(); +#if USE_COLLIDER_COMPOSITE_OPERATION + RootRigidbody.bodyType = pinStartBone ? RigidbodyType2D.Kinematic : RigidbodyType2D.Dynamic; +#else RootRigidbody.isKinematic = pinStartBone; +#endif RootRigidbody.mass = rootMass; List boneColliders = new List(); foreach (KeyValuePair pair in boneTable) { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/EditorSkeletonPlayer.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/EditorSkeletonPlayer.cs index f94f4891c..0bfa0be97 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/EditorSkeletonPlayer.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/EditorSkeletonPlayer.cs @@ -27,6 +27,10 @@ * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +#if UNITY_2022_2_OR_NEWER +#define USE_FIND_OBJECTS_BY_TYPE +#endif + #if UNITY_EDITOR using UnityEditor; using UnityEditor.Callbacks; @@ -54,7 +58,11 @@ namespace Spine.Unity { [DidReloadScripts] private static void OnReloaded () { // Force start when scripts are reloaded +#if USE_FIND_OBJECTS_BY_TYPE + EditorSkeletonPlayer[] editorSpineAnimations = FindObjectsByType(FindObjectsSortMode.None); +#else EditorSkeletonPlayer[] editorSpineAnimations = FindObjectsOfType(); +#endif foreach (EditorSkeletonPlayer editorSpineAnimation in editorSpineAnimations) editorSpineAnimation.Start(); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollower.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollower.cs index bc0ec0704..151542dbb 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollower.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollower.cs @@ -31,6 +31,10 @@ #define NEW_PREFAB_SYSTEM #endif +#if UNITY_2023_1_OR_NEWER +#define USE_COLLIDER_COMPOSITE_OPERATION +#endif + using System.Collections.Generic; using UnityEngine; @@ -165,7 +169,12 @@ namespace Spine.Unity { SkeletonUtility.SetColliderPointsLocal(bbCollider, slot, boundingBoxAttachment); bbCollider.isTrigger = isTrigger; bbCollider.usedByEffector = usedByEffector; +#if USE_COLLIDER_COMPOSITE_OPERATION + bbCollider.compositeOperation = usedByComposite ? + Collider2D.CompositeOperation.Merge : Collider2D.CompositeOperation.None; +#else bbCollider.usedByComposite = usedByComposite; +#endif bbCollider.enabled = false; bbCollider.hideFlags = HideFlags.NotEditable; colliderTable.Add(boundingBoxAttachment, bbCollider); @@ -205,7 +214,7 @@ namespace Spine.Unity { DestroyImmediate(collider); else #endif - Destroy(collider); + Destroy(collider); } } } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollowerGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollowerGraphic.cs index a8648cd51..16954a560 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollowerGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/Following/BoundingBoxFollowerGraphic.cs @@ -31,6 +31,10 @@ #define NEW_PREFAB_SYSTEM #endif +#if UNITY_2023_1_OR_NEWER +#define USE_COLLIDER_COMPOSITE_OPERATION +#endif + using System.Collections.Generic; using UnityEngine; @@ -166,7 +170,12 @@ namespace Spine.Unity { SkeletonUtility.SetColliderPointsLocal(bbCollider, slot, boundingBoxAttachment, scale); bbCollider.isTrigger = isTrigger; bbCollider.usedByEffector = usedByEffector; +#if USE_COLLIDER_COMPOSITE_OPERATION + bbCollider.compositeOperation = usedByComposite ? + Collider2D.CompositeOperation.Merge : Collider2D.CompositeOperation.None; +#else bbCollider.usedByComposite = usedByComposite; +#endif bbCollider.enabled = false; bbCollider.hideFlags = HideFlags.NotEditable; colliderTable.Add(boundingBoxAttachment, bbCollider); 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 81fc288b8..a66286ef4 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,10 @@ * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +#if UNITY_6000_0_OR_NEWER +#define RIGIDBODY2D_USES_LINEAR_VELOCITY +#endif + // 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, @@ -215,9 +219,15 @@ namespace Spine.Unity { float deltaTime = Time.fixedDeltaTime; float deltaTimeSquared = (deltaTime * deltaTime); +#if RIGIDBODY2D_USES_LINEAR_VELOCITY + rigidBody2D.linearVelocity += rigidBody2D.gravityScale * Physics2D.gravity * deltaTime; + gravityAndVelocityMovement = 0.5f * rigidBody2D.gravityScale * Physics2D.gravity * deltaTimeSquared + + rigidBody2D.linearVelocity * deltaTime; +#else rigidBody2D.velocity += rigidBody2D.gravityScale * Physics2D.gravity * deltaTime; gravityAndVelocityMovement = 0.5f * rigidBody2D.gravityScale * Physics2D.gravity * deltaTimeSquared + rigidBody2D.velocity * deltaTime; +#endif } Vector2 rigidbodyDisplacement2D = new Vector2(rigidbodyDisplacement.x, rigidbodyDisplacement.y); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs index 006ea81b5..9a1f3ace5 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonUtility/SkeletonUtility.cs @@ -31,6 +31,10 @@ #define NEW_PREFAB_SYSTEM #endif +#if UNITY_6000_0_OR_NEWER +#define USE_RIGIDBODY_BODY_TYPE +#endif + using System.Collections.Generic; using UnityEngine; @@ -123,7 +127,11 @@ namespace Spine.Unity { Rigidbody2D rb = gameObject.GetComponent(); if (rb == null) { rb = gameObject.AddComponent(); +#if USE_RIGIDBODY_BODY_TYPE + rb.bodyType = isKinematic ? RigidbodyType2D.Kinematic : RigidbodyType2D.Dynamic; +#else rb.isKinematic = isKinematic; +#endif rb.gravityScale = gravityScale; } return rb; diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index c9070f3f4..71df31a23 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.113", + "version": "4.2.114", "unity": "2018.3", "author": { "name": "Esoteric Software",