From 209acdc892158d235f381ae8edd5a7cec3a55ed9 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 3 Oct 2023 17:17:37 +0200 Subject: [PATCH] [unity] Added `UpdateTiming` mode `In Late Update` for all animated skeleton components. --- CHANGELOG.md | 1 + .../Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs | 4 ++++ .../Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs | 3 +++ .../Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs | 2 ++ .../Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs | 3 ++- spine-unity/Assets/Spine/package.json | 2 +- 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a316f9333..8212b464d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,7 @@ If you are using `SkeletonRenderSeparator` and need to enable and disable the `SkeletonRenderSeparator` component at runtime, you can increase the `RenderCombinedMesh` `Reference Renderers` array by one and assign the `SkeletonRenderer` itself at the last entry after the parts renderers. Disabled `MeshRenderer` components will be skipped when combining the final mesh, so the combined mesh is automatically filled from the desired active renderers. * Timeline extension package: Added static `EditorEvent` callback to allow editor scripts to react to animation events outside of play-mode. Register to the events via `Spine.Unity.Playables.SpineAnimationStateMixerBehaviour.EditorEvent += YourCallback;`. * URP Shaders: Added `Depth Write` property to shaders `Universal Render Pipeline/Spine/Skeleton` and `Universal Render Pipeline/Spine/Skeleton Lit`. Defaults to false to maintain existing behaviour. + * Added `Animation Update` mode (called `UpdateTiming` in code) `In Late Update` for `SkeletonAnimation`, `SkeletonMecanim` and `SkeletonGraphic`. This allows you to update the `SkeletonMecanim` skeleton in the same frame that the Mecanim Animator updated its state, which happens between `Update` and `LateUpdate`. * **Breaking changes** * Made `SkeletonGraphic.unscaledTime` parameter protected, use the new property `UnscaledTime` instead. 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 29c280661..087dabd76 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonAnimation.cs @@ -273,8 +273,12 @@ namespace Spine.Unity { } public override void LateUpdate () { + if (updateTiming == UpdateTiming.InLateUpdate && valid) + Update(unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime); + // instantiation can happen from Update() after this component, leading to a missing Update() call. if (!wasUpdatedAfterInit) Update(0); + base.LateUpdate(); } 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 d8e0cf2dc..92871e4c3 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -415,6 +415,9 @@ namespace Spine.Unity { if (freeze) return; if (updateMode != UpdateMode.FullUpdate) return; + if (updateTiming == UpdateTiming.InLateUpdate) + Update(unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime); + PrepareInstructionsAndRenderers(); SetVerticesDirty(); // triggers Rebuild and avoids potential double-update in a single frame 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 29959d445..41e72bc8b 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonMecanim.cs @@ -167,6 +167,8 @@ namespace Spine.Unity { } public override void LateUpdate () { + if (updateTiming == UpdateTiming.InLateUpdate && valid) + UpdateAnimation(); // instantiation can happen from Update() after this component, leading to a missing Update() call. if (!wasUpdatedAfterInit) Update(); base.LateUpdate(); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs index 67ecf8393..06dea7f70 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/ISkeletonAnimation.cs @@ -40,7 +40,8 @@ namespace Spine.Unity { public enum UpdateTiming { ManualUpdate = 0, InUpdate, - InFixedUpdate + InFixedUpdate, + InLateUpdate } public delegate void ISkeletonAnimationDelegate (ISkeletonAnimation animated); diff --git a/spine-unity/Assets/Spine/package.json b/spine-unity/Assets/Spine/package.json index 29bbb1af5..346c68baf 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.1.26", + "version": "4.1.27", "unity": "2018.3", "author": { "name": "Esoteric Software",