File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed
Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 11using System . Collections . Generic ;
22using UnityEngine ;
3+ using UnityEngine . SceneManagement ;
34
45namespace Zigurous . Tweening
56{
@@ -39,8 +40,7 @@ internal static TweenManager Instance
3940 GameObject singleton = new GameObject ( ) ;
4041 singleton . name = typeof ( TweenManager ) . Name ;
4142 singleton . hideFlags = HideFlags . HideInHierarchy | HideFlags . HideInInspector ;
42-
43- _instance = singleton . AddComponent < TweenManager > ( ) ;
43+ singleton . AddComponent < TweenManager > ( ) ;
4444 DontDestroyOnLoad ( singleton ) ;
4545 }
4646 }
@@ -54,9 +54,14 @@ private void Awake()
5454 {
5555 _isUnloading = false ;
5656
57- if ( _instance == null ) {
57+ if ( _instance == null )
58+ {
5859 _instance = this ;
59- } else {
60+
61+ SceneManager . sceneUnloaded += SceneUnloaded ;
62+ }
63+ else
64+ {
6065 Destroy ( this ) ;
6166 }
6267 }
@@ -65,8 +70,11 @@ private void OnDestroy()
6570 {
6671 _isUnloading = true ;
6772
68- if ( _instance == this ) {
73+ if ( _instance == this )
74+ {
6975 _instance = null ;
76+
77+ SceneManager . sceneUnloaded -= SceneUnloaded ;
7078 }
7179
7280 foreach ( Tween tween in this . tweens ) {
@@ -176,6 +184,16 @@ internal void Track(Tween tween)
176184 }
177185 }
178186
187+ /// <summary>
188+ /// Kills all tweens when the active scene is unloaded.
189+ /// </summary>
190+ private void SceneUnloaded ( Scene scene )
191+ {
192+ if ( Tweening . killTweensOnSceneUnload ) {
193+ Tweening . KillAll ( ) ;
194+ }
195+ }
196+
179197 }
180198
181199}
Original file line number Diff line number Diff line change @@ -43,6 +43,11 @@ public static class Tweening
4343 /// </summary>
4444 public static float overshoot = 1.70158f ;
4545
46+ /// <summary>
47+ /// Kills all tweens when the active scene is unloaded.
48+ /// </summary>
49+ public static bool killTweensOnSceneUnload = true ;
50+
4651 /// <summary>
4752 /// The initial amount of tweens that memory is allocated for when the
4853 /// system starts. Additional memory will be allocated as needed.
You can’t perform that action at this time.
0 commit comments