Skip to content

Commit 8f2d5c1

Browse files
Bugfix: Endless exception loop when exiting prefab mode annulusgames#223
1 parent a42784e commit 8f2d5c1

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEditor.UIElements;
44
using System.Collections.Generic;
55
using UnityEngine;
6+
using UnityEditor.SceneManagement;
67

78
namespace LitMotion.Animation.Editor
89
{
@@ -192,7 +193,14 @@ VisualElement CreateDebugPanel()
192193
flexGrow = 1f,
193194
}
194195
};
195-
var playButton = new Button(() => ((LitMotionAnimation)target).Play())
196+
var playButton = new Button(() => {
197+
((LitMotionAnimation)target).Play();
198+
if (PrefabStageUtility.GetCurrentPrefabStage() != null)
199+
{
200+
PrefabStage.prefabStageClosing -= OnPrefabStageClosing;
201+
PrefabStage.prefabStageClosing += OnPrefabStageClosing;
202+
}
203+
})
196204
{
197205
text = "Play",
198206
style = {
@@ -345,5 +353,14 @@ bool IsActive()
345353
{
346354
return !((LitMotionAnimation)target).IsActive;
347355
}
356+
357+
void OnPrefabStageClosing(PrefabStage stage)
358+
{
359+
PrefabStage.prefabStageClosing -= OnPrefabStageClosing;
360+
foreach (var i in stage.prefabContentsRoot.GetComponentsInChildren<LitMotionAnimation>(true))
361+
{
362+
i.Stop();
363+
}
364+
}
348365
}
349366
}

0 commit comments

Comments
 (0)