From e218c83ead5d34b2bb33bb8c9522cafce0810338 Mon Sep 17 00:00:00 2001 From: Pauli Savolainen Date: Fri, 5 Feb 2016 09:12:16 +0200 Subject: [PATCH] Provide a callback for a situation where GameObject gets destroyed during a tween. In such situation onComplete never gets called. Code using lean tween might need to be able to react to game objects being destroyed during a tween. --- Assets/Plugins/LTDescr.cs | 1 + Assets/Plugins/LeanTween.cs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Assets/Plugins/LTDescr.cs b/Assets/Plugins/LTDescr.cs index 5e332b88..2bf7baec 100644 --- a/Assets/Plugins/LTDescr.cs +++ b/Assets/Plugins/LTDescr.cs @@ -82,6 +82,7 @@ public interface LTDescr LTDescr setLoopPingPong(); LTDescr setLoopPingPong(int loops); LTDescr setLoopType(LeanTweenType loopType); + LTDescr setOnDestroyed(Action onDestroyed); LTDescr setOnComplete(Action onComplete); LTDescr setOnComplete(Action onComplete); LTDescr setOnComplete(Action onComplete, object onCompleteParam); diff --git a/Assets/Plugins/LeanTween.cs b/Assets/Plugins/LeanTween.cs index 2a5c5082..95fc3215 100755 --- a/Assets/Plugins/LeanTween.cs +++ b/Assets/Plugins/LeanTween.cs @@ -265,6 +265,7 @@ public class LTDescrImpl : LTDescr { public LeanTweenType tweenType { get; set; } public AnimationCurve animationCurve { get; set; } public LeanTweenType loopType { get; set; } + public bool hasOnDestroyedCallback { get { return this.onDestroyed != null; } } public bool hasUpdateCallback { get; set; } public Action onUpdateFloat { get; set; } public Action onUpdateFloatRatio { get; set; } @@ -273,6 +274,7 @@ public class LTDescrImpl : LTDescr { public Action onUpdateVector3 { get; set; } public Action onUpdateVector3Object { get; set; } public Action onUpdateColor { get; set; } + public Action onDestroyed { get; set; } public Action onComplete { get; set; } public Action onCompleteObject { get; set; } public object onCompleteParam { get; set; } @@ -901,6 +903,11 @@ public LTDescr setLoopPingPong( int loops ) { return this; } + public LTDescr setOnDestroyed(Action onDestroyed){ + this.onDestroyed = onDestroyed; + return this; + } + /** * Have a method called when the tween finishes * @method setOnComplete @@ -1430,6 +1437,9 @@ public static void update() { } if(trans==null){ + if (tweens[i].hasOnDestroyedCallback){ + tweens[i].onDestroyed(); + } removeTween(i); continue; }