From d11ebfededd3ae285227f6cd1f93d3370dc80ff7 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 24 May 2018 09:25:09 +0800 Subject: [PATCH 1/2] [unity] Skeleton preview in 2018.1 and 2017.4. Special thanks to @GarlicDipping Fixes https://github.com/EsotericSoftware/spine-runtimes/issues/1110 --- .../Editor/SkeletonDataAssetInspector.cs | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs index 3085ca65e..ee2c2945d 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs @@ -651,7 +651,12 @@ namespace Spine.Unity.Editor { SkeletonAnimation skeletonAnimation; GameObject previewGameObject; internal bool requiresRefresh; + + #if !(UNITY_2017_4 || UNITY_2018) float animationLastTime; + #endif + + static float CurrentTime { get { return (float)EditorApplication.timeSinceStartup; } } Action Repaint; public event Action OnSkinChanged; @@ -742,7 +747,9 @@ namespace Spine.Unity.Editor { if (previewRenderUtility == null) { previewRenderUtility = new PreviewRenderUtility(true); - animationLastTime = Time.realtimeSinceStartup; + #if !(UNITY_2017_4 || UNITY_2018) + animationLastTime = CurrentTime; + #endif const int PreviewLayer = 30; const int PreviewCameraCullingMask = 1 << PreviewLayer; @@ -770,6 +777,10 @@ namespace Spine.Unity.Editor { skeletonAnimation.initialSkinName = skinName; skeletonAnimation.LateUpdate(); previewGameObject.GetComponent().enabled = false; + + #if UNITY_2017_4 || UNITY_2018 + previewRenderUtility.AddSingleGO(previewGameObject); + #endif } if (this.ActiveTrack != null) cameraAdjustEndFrame = EditorApplication.timeSinceStartup + skeletonAnimation.AnimationState.GetCurrent(0).Alpha; @@ -813,6 +824,7 @@ namespace Spine.Unity.Editor { previewRenderUtility.BeginStaticPreview(new Rect(0, 0, width, height)); DoRenderPreview(false); var tex = previewRenderUtility.EndStaticPreview(); + return tex; } @@ -825,12 +837,17 @@ namespace Spine.Unity.Editor { var renderer = go.GetComponent(); renderer.enabled = true; - if (!EditorApplication.isPlaying) { - skeletonAnimation.Update((Time.realtimeSinceStartup - animationLastTime)); - skeletonAnimation.LateUpdate(); - animationLastTime = Time.realtimeSinceStartup; - } + if (!EditorApplication.isPlaying) { + #if !(UNITY_2017_4 || UNITY_2018) + float current = CurrentTime; + float deltaTime = (current - animationLastTime); + skeletonAnimation.Update(deltaTime); + animationLastTime = current; + #endif + skeletonAnimation.LateUpdate(); + } + var thisPreviewUtilityCamera = this.PreviewUtilityCamera; if (drawHandles) { @@ -861,7 +878,7 @@ namespace Spine.Unity.Editor { if (previewRenderUtility == null) return; - if (EditorApplication.timeSinceStartup < cameraAdjustEndFrame) + if (CurrentTime < cameraAdjustEndFrame) AdjustCameraGoals(); lastCameraPositionGoal = cameraPositionGoal; From 41024db6ebe028dce90a07201a5a299985a1584b Mon Sep 17 00:00:00 2001 From: John Date: Fri, 25 May 2018 11:59:11 +0800 Subject: [PATCH 2/2] [unity] Fix AnimationStateClip first frame mesh. --- .../SpineAnimationStateMixerBehaviour.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spine-unity/Assets/spine-unity/Modules/Timeline/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs b/spine-unity/Assets/spine-unity/Modules/Timeline/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs index 52f55c0a6..05371ace7 100644 --- a/spine-unity/Assets/spine-unity/Modules/Timeline/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs +++ b/spine-unity/Assets/spine-unity/Modules/Timeline/SpineAnimationState/SpineAnimationStateMixerBehaviour.cs @@ -50,9 +50,9 @@ namespace Spine.Unity.Playables { var state = spineComponent.AnimationState; if (!Application.isPlaying) { -#if SPINE_EDITMODEPOSE + #if SPINE_EDITMODEPOSE PreviewEditModePose(playable, spineComponent); -#endif + #endif return; } @@ -81,7 +81,6 @@ namespace Spine.Unity.Playables { if (clipData.animationReference == null) { float mixDuration = clipData.customDuration ? clipData.mixDuration : state.Data.DefaultMix; state.SetEmptyAnimation(0, mixDuration); - continue; } else { if (clipData.animationReference.Animation != null) { Spine.TrackEntry trackEntry = state.SetAnimation(0, clipData.animationReference.Animation, clipData.loop); @@ -96,11 +95,15 @@ namespace Spine.Unity.Playables { } //else Debug.LogWarningFormat("Animation named '{0}' not found", clipData.animationName); } + + // Ensure that the first frame ends with an updated mesh. + spineComponent.Update(0); + spineComponent.LateUpdate(); } } } -#if SPINE_EDITMODEPOSE + #if SPINE_EDITMODEPOSE public void PreviewEditModePose (Playable playable, SkeletonAnimation spineComponent) { if (Application.isPlaying) return; if (spineComponent == null) return; @@ -160,9 +163,9 @@ namespace Spine.Unity.Playables { // Do nothing outside of the first clip and the last clip. } -#endif + #endif } } -#endif \ No newline at end of file +#endif