ソースを参照

[unity] Now providing `BeforeApply` update callbacks at all skeleton animation components. Closes #1783.

Harald Csaszar 5 年 前
コミット
90486705f6

+ 1 - 0
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`.

+ 10 - 0
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;
 
+		/// <summary>
+		/// Occurs before the animations are applied.
+		/// Use this callback when you want to change the skeleton state before animations are applied on top.
+		/// </summary>
+		public event UpdateBonesDelegate BeforeApply { add { _BeforeApply += value; } remove { _BeforeApply -= value; } }
+
 		/// <summary>
 		/// 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)

+ 4 - 0
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;

+ 10 - 0
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;
 
+		/// <summary>
+		/// Occurs before the animations are applied.
+		/// Use this callback when you want to change the skeleton state before animations are applied on top.
+		/// </summary>
+		public event UpdateBonesDelegate BeforeApply { add { _BeforeApply += value; } remove { _BeforeApply -= value; } }
+
 		/// <summary>
 		/// Occurs after the animations are applied and before world space values are resolved.
 		/// Use this callback when you want to set bone local values.</summary>
@@ -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)