From 97b3f3058b08ebd48034694659c64a14aba3a41f Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 6 Apr 2021 17:44:50 +0200 Subject: [PATCH] [unity] Added `RootMotionDeltaCompensation` example component demonstrating simple root motion delta compensation. See #1873. --- CHANGELOG.md | 1 + .../RootMotionDeltaCompensation.cs | 29 +++++++++++++++++++ .../RootMotionDeltaCompensation.cs.meta | 12 ++++++++ 3 files changed, 42 insertions(+) create mode 100644 spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs create mode 100644 spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index 554049c12..9578d901d 100644 --- a/CHANGELOG.md +++ b/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`. diff --git a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs new file mode 100644 index 000000000..7731374ab --- /dev/null +++ b/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(); + } + + void Update () { + AdjustDelta(); + } + + void OnDisable () { + rootMotion.rootMotionScaleX = rootMotion.rootMotionScaleY = 1; + } + + void AdjustDelta() { + Vector3 toTarget = targetPosition.position - this.transform.position; + rootMotion.AdjustRootMotionToDistance(toTarget, trackIndex); + } + } +} diff --git a/spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs.meta b/spine-unity/Assets/Spine Examples/Scripts/Sample Components/RootMotionDeltaCompensation.cs.meta new file mode 100644 index 000000000..dd05576cc --- /dev/null +++ b/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: