Browse Source

[unity] Added `RootMotionDeltaCompensation` example component demonstrating simple root motion delta compensation. See #1873.

Harald Csaszar 4 years ago
parent
commit
97b3f3058b

+ 1 - 0
CHANGELOG.md

@@ -254,6 +254,7 @@
   * Added **native support for slot blend modes** `Additive`, `Multiply` and `Screen` with automatic assignment at newly imported skeleton assets. `BlendModeMaterialAssets` are now obsolete and replaced by the native properties at `SkeletonDataAsset`. The `SkeletonDataAsset` Inspector provides a new `Blend Modes - Upgrade` button to upgrade an obsolete `BlendModeMaterialAsset` to the native blend modes properties. This upgrade will be performed automatically on imported and re-imported assets in Unity 2020.1 and newer to prevent reported `BlendModeMaterialAsset` issues in these Unity versions. spine-unity 4.0 and newer will automatically perform this upgrade regardless of the Unity version.
   * `BoneFollower` and `BoneFollowerGraphic` components now provide better support for following bones when the skeleton's Transform is not the parent of the follower's Transform. Previously e.g. rotating a common parent Transform did not lead to the desired result, as well as negatively scaling a skeleton's Transform when it is not a parent of the follower's Transform.
   * URP and LWRP `Sprite` and `SkeletonLit` shaders no longer require `Advanced - Add Normals` enabled to properly cast and receive shadows. It is recommended to disable `Add Normals` if normals are otherwise not needed.
+  * Added an example component `RootMotionDeltaCompensation` located in `Spine Examples/Scripts/Sample Components` which can be used for applying simple delta compensation. You can enable and disable the component to toggle delta compensation of the currently playing animation on and off.
 
 * **Changes of default values**
   * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`.

+ 29 - 0
spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs

@@ -0,0 +1,29 @@
+using UnityEngine;
+using Spine.Unity;
+
+namespace Spine.Unity.Examples {
+
+	public class RootMotionDeltaCompensation : MonoBehaviour {
+
+		protected SkeletonRootMotionBase rootMotion;
+		public Transform targetPosition;
+		public int trackIndex = 0;
+
+		void Start () {
+			rootMotion = this.GetComponent<SkeletonRootMotionBase>();
+		}
+
+		void Update () {
+			AdjustDelta();
+		}
+
+		void OnDisable () {
+			rootMotion.rootMotionScaleX = rootMotion.rootMotionScaleY = 1;
+		}
+
+		void AdjustDelta() {
+			Vector3 toTarget = targetPosition.position - this.transform.position;
+			rootMotion.AdjustRootMotionToDistance(toTarget, trackIndex);
+		}
+	}
+}

+ 12 - 0
spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: e47cc991328826946a8c4efdd1885bf2
+timeCreated: 1599066046
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: