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

This commit is contained in:
Harald Csaszar 2020-06-24 16:04:36 +02:00
parent 5b65f3f155
commit 7ecc3b6f95
2 changed files with 31 additions and 1 deletions

View File

@ -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>();

View File

@ -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);