diff --git a/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.XML b/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.XML index e40dddf..2b1b76a 100644 --- a/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.XML +++ b/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.XML @@ -927,6 +927,32 @@ Max Sequences capacity. Default: 50 + + + Behaviour that can be assigned when chaining a SetLink to a tween + + + + Pauses the tween when the link target is disabled + + + Pauses the tween when the link target is disabled, plays it when it's enabled + + + Pauses the tween when the link target is disabled, restarts it when it's enabled + + + Plays the tween when the link target is enabled + + + Restarts the tween when the link target is enabled + + + Kills the tween when the link target is disabled + + + Kills the tween when the link target is destroyed (becomes NULL). This is always active even if another behaviour is chosen + Path mode (used to determine correct LookAt orientation) @@ -2123,12 +2149,12 @@ - Sets the autoKill behaviour of the tween. - Has no effect if the tween has already started + Sets the autoKill behaviour of the tween to TRUE. + Has no effect if the tween has already started or if it's added to a Sequence Sets the autoKill behaviour of the tween. - Has no effect if the tween has already started + Has no effect if the tween has already started or if it's added to a Sequence If TRUE the tween will be automatically killed when complete @@ -2145,6 +2171,19 @@ Filtering via int is 4X faster than via object, 2X faster than via string (using the alternate object/string overloads) The int ID to assign to this tween. + + Allows to link this tween to a GameObject + so that it will be automatically killed when the GameObject is destroyed. + Has no effect if the tween is added to a Sequence + The link target (unrelated to the target set via SetTarget) + + + Allows to link this tween to a GameObject and assign a behaviour depending on it. + This will also automatically kill the tween when the GameObject is destroyed. + Has no effect if the tween is added to a Sequence + The link target (unrelated to the target set via SetTarget) + The behaviour to use ( is always evaluated even if you choose another one) + Sets the target for the tween, which can then be used as a filter with DOTween's static methods. IMPORTANT: use it with caution. If you just want to set an ID for the tween use SetId instead. diff --git a/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll b/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll index bad952b..a1745b0 100644 Binary files a/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll and b/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll differ diff --git a/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll.mdb b/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll.mdb index d5886b3..7ba04dc 100644 Binary files a/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll.mdb and b/UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll.mdb differ diff --git a/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenEditor.dll b/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenEditor.dll index 129ab0d..7a12b35 100644 Binary files a/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenEditor.dll and b/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenEditor.dll differ diff --git a/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenEditor.dll.mdb b/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenEditor.dll.mdb index e42983d..a353a05 100644 Binary files a/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenEditor.dll.mdb and b/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenEditor.dll.mdb differ diff --git a/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenUpgradeManager.dll b/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenUpgradeManager.dll index 5751ab5..9945786 100644 Binary files a/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenUpgradeManager.dll and b/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenUpgradeManager.dll differ diff --git a/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenUpgradeManager.dll.mdb b/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenUpgradeManager.dll.mdb index 2eaf8c8..5f3c28b 100644 Binary files a/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenUpgradeManager.dll.mdb and b/UnityTests.Unity5/Assets/Demigiant/DOTween/Editor/DOTweenUpgradeManager.dll.mdb differ diff --git a/UnityTests.Unity5/Assets/Demigiant/DemiLib/Core/Editor/Imgs/whiteSquare.png.meta b/UnityTests.Unity5/Assets/Demigiant/DemiLib/Core/Editor/Imgs/whiteSquare.png.meta index 284fe7b..ecbc857 100644 --- a/UnityTests.Unity5/Assets/Demigiant/DemiLib/Core/Editor/Imgs/whiteSquare.png.meta +++ b/UnityTests.Unity5/Assets/Demigiant/DemiLib/Core/Editor/Imgs/whiteSquare.png.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: d3e15b806a8368742ba6f10e794d7b76 -timeCreated: 1549961173 +timeCreated: 1551014982 licenseType: Pro TextureImporter: fileIDToRecycleName: {} diff --git a/UnityTests.Unity5/Assets/Resources/DOTweenSettings.asset b/UnityTests.Unity5/Assets/Resources/DOTweenSettings.asset index 3746c84..577d24a 100644 Binary files a/UnityTests.Unity5/Assets/Resources/DOTweenSettings.asset and b/UnityTests.Unity5/Assets/Resources/DOTweenSettings.asset differ diff --git a/UnityTests.Unity5/Assets/_Tests/SetLink.cs b/UnityTests.Unity5/Assets/_Tests/SetLink.cs new file mode 100644 index 0000000..8d6017a --- /dev/null +++ b/UnityTests.Unity5/Assets/_Tests/SetLink.cs @@ -0,0 +1,22 @@ +using System.Collections; +using DG.Tweening; +using UnityEngine; + +public class SetLink : BrainBase +{ + public Transform tweenTarget; + public bool autoKill = true; + public bool pauseAtStartup = true; + public int loops = 2; + public float duration = 1; + public GameObject linkTarget; + public LinkBehaviour linkBehaviour; + + void Start() + { + Tween t = tweenTarget.DOMoveX(3, duration).SetLoops(loops, LoopType.Yoyo).SetEase(Ease.Linear) + .SetLink(linkTarget, linkBehaviour); + if (autoKill) t.SetAutoKill(); + if (pauseAtStartup) t.Pause(); + } +} \ No newline at end of file diff --git a/UnityTests.Unity5/Assets/_Tests/SetLink.cs.meta b/UnityTests.Unity5/Assets/_Tests/SetLink.cs.meta new file mode 100644 index 0000000..a1243c0 --- /dev/null +++ b/UnityTests.Unity5/Assets/_Tests/SetLink.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ca67d5bc4d6738b4c9a0f4e5bac5eaaa +timeCreated: 1551014610 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityTests.Unity5/Assets/_Tests/SetLink.unity b/UnityTests.Unity5/Assets/_Tests/SetLink.unity new file mode 100644 index 0000000..454945c Binary files /dev/null and b/UnityTests.Unity5/Assets/_Tests/SetLink.unity differ diff --git a/UnityTests.Unity5/Assets/_Tests/SetLink.unity.meta b/UnityTests.Unity5/Assets/_Tests/SetLink.unity.meta new file mode 100644 index 0000000..b52a680 --- /dev/null +++ b/UnityTests.Unity5/Assets/_Tests/SetLink.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 454dbfdf73f2661409a2833466ef5e78 +timeCreated: 1426535291 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/_DOTween.Assembly/DOTween/Core/TweenLink.cs b/_DOTween.Assembly/DOTween/Core/TweenLink.cs new file mode 100644 index 0000000..3247467 --- /dev/null +++ b/_DOTween.Assembly/DOTween/Core/TweenLink.cs @@ -0,0 +1,23 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2019/02/24 13:10 +// License Copyright (c) Daniele Giardini +// This work is subject to the terms at http://dotween.demigiant.com/license.php + +using UnityEngine; + +namespace DG.Tweening.Core +{ + internal class TweenLink + { + public readonly GameObject target; + public readonly LinkBehaviour behaviour; + public bool lastSeenActive; + + public TweenLink(GameObject target, LinkBehaviour behaviour) + { + this.target = target; + this.behaviour = behaviour; + lastSeenActive = target.activeInHierarchy; + } + } +} \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/Core/TweenManager.cs b/_DOTween.Assembly/DOTween/Core/TweenManager.cs index a525cb9..d90f867 100644 --- a/_DOTween.Assembly/DOTween/Core/TweenManager.cs +++ b/_DOTween.Assembly/DOTween/Core/TweenManager.cs @@ -38,6 +38,8 @@ namespace DG.Tweening.Core static readonly Stack _PooledSequences = new Stack(); static readonly List _KillList = new List(_DefaultMaxTweeners + _DefaultMaxSequences); + static readonly Dictionary _TweenLinks = new Dictionary(_DefaultMaxTweeners + _DefaultMaxSequences); + static int _totTweenLinks; // Used for quicker skip in case no TweenLinks were set static int _maxActiveLookupId = -1; // Highest full ID in _activeTweens static bool _requiresActiveReorganization; // True when _activeTweens need to be reorganized to fill empty spaces static int _reorganizeFromId = -1; // First null ID from which to reorganize @@ -216,6 +218,8 @@ namespace DG.Tweening.Core totActiveTweeners = totActiveSequences = 0; _maxActiveLookupId = _reorganizeFromId = -1; _requiresActiveReorganization = false; + _TweenLinks.Clear(); + _totTweenLinks = 0; if (isUpdateLoop) _despawnAllCalledFromUpdateLoopCallback = true; @@ -317,6 +321,39 @@ namespace DG.Tweening.Core _minPooledTweenerId = _maxPooledTweenerId = -1; } + internal static void AddTweenLink(Tween t, TweenLink tweenLink) + { + _totTweenLinks++; + if (_TweenLinks.ContainsKey(t)) _TweenLinks[t] = tweenLink; + else _TweenLinks.Add(t, tweenLink); + // Pause or play tween immediately depending on target's state + if (tweenLink.lastSeenActive) { + switch (tweenLink.behaviour) { + case LinkBehaviour.PauseOnDisablePlayOnEnable: + case LinkBehaviour.PauseOnDisableRestartOnEnable: + case LinkBehaviour.PlayOnEnable: + case LinkBehaviour.RestartOnEnable: + Play(t); + break; + } + } else { + switch (tweenLink.behaviour) { + case LinkBehaviour.PauseOnDisable: + case LinkBehaviour.PauseOnDisablePlayOnEnable: + case LinkBehaviour.PauseOnDisableRestartOnEnable: + Pause(t); + break; + } + } + } + + static void RemoveTweenLink(Tween t) + { + if (!_TweenLinks.ContainsKey(t)) return; + _TweenLinks.Remove(t); + _totTweenLinks--; + } + internal static void ResetCapacities() { SetCapacities(_DefaultMaxTweeners, _DefaultMaxSequences); @@ -375,6 +412,7 @@ namespace DG.Tweening.Core for (int i = 0; i < len; ++i) { Tween t = _activeTweens[i]; if (t == null || t.updateType != updateType) continue; // Wrong updateType or was added to a Sequence (thus removed from active list) while inside current updateLoop + if (_totTweenLinks > 0) EvaluateTweenLink(t); // TweenLinks if (!t.active) { // Manually killed by another tween's callback willKill = true; @@ -890,6 +928,45 @@ namespace DG.Tweening.Core _KillList.Add(t); } + // Called by Update method + static void EvaluateTweenLink(Tween t) + { + // Check tween links + TweenLink tLink; + if (!_TweenLinks.TryGetValue(t, out tLink)) return; + + if (tLink.target == null) { + t.active = false; + } else { + bool goActive = tLink.target.activeInHierarchy; + bool justEnabled = !tLink.lastSeenActive && goActive; + bool justDisabled = tLink.lastSeenActive && !goActive; + tLink.lastSeenActive = goActive; + switch (tLink.behaviour) { + case LinkBehaviour.KillOnDisable: + if (!goActive) t.active = false; // Will be killed by rest of Update loop + break; + case LinkBehaviour.PauseOnDisable: + if (justDisabled && t.isPlaying) Pause(t); + break; + case LinkBehaviour.PauseOnDisablePlayOnEnable: + if (justDisabled) Pause(t); + else if (justEnabled) Play(t); + break; + case LinkBehaviour.PauseOnDisableRestartOnEnable: + if (justDisabled) Pause(t); + else if (justEnabled) Restart(t); + break; + case LinkBehaviour.PlayOnEnable: + if (justEnabled) Play(t); + break; + case LinkBehaviour.RestartOnEnable: + if (justEnabled) Restart(t); + break; + } + } + } + // Adds the given tween to the active tweens list (updateType is always Normal, but can be changed by SetUpdateType) static void AddActiveTween(Tween t) { @@ -973,12 +1050,14 @@ namespace DG.Tweening.Core for (int i = count; i > -1; --i) Despawn(tweens[i]); } - // Removes a tween from the active list, reorganizes said list - // and decreases the given total + // Removes a tween from the active list, then reorganizes said list and decreases the given total. + // Also removes any TweenLinks associated to this tween. static void RemoveActiveTween(Tween t) { int index = t.activeId; + if (_totTweenLinks > 0) RemoveTweenLink(t); + t.activeId = -1; _requiresActiveReorganization = true; if (_reorganizeFromId == -1 || _reorganizeFromId > index) _reorganizeFromId = index; @@ -1068,7 +1147,7 @@ namespace DG.Tweening.Core maxSequences += increaseSequencesBy; break; default: - killAdd += increaseTweenersBy; + killAdd += increaseTweenersBy + increaseSequencesBy; maxTweeners += increaseTweenersBy; maxSequences += increaseSequencesBy; Array.Resize(ref _pooledTweeners, maxTweeners); diff --git a/_DOTween.Assembly/DOTween/DOTween.cs b/_DOTween.Assembly/DOTween/DOTween.cs index 638f406..ff55e97 100644 --- a/_DOTween.Assembly/DOTween/DOTween.cs +++ b/_DOTween.Assembly/DOTween/DOTween.cs @@ -32,7 +32,7 @@ namespace DG.Tweening public class DOTween { /// DOTween's version - public static readonly string Version = "1.2.186"; // Last version before modules: 1.1.755 + public static readonly string Version = "1.2.190"; // Last version before modules: 1.1.755 /////////////////////////////////////////////// // Options //////////////////////////////////// diff --git a/_DOTween.Assembly/DOTween/DOTween.csproj b/_DOTween.Assembly/DOTween/DOTween.csproj index d0c5db0..605d924 100644 --- a/_DOTween.Assembly/DOTween/DOTween.csproj +++ b/_DOTween.Assembly/DOTween/DOTween.csproj @@ -94,6 +94,7 @@ + @@ -102,6 +103,7 @@ + diff --git a/_DOTween.Assembly/DOTween/LinkBehaviour.cs b/_DOTween.Assembly/DOTween/LinkBehaviour.cs new file mode 100644 index 0000000..1efb0ff --- /dev/null +++ b/_DOTween.Assembly/DOTween/LinkBehaviour.cs @@ -0,0 +1,28 @@ +// Author: Daniele Giardini - http://www.demigiant.com +// Created: 2019/02/24 13:05 +// License Copyright (c) Daniele Giardini +// This work is subject to the terms at http://dotween.demigiant.com/license.php + +namespace DG.Tweening +{ + /// + /// Behaviour that can be assigned when chaining a SetLink to a tween + /// + public enum LinkBehaviour + { + /// Pauses the tween when the link target is disabled + PauseOnDisable, + /// Pauses the tween when the link target is disabled, plays it when it's enabled + PauseOnDisablePlayOnEnable, + /// Pauses the tween when the link target is disabled, restarts it when it's enabled + PauseOnDisableRestartOnEnable, + /// Plays the tween when the link target is enabled + PlayOnEnable, + /// Restarts the tween when the link target is enabled + RestartOnEnable, + /// Kills the tween when the link target is disabled + KillOnDisable, + /// Kills the tween when the link target is destroyed (becomes NULL). This is always active even if another behaviour is chosen + KillOnDestroy, + } +} \ No newline at end of file diff --git a/_DOTween.Assembly/DOTween/TweenSettingsExtensions.cs b/_DOTween.Assembly/DOTween/TweenSettingsExtensions.cs index bedd1bd..637d462 100644 --- a/_DOTween.Assembly/DOTween/TweenSettingsExtensions.cs +++ b/_DOTween.Assembly/DOTween/TweenSettingsExtensions.cs @@ -34,8 +34,8 @@ namespace DG.Tweening { #region Tweeners + Sequences - /// Sets the autoKill behaviour of the tween. - /// Has no effect if the tween has already started + /// Sets the autoKill behaviour of the tween to TRUE. + /// Has no effect if the tween has already started or if it's added to a Sequence public static T SetAutoKill(this T t) where T : Tween { if (t == null || !t.active || t.creationLocked) return t; @@ -44,7 +44,7 @@ namespace DG.Tweening return t; } /// Sets the autoKill behaviour of the tween. - /// Has no effect if the tween has already started + /// Has no effect if the tween has already started or if it's added to a Sequence /// If TRUE the tween will be automatically killed when complete public static T SetAutoKill(this T t, bool autoKillOnCompletion) where T : Tween { @@ -84,6 +84,30 @@ namespace DG.Tweening return t; } + /// Allows to link this tween to a GameObject + /// so that it will be automatically killed when the GameObject is destroyed. + /// Has no effect if the tween is added to a Sequence + /// The link target (unrelated to the target set via SetTarget) + public static T SetLink(this T t, GameObject gameObject) where T : Tween + { + if (t == null || !t.active || t.isSequenced || gameObject == null) return t; + + TweenManager.AddTweenLink(t, new TweenLink(gameObject, LinkBehaviour.KillOnDestroy)); + return t; + } + /// Allows to link this tween to a GameObject and assign a behaviour depending on it. + /// This will also automatically kill the tween when the GameObject is destroyed. + /// Has no effect if the tween is added to a Sequence + /// The link target (unrelated to the target set via SetTarget) + /// The behaviour to use ( is always evaluated even if you choose another one) + public static T SetLink(this T t, GameObject gameObject, LinkBehaviour behaviour) where T : Tween + { + if (t == null || !t.active || t.isSequenced || gameObject == null) return t; + + TweenManager.AddTweenLink(t, new TweenLink(gameObject, behaviour)); + return t; + } + /// Sets the target for the tween, which can then be used as a filter with DOTween's static methods. /// IMPORTANT: use it with caution. If you just want to set an ID for the tween use SetId instead. /// When using shorcuts the shortcut target is already assigned as the tween's target, diff --git a/_DOTween.Assembly/bin/DOTween.XML b/_DOTween.Assembly/bin/DOTween.XML index e40dddf..2b1b76a 100644 --- a/_DOTween.Assembly/bin/DOTween.XML +++ b/_DOTween.Assembly/bin/DOTween.XML @@ -927,6 +927,32 @@ Max Sequences capacity. Default: 50 + + + Behaviour that can be assigned when chaining a SetLink to a tween + + + + Pauses the tween when the link target is disabled + + + Pauses the tween when the link target is disabled, plays it when it's enabled + + + Pauses the tween when the link target is disabled, restarts it when it's enabled + + + Plays the tween when the link target is enabled + + + Restarts the tween when the link target is enabled + + + Kills the tween when the link target is disabled + + + Kills the tween when the link target is destroyed (becomes NULL). This is always active even if another behaviour is chosen + Path mode (used to determine correct LookAt orientation) @@ -2123,12 +2149,12 @@ - Sets the autoKill behaviour of the tween. - Has no effect if the tween has already started + Sets the autoKill behaviour of the tween to TRUE. + Has no effect if the tween has already started or if it's added to a Sequence Sets the autoKill behaviour of the tween. - Has no effect if the tween has already started + Has no effect if the tween has already started or if it's added to a Sequence If TRUE the tween will be automatically killed when complete @@ -2145,6 +2171,19 @@ Filtering via int is 4X faster than via object, 2X faster than via string (using the alternate object/string overloads) The int ID to assign to this tween. + + Allows to link this tween to a GameObject + so that it will be automatically killed when the GameObject is destroyed. + Has no effect if the tween is added to a Sequence + The link target (unrelated to the target set via SetTarget) + + + Allows to link this tween to a GameObject and assign a behaviour depending on it. + This will also automatically kill the tween when the GameObject is destroyed. + Has no effect if the tween is added to a Sequence + The link target (unrelated to the target set via SetTarget) + The behaviour to use ( is always evaluated even if you choose another one) + Sets the target for the tween, which can then be used as a filter with DOTween's static methods. IMPORTANT: use it with caution. If you just want to set an ID for the tween use SetId instead. diff --git a/_DOTween.Assembly/bin/DOTween.dll b/_DOTween.Assembly/bin/DOTween.dll index bad952b..a1745b0 100644 Binary files a/_DOTween.Assembly/bin/DOTween.dll and b/_DOTween.Assembly/bin/DOTween.dll differ diff --git a/_DOTween.Assembly/bin/DOTween.dll.mdb b/_DOTween.Assembly/bin/DOTween.dll.mdb index d5886b3..7ba04dc 100644 Binary files a/_DOTween.Assembly/bin/DOTween.dll.mdb and b/_DOTween.Assembly/bin/DOTween.dll.mdb differ diff --git a/_DOTween.Assembly/bin/Editor/DOTweenEditor.dll b/_DOTween.Assembly/bin/Editor/DOTweenEditor.dll index 129ab0d..7a12b35 100644 Binary files a/_DOTween.Assembly/bin/Editor/DOTweenEditor.dll and b/_DOTween.Assembly/bin/Editor/DOTweenEditor.dll differ diff --git a/_DOTween.Assembly/bin/Editor/DOTweenEditor.dll.mdb b/_DOTween.Assembly/bin/Editor/DOTweenEditor.dll.mdb index e42983d..a353a05 100644 Binary files a/_DOTween.Assembly/bin/Editor/DOTweenEditor.dll.mdb and b/_DOTween.Assembly/bin/Editor/DOTweenEditor.dll.mdb differ diff --git a/_DOTween.Assembly/bin/Editor/DOTweenUpgradeManager.dll b/_DOTween.Assembly/bin/Editor/DOTweenUpgradeManager.dll index 5751ab5..9945786 100644 Binary files a/_DOTween.Assembly/bin/Editor/DOTweenUpgradeManager.dll and b/_DOTween.Assembly/bin/Editor/DOTweenUpgradeManager.dll differ diff --git a/_DOTween.Assembly/bin/Editor/DOTweenUpgradeManager.dll.mdb b/_DOTween.Assembly/bin/Editor/DOTweenUpgradeManager.dll.mdb index 2eaf8c8..5f3c28b 100644 Binary files a/_DOTween.Assembly/bin/Editor/DOTweenUpgradeManager.dll.mdb and b/_DOTween.Assembly/bin/Editor/DOTweenUpgradeManager.dll.mdb differ