From 2a42f1a1609777f799f8e04a8acfe56153b43d68 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 5 Feb 2024 20:12:21 +0100 Subject: [PATCH] [unity] PhysicsConstraints: Made `physicsMovementRelativeTo` protected, added getter/setter automatically resetting last position (see commit 4266c72). --- .../spine-unity/Components/SkeletonGraphic.cs | 14 +++++++++++++- .../spine-unity/Components/SkeletonRenderer.cs | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs index 246e38171..ac5994eb3 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -572,13 +572,25 @@ namespace Spine.Unity { /// When enabled, Transform rotation is applied to skeleton PhysicsConstraints. public bool applyRotationToPhysics = true; /// Reference transform relative to which physics movement will be calculated, or null to use world location. - public Transform physicsMovementRelativeTo = null; + [SerializeField] protected Transform physicsMovementRelativeTo = null; /// Used for applying Transform translation to skeleton PhysicsConstraints. protected Vector2 lastPosition; /// Used for applying Transform rotation to skeleton PhysicsConstraints. protected float lastRotation; + /// Reference transform relative to which physics movement will be calculated, or null to use world location. + public Transform PhysicsMovementRelativeTo { + get { + return physicsMovementRelativeTo; + } + set { + physicsMovementRelativeTo = value; + if (applyTranslationToPhysics) ResetLastPosition(); + if (applyRotationToPhysics) ResetLastRotation(); + } + } + public void ResetLastPosition () { lastPosition = GetPhysicsTransformPosition(); } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs index 51cebc816..a07f2cde4 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs @@ -294,13 +294,25 @@ namespace Spine.Unity { /// When enabled, Transform rotation is applied to skeleton PhysicsConstraints. public bool applyRotationToPhysics = true; /// Reference transform relative to which physics movement will be calculated, or null to use world location. - public Transform physicsMovementRelativeTo = null; + [SerializeField] protected Transform physicsMovementRelativeTo = null; /// Used for applying Transform translation to skeleton PhysicsConstraints. protected Vector2 lastPosition; /// Used for applying Transform rotation to skeleton PhysicsConstraints. protected float lastRotation; + /// Reference transform relative to which physics movement will be calculated, or null to use world location. + public Transform PhysicsMovementRelativeTo { + get { + return physicsMovementRelativeTo; + } + set { + physicsMovementRelativeTo = value; + if (applyTranslationToPhysics) ResetLastPosition(); + if (applyRotationToPhysics) ResetLastRotation(); + } + } + public void ResetLastPosition () { lastPosition = GetPhysicsTransformPosition(); }