diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/AnimationReferenceAssetEditor.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/AnimationReferenceAssetEditor.cs index 7c714b9a8..3c4c149f0 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/AnimationReferenceAssetEditor.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/AnimationReferenceAssetEditor.cs @@ -33,6 +33,7 @@ using UnityEngine; using UnityEditor; using System.Reflection; +using System; namespace Spine.Unity.Editor { using Editor = UnityEditor.Editor; @@ -58,7 +59,11 @@ namespace Spine.Unity.Editor { SkeletonData lastSkeletonData; void OnEnable () { HandleOnEnablePreview(); } - void OnDestroy () { HandleOnDestroyPreview(); } + void OnDestroy () { + HandleOnDestroyPreview(); + AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload; + EditorApplication.update -= preview.HandleEditorUpdate; + } public override void OnInspectorGUI () { animationNameProperty = animationNameProperty ?? serializedObject.FindProperty("animationName"); @@ -133,6 +138,11 @@ namespace Spine.Unity.Editor { void HandleOnEnablePreview () { if (ThisSkeletonDataAsset != null && ThisSkeletonDataAsset.skeletonJSON == null) return; + SpineEditorUtilities.ConfirmInitialization(); + + // This handles the case where the managed editor assembly is unloaded before recompilation when code changes. + AppDomain.CurrentDomain.DomainUnload -= OnDomainUnload; + AppDomain.CurrentDomain.DomainUnload += OnDomainUnload; preview.Initialize(this.Repaint, ThisSkeletonDataAsset, LastSkinName); preview.PlayPauseAnimation(ThisAnimationName, true); @@ -142,6 +152,10 @@ namespace Spine.Unity.Editor { EditorApplication.update += preview.HandleEditorUpdate; } + private void OnDomainUnload (object sender, EventArgs e) { + OnDestroy(); + } + private void HandleOnSkinChanged (string skinName) { EditorPrefs.SetString(LastSkinKey, skinName); preview.PlayPauseAnimation(ThisAnimationName, true); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/SkeletonDataAssetInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/SkeletonDataAssetInspector.cs index 9b56de984..5cb6eca00 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Asset Types/SkeletonDataAssetInspector.cs @@ -1158,7 +1158,7 @@ namespace Spine.Unity.Editor { float lineRectWidth = lineRect.width; TrackEntry t = skeletonAnimation.AnimationState.GetCurrent(0); - if (t != null) { + if (t != null && Icons.userEvent != null) { // when changing to play mode, Icons.userEvent will not be reset int loopCount = (int)(t.TrackTime / t.TrackEnd); float currentTime = t.TrackTime - (t.TrackEnd * loopCount); float normalizedTime = currentTime / t.Animation.Duration; @@ -1176,14 +1176,15 @@ namespace Spine.Unity.Editor { for (int i = 0; i < currentAnimationEvents.Count; i++) { float eventTime = currentAnimationEventTimes[i]; var userEventIcon = Icons.userEvent; + float iconX = Mathf.Max(((eventTime / t.Animation.Duration) * lineRectWidth) - (userEventIcon.width / 2), barRect.x); + float iconY = barRect.y + userEventIcon.height; var evRect = new Rect(barRect) { - x = Mathf.Max(((eventTime / t.Animation.Duration) * lineRectWidth) - (userEventIcon.width / 2), barRect.x), - y = barRect.y + userEventIcon.height, + x = iconX, + y = iconY, width = userEventIcon.width, height = userEventIcon.height }; GUI.DrawTexture(evRect, userEventIcon); - Event ev = Event.current; if (ev.type == EventType.Repaint) { if (evRect.Contains(ev.mousePosition)) {