From 74615a5177af8d90a5246e6a54cdd9c439af8b9d Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 13 Sep 2023 16:24:31 +0200 Subject: [PATCH] [unity] Timeline extension package: Added static `EditorEvent` callback for editor scripts to react to animation events outside play-mode. --- CHANGELOG.md | 1 + .../SpineAnimationStateMixerBehaviour.cs | 18 ++++++++++++++++-- .../package.json | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7096502b9..51fa9e8a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -111,6 +111,7 @@ 3) Copy the original material, add *_Outline* to its name and set the shader to your outline-only shader like `Universal Render Pipeline/Spine/Outline/Skeleton-OutlineOnly` or `Spine/Outline/OutlineOnly-ZWrite`. 4) Assign this *_Outline* material at the new child GameObject's `MeshRenderer` component. 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;`. * **Breaking changes** * Made `SkeletonGraphic.unscaledTime` parameter protected, use the new property `UnscaledTime` instead. diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs index 2a277ced3..553331415 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/Runtime/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs @@ -31,7 +31,9 @@ #define SPEED_INCLUDED_IN_CLIP_TIME #endif +#if UNITY_EDITOR #define SPINE_EDITMODEPOSE +#endif using System; using UnityEngine; @@ -250,8 +252,11 @@ namespace Spine.Unity.Playables { } #if SPINE_EDITMODEPOSE + /// Animation event callback for editor scripts when outside of play-mode. + public static event AnimationState.TrackEntryEventDelegate EditorEvent; AnimationState dummyAnimationState; + ExposedList editorAnimationEvents = new ExposedList(); public void PreviewEditModePose (Playable playable, ISkeletonComponent skeletonComponent, IAnimationStateComponent animationStateComponent, @@ -259,6 +264,7 @@ namespace Spine.Unity.Playables { if (Application.isPlaying) return; if (animationStateComponent.IsNullOrDestroyed() || skeletonComponent == null) return; + editorAnimationEvents.Clear(false); int inputCount = playable.GetInputCount(); float rootSpeed = GetRootPlayableSpeed(playable); @@ -341,11 +347,19 @@ namespace Spine.Unity.Playables { } // Apply Pose + dummyAnimationState.Event += EditorEvent; dummyAnimationState.Update(0); dummyAnimationState.Apply(skeleton); + dummyAnimationState.Event -= EditorEvent; } else { - if (toAnimation != null) - toAnimation.Apply(skeleton, 0, toClipTime, clipData.loop, null, clipData.alpha, MixBlend.Setup, MixDirection.In); + if (toAnimation != null) { + toAnimation.Apply(skeleton, 0, toClipTime, clipData.loop, editorAnimationEvents, clipData.alpha, MixBlend.Setup, MixDirection.In); + if (EditorEvent != null) { + foreach (Spine.Event e in editorAnimationEvents) { + EditorEvent(null, e); + } + } + } } skeleton.UpdateWorldTransform(); diff --git a/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json b/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json index f7e25a8a3..5f194832e 100644 --- a/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json +++ b/spine-unity/Modules/com.esotericsoftware.spine.timeline/package.json @@ -2,7 +2,7 @@ "name": "com.esotericsoftware.spine.timeline", "displayName": "Spine Timeline Extensions", "description": "This plugin provides integration of spine-unity for the Unity Timeline.\n\nPrerequisites:\nIt requires a working installation of the spine-unity and spine-csharp runtimes as UPM packages (not as spine-unity unitypackage), version 4.1.\n(See http://esotericsoftware.com/git/spine-runtimes/spine-unity)", - "version": "4.1.12", + "version": "4.1.13", "unity": "2018.3", "author": { "name": "Esoteric Software",