From 90486705f6253cfd2d2180562068d78943e4e985 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 14 Oct 2020 12:11:30 +0200 Subject: [PATCH] [unity] Now providing `BeforeApply` update callbacks at all skeleton animation components. Closes #1783. --- CHANGELOG.md | 1 + .../spine-unity/Components/SkeletonAnimation.cs | 10 ++++++++++ .../Runtime/spine-unity/Components/SkeletonGraphic.cs | 4 ++++ .../Runtime/spine-unity/Components/SkeletonMecanim.cs | 10 ++++++++++ 4 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f2d0fef..3b724a804 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -243,6 +243,7 @@ * Added `Mix and Match Skins` example scene to demonstrate how the 3.8 Skin API and combining skins can be used for a wardrobe and equipment use case. * Spine Timeline Extensions: Added `Hold Previous` parameter at `SpineAnimationStateClip`. * Added more warning messages at incompatible SkeletonRenderer/SkeletonGraphic Component vs Material settings. They appear both as an info box in the Inspector as well as upon initialization in the Console log window. The Inspector box warnings can be disabled via `Edit - Preferences - Spine`. + * Now providing `BeforeApply` update callbacks at all skeleton animation components (`SkeletonAnimation`, `SkeletonMecanim` and `SkeletonGraphic`). * **Changes of default values** * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`. diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs index 1011099b2..514eaa341 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs @@ -57,10 +57,17 @@ namespace Spine.Unity { #endregion #region Bone Callbacks ISkeletonAnimation + protected event UpdateBonesDelegate _BeforeApply; protected event UpdateBonesDelegate _UpdateLocal; protected event UpdateBonesDelegate _UpdateWorld; protected event UpdateBonesDelegate _UpdateComplete; + /// + /// Occurs before the animations are applied. + /// Use this callback when you want to change the skeleton state before animations are applied on top. + /// + public event UpdateBonesDelegate BeforeApply { add { _BeforeApply += value; } remove { _BeforeApply -= value; } } + /// /// Occurs after the animations are applied and before world space values are resolved. /// Use this callback when you want to set bone local values. @@ -203,6 +210,9 @@ namespace Spine.Unity { } protected void ApplyAnimation () { + if (_BeforeApply != null) + _BeforeApply(this); + state.Apply(skeleton); if (_UpdateLocal != null) 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 ccb83f8dc..020e4883f 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -260,6 +260,9 @@ namespace Spine.Unity { } protected void ApplyAnimation () { + if (BeforeApply != null) + BeforeApply(this); + state.Apply(skeleton); if (UpdateLocal != null) @@ -413,6 +416,7 @@ namespace Spine.Unity { this.rectTransform.pivot = p; } + public event UpdateBonesDelegate BeforeApply; public event UpdateBonesDelegate UpdateLocal; public event UpdateBonesDelegate UpdateWorld; public event UpdateBonesDelegate UpdateComplete; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs index 98da35cb1..cc6ffaed7 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs @@ -40,10 +40,17 @@ namespace Spine.Unity { private bool wasUpdatedAfterInit = true; #region Bone Callbacks (ISkeletonAnimation) + protected event UpdateBonesDelegate _BeforeApply; protected event UpdateBonesDelegate _UpdateLocal; protected event UpdateBonesDelegate _UpdateWorld; protected event UpdateBonesDelegate _UpdateComplete; + /// + /// Occurs before the animations are applied. + /// Use this callback when you want to change the skeleton state before animations are applied on top. + /// + public event UpdateBonesDelegate BeforeApply { add { _BeforeApply += value; } remove { _BeforeApply -= value; } } + /// /// Occurs after the animations are applied and before world space values are resolved. /// Use this callback when you want to set bone local values. @@ -87,6 +94,9 @@ namespace Spine.Unity { } protected void ApplyAnimation () { + if (_BeforeApply != null) + _BeforeApply(this); + #if UNITY_EDITOR var translatorAnimator = translator.Animator; if (translatorAnimator != null && !translatorAnimator.isInitialized)