Эх сурвалжийг харах

[unity] Reload during Play mode now copies registered event subscribers from before reload. Closes #1704.

Harald Csaszar 5 жил өмнө
parent
commit
7ecc3b6f95

+ 19 - 0
spine-csharp/src/AnimationState.cs

@@ -85,6 +85,25 @@ namespace Spine {
 
 		public delegate void TrackEntryEventDelegate (TrackEntry trackEntry, Event e);
 		public event TrackEntryEventDelegate Event;
+
+		public void AssignEventSubscribersFrom (AnimationState src) {
+			Event = src.Event;
+			Start = src.Start;
+			Interrupt = src.Interrupt;
+			End = src.End;
+			Dispose = src.Dispose;
+			Complete = src.Complete;
+		}
+
+		public void AddEventSubscribersFrom (AnimationState src) {
+			Event += src.Event;
+			Start += src.Start;
+			Interrupt += src.Interrupt;
+			End += src.End;
+			Dispose += src.Dispose;
+			Complete += src.Complete;
+		}
+
 		// end of difference
 		private readonly EventQueue queue; // Initialized by constructor.
 		private readonly HashSet<int> propertyIDs = new HashSet<int>();

+ 12 - 1
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs

@@ -219,7 +219,18 @@ namespace Spine.Unity.Editor {
 		public static void ReinitializeComponent (SkeletonRenderer component) {
 			if (component == null) return;
 			if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
-			component.Initialize(true);
+
+			var stateComponent = component as IAnimationStateComponent;
+			AnimationState oldAnimationState = null;
+			if (stateComponent != null) {
+				oldAnimationState = stateComponent.AnimationState;
+			}
+
+			component.Initialize(true); // implicitly clears any subscribers
+
+			if (oldAnimationState != null) {
+				stateComponent.AnimationState.AssignEventSubscribersFrom(oldAnimationState);
+			}
 
 		#if BUILT_IN_SPRITE_MASK_COMPONENT
 			SpineMaskUtilities.EditorAssignSpriteMaskMaterials(component);