From d2953d6053b0ae9f3634cedb94687b84481ab445 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 10 Jul 2024 17:36:04 +0200 Subject: [PATCH] [unity] Automatically updating SkeletonRootMotion references after SkeletonDataAsset change. Exposed `rootMotionBoneName`. Closes #2575. --- CHANGELOG.md | 1 + .../RootMotion/SkeletonMecanimRootMotion.cs | 4 ++-- .../Components/RootMotion/SkeletonRootMotion.cs | 4 ++-- .../RootMotion/SkeletonRootMotionBase.cs | 17 ++++++++++++++--- spine-unity/Assets/Spine/package.json | 2 +- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed1be6312..e71f765f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -161,6 +161,7 @@ - Added support for BlendModeMaterials at runtime instantiation from files via an additional method `SkeletonDataAsset.SetupRuntimeBlendModeMaterials`. See example scene `Spine Examples/Other Examples/Instantiate from Script` for a usage example. - SkeletonGraphic: You can now offset the skeleton mesh relative to the pivot via a newly added green circle handle. This allows you to e.g. frame only the face of a skeleton inside a masked frame. Previously offsetting the pivot downwards fails when `Layout Scale Mode` scales the mesh smaller and towards the pivot (e.g. the feet) and thus out of the frame. Now you can keep the pivot in the center of the `RectTransform` while offsetting only the mesh downwards, keeping the desired skeleton area (e.g. the face) centered while resizing. Moving the new larger green circle handle moves the mesh offset, while moving the blue pivot circle handle moves the pivot as usual. - `Universal Render Pipeline/Spine/Skeleton` shader now performs proper alpha-testing when `Depth Write` is enabled, using the existing `Shadow alpha cutoff` parameter. + - `SkeletonRootMotion` components now provide a public `Initialize()` method which is automatically called when calling `skeletonAnimation.Initialize(true)` to update the necessary skeleton references. If a different root bone shall be used, be sure to set `skeletonRootMotion.rootMotionBoneName` before calling `skeletonAnimation.Initialize(true)`. - **Breaking changes** diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs index 4dbc7d2f1..4e031166e 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonMecanimRootMotion.cs @@ -88,8 +88,8 @@ namespace Spine.Unity { mecanimLayerFlags = DefaultMecanimLayerFlags; } - protected override void Start () { - base.Start(); + public override void Initialize () { + base.Initialize(); skeletonMecanim = GetComponent(); if (skeletonMecanim) { skeletonMecanim.Translator.OnClipApplied -= OnClipApplied; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs index 6bc6c0b60..2086c3e2a 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotion.cs @@ -88,8 +88,8 @@ namespace Spine.Unity { animationTrackFlags = DefaultAnimationTrackFlags; } - protected override void Start () { - base.Start(); + public override void Initialize () { + base.Initialize(); IAnimationStateComponent animstateComponent = skeletonComponent as IAnimationStateComponent; this.animationState = (animstateComponent != null) ? animstateComponent.AnimationState : null; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs index a85b077ba..0e88ad732 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/RootMotion/SkeletonRootMotionBase.cs @@ -42,8 +42,7 @@ namespace Spine.Unity { #region Inspector [SpineBone] - [SerializeField] - protected string rootMotionBoneName = "root"; + public string rootMotionBoneName = "root"; public bool transformPositionX = true; public bool transformPositionY = true; public bool transformRotation = false; @@ -155,6 +154,14 @@ namespace Spine.Unity { } protected virtual void Start () { + Initialize(); + } + + protected void InitializeOnRebuild (ISkeletonAnimation animatedSkeletonComponent) { + Initialize(); + } + + public virtual void Initialize () { skeletonComponent = GetComponent(); GatherTopLevelBones(); SetRootMotionBone(rootMotionBoneName); @@ -167,6 +174,9 @@ namespace Spine.Unity { if (skeletonAnimation != null) { skeletonAnimation.UpdateLocal -= HandleUpdateLocal; skeletonAnimation.UpdateLocal += HandleUpdateLocal; + + skeletonAnimation.OnAnimationRebuild -= InitializeOnRebuild; + skeletonAnimation.OnAnimationRebuild += InitializeOnRebuild; } } @@ -271,7 +281,8 @@ namespace Spine.Unity { this.rootMotionBone = bone; FindTransformConstraintsAffectingBone(); } else { - Debug.Log("Bone named \"" + name + "\" could not be found."); + Debug.Log("Bone named \"" + name + "\" could not be found. " + + "Set 'skeletonRootMotion.rootMotionBoneName' before calling 'skeletonAnimation.Initialize(true)'."); this.rootMotionBoneIndex = 0; this.rootMotionBone = skeleton.RootBone; } diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index a94a81c48..5150344c7 100644 --- a/spine-unity/Assets/Spine/package.json +++ b/spine-unity/Assets/Spine/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.spine-unity", "displayName": "spine-unity Runtime", "description": "This plugin provides the spine-unity runtime core.", - "version": "4.2.76", + "version": "4.2.77", "unity": "2018.3", "author": { "name": "Esoteric Software",