From bffb83fbd7fbd78c816f406117ff76ff959d87c6 Mon Sep 17 00:00:00 2001 From: VirtueSky Date: Wed, 17 Jan 2024 19:56:52 +0700 Subject: [PATCH] update tween 1.1.10 --- VirtueSky/PrimeTween/.DS_Store | Bin 0 -> 6148 bytes VirtueSky/PrimeTween/Editor/CodeGenerator.cs | 2 +- .../Editor/PrimeTweenManagerInspector.cs | 2 +- .../PrimeTween/Runtime/Internal/Assert.cs | 1 + .../PrimeTween/Runtime/Internal/Constants.cs | 5 +- .../Internal/DOTweenAdapter/DOTweenAdapter.cs | 29 +-- .../DOTweenAdapter/DOTweenAdapterGenerated.cs | 134 ++++++------- .../Runtime/Internal/PrimeTweenManager.cs | 12 +- .../Runtime/Internal/ReusableTween.cs | 11 +- VirtueSky/PrimeTween/Runtime/Sequence.cs | 187 ++++++++++-------- VirtueSky/PrimeTween/Runtime/Tween.cs | 5 +- VirtueSky/PrimeTween/Runtime/TweenMethods.cs | 39 ---- 12 files changed, 208 insertions(+), 219 deletions(-) create mode 100644 VirtueSky/PrimeTween/.DS_Store diff --git a/VirtueSky/PrimeTween/.DS_Store b/VirtueSky/PrimeTween/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1d478fe6713d25530e897b76026ff1dfe4267455 GIT binary patch literal 6148 zcmeHK%Sr=55Ukdq0WUdvoL}${mXQ2_`2i0R3Frob$$4-7w$%?I%jzK)51|@*YNn@a zhN;8$HUL{5w@<(Vz?|-gFCV7n`|cCFsfeS+8G9T~n?wJ;@82fbzXzOqhc&j?;S*y% z&%`~RaYWC(9X{}ScDnD%q<|EV0#ZNd&%ya5ys}9BDcE($z z!@5L`Qa}of6}Zji!t4K<{zv~mCTS%Fq`*}vV6)X`wd9kkwoV@BwYJe;=s(8XNaqlx km>8v)3opfwXL-%%-0up9#Go@CbfSI)To;)X_zwlX0l!BZ7XSbN literal 0 HcmV?d00001 diff --git a/VirtueSky/PrimeTween/Editor/CodeGenerator.cs b/VirtueSky/PrimeTween/Editor/CodeGenerator.cs index 8b49a694..dee45435 100644 --- a/VirtueSky/PrimeTween/Editor/CodeGenerator.cs +++ b/VirtueSky/PrimeTween/Editor/CodeGenerator.cs @@ -68,7 +68,7 @@ void generateDotweenMethods() { namespace PrimeTween { [PublicAPI] public static partial class DOTweenAdapter {"; - const string dotweenOverload = " public static Tween DOTWEEN_METHOD_NAME([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.METHOD_NAME(target, endValue, duration, defaultDotweenEase);"; + const string dotweenOverload = " public static Tween DOTWEEN_METHOD_NAME([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.METHOD_NAME(target, endValue, duration);"; str += generateWithDefines(data => { if (!data.dotweenMethodName.Any()) { return string.Empty; diff --git a/VirtueSky/PrimeTween/Editor/PrimeTweenManagerInspector.cs b/VirtueSky/PrimeTween/Editor/PrimeTweenManagerInspector.cs index ef0991c4..299477af 100644 --- a/VirtueSky/PrimeTween/Editor/PrimeTweenManagerInspector.cs +++ b/VirtueSky/PrimeTween/Editor/PrimeTweenManagerInspector.cs @@ -33,7 +33,7 @@ public override void OnInspectorGUI() { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); - GUILayout.Label( Constants.maxAliveTweens + "", EditorStyles.label); + GUILayout.Label( Constants.maxAliveTweens, EditorStyles.label); GUILayout.Label(manager.maxSimultaneousTweensCount.ToString(), EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); diff --git a/VirtueSky/PrimeTween/Runtime/Internal/Assert.cs b/VirtueSky/PrimeTween/Runtime/Internal/Assert.cs index c2bcea2e..0c055dbc 100644 --- a/VirtueSky/PrimeTween/Runtime/Internal/Assert.cs +++ b/VirtueSky/PrimeTween/Runtime/Internal/Assert.cs @@ -28,6 +28,7 @@ static string TryAddStackTrace([CanBeNull] string msg, int tweenId) { } #if UNITY_ASSERTIONS && !PRIME_TWEEN_DISABLE_ASSERTIONS + [ContractAnnotation("condition:false => halt")] internal static void IsTrue(bool condition, int? tweenId = null, string msg = null) => UnityEngine.Assertions.Assert.IsTrue(condition, AddStackTrace(!condition, msg, tweenId)); internal static void AreEqual(T expected, T actual, string msg = null) => UnityEngine.Assertions.Assert.AreEqual(expected, actual, msg); internal static void AreNotEqual(T expected, T actual, string msg = null) => UnityEngine.Assertions.Assert.AreNotEqual(expected, actual, msg); diff --git a/VirtueSky/PrimeTween/Runtime/Internal/Constants.cs b/VirtueSky/PrimeTween/Runtime/Internal/Constants.cs index 4c865cf1..d1c504f8 100644 --- a/VirtueSky/PrimeTween/Runtime/Internal/Constants.cs +++ b/VirtueSky/PrimeTween/Runtime/Internal/Constants.cs @@ -12,7 +12,7 @@ internal static class Constants { "Use Stop()/Complete()/isPaused/timeScale/elapsedTime/etc. of their parent Sequence instead.\n"; [NotNull] internal static string buildWarningCanBeDisabledMessage(string settingName) { - return $"To disable this warning, disable the '{nameof(PrimeTweenConfig)}.{settingName}' setting."; + return $"To disable this warning, set '{nameof(PrimeTweenConfig)}.{settingName} = false;'."; } internal const string isDeadMessage = "Tween/Sequence is not alive. Please check the 'isAlive' property before calling this API.\n"; @@ -40,6 +40,9 @@ internal static string buildWarningCanBeDisabledMessage(string settingName) { internal const string maxAliveTweens = "Max alive tweens"; internal const string sequenceAlreadyStarted = "Sequence has already been started, it's not allowed to manipulate it anymore."; internal const string recursiveCallError = "Please don't call this API recursively from Tween.Custom() or tween.OnUpdate()."; + internal const string nestSequenceTwiceError = "Sequence can be nested in other sequence only once."; + internal const string nestTweenTwiceError = "A tween can be added to a sequence only once and can only belong to one sequence."; + internal const string addDeadTweenToSequenceError = "It's not allowed to add 'dead' tweens to a sequence."; #if UNITY_EDITOR internal const string editModeWarning = "Please don't call PrimeTween's API in Edit mode (while the scene is not playing)."; diff --git a/VirtueSky/PrimeTween/Runtime/Internal/DOTweenAdapter/DOTweenAdapter.cs b/VirtueSky/PrimeTween/Runtime/Internal/DOTweenAdapter/DOTweenAdapter.cs index 8d50dcb8..1fa952cb 100644 --- a/VirtueSky/PrimeTween/Runtime/Internal/DOTweenAdapter/DOTweenAdapter.cs +++ b/VirtueSky/PrimeTween/Runtime/Internal/DOTweenAdapter/DOTweenAdapter.cs @@ -1,6 +1,5 @@ // ReSharper disable UnusedMember.Global // ReSharper disable UnusedType.Global -// ReSharper disable UnusedParameter.Local #if PRIME_TWEEN_DOTWEEN_ADAPTER using System; using System.Collections; @@ -9,8 +8,6 @@ namespace PrimeTween { public static partial class DOTweenAdapter { - const Ease defaultDotweenEase = Ease.OutQuad; - static int remapFrequency(float frequency) { return (int) (frequency * 1.35f); } @@ -76,15 +73,15 @@ public static Tween DOPunchScale([NotNull] this Component target, Vector3 punch, } public static Tween DORotate([NotNull] this Transform target, Vector3 endValue, float duration) { - return Tween.Rotation(target, Quaternion.Euler(endValue), duration, defaultDotweenEase); + return Tween.Rotation(target, Quaternion.Euler(endValue), duration); } public static Tween DOLocalRotate([NotNull] this Transform target, Vector3 endValue, float duration) { - return Tween.LocalRotation(target, Quaternion.Euler(endValue), duration, defaultDotweenEase); + return Tween.LocalRotation(target, Quaternion.Euler(endValue), duration); } public static Tween DOScale([NotNull] this Transform target, Single endValue, float duration) { - return Tween.Scale(target, endValue, duration, defaultDotweenEase); + return Tween.Scale(target, endValue, duration); } public static int DOKill([NotNull] this Component target, bool complete = false) => doKill_internal(target, complete); @@ -98,10 +95,15 @@ internal static int doKill_internal([CanBeNull] object target, bool complete = f return result; } - // public static Tween DOTWEEN_METHOD_NAME([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.METHOD_NAME(target, endValue, duration, defaultDotweenEase); + // public static Tween DOTWEEN_METHOD_NAME([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.METHOD_NAME(target, endValue, duration); } public static class DOTween { + public static Ease defaultEaseType { + get => PrimeTweenConfig.defaultEase; + set => PrimeTweenConfig.defaultEase = value; + } + public static Sequence Sequence() => PrimeTween.Sequence.Create(); public static void Kill([NotNull] object target, bool complete = false) => DOTweenAdapter.doKill_internal(target, complete); @@ -156,10 +158,10 @@ public Sequence Join(Tween other) { /// Schedules after the last added tween. /// Internal because this API is hard to understand, but needed for adapter. internal Sequence ChainLast(Tween other) { - if (!tryManipulate()) { - return this; + if (tryManipulate()) { + Insert(getLastInSelfOrRoot().durationWithWaitDelay, other); } - return chain(other, getLastInSelfOrRoot().durationWithWaitDelay); + return this; } public Sequence Append(Sequence other) => Chain(other); @@ -215,7 +217,7 @@ public Sequence OnStepComplete([NotNull] Action action) { } public Sequence PrependInterval(float interval) { - if (!tryManipulate() || !validateCanAddChildren()) { + if (!ValidateCanManipulateSequence()) { return this; } foreach (var t in getSelfChildren()) { @@ -236,10 +238,9 @@ public Sequence SetUpdate(bool isIndependentUpdate) { public IEnumerator WaitForCompletion() => ToYieldInstruction(); + /// It's safe to destroy objects with running animations in PrimeTween, so this adapter method does nothing. More info: https://github.com/KyryloKuzyk/PrimeTween/discussions/4 [PublicAPI] - public Sequence SetLink(GameObject gameObject) { - return this; - } + public Sequence SetLink(GameObject gameObject) => this; } public partial struct Tween { diff --git a/VirtueSky/PrimeTween/Runtime/Internal/DOTweenAdapter/DOTweenAdapterGenerated.cs b/VirtueSky/PrimeTween/Runtime/Internal/DOTweenAdapter/DOTweenAdapterGenerated.cs index 2e5b5c72..285cbd7d 100644 --- a/VirtueSky/PrimeTween/Runtime/Internal/DOTweenAdapter/DOTweenAdapterGenerated.cs +++ b/VirtueSky/PrimeTween/Runtime/Internal/DOTweenAdapter/DOTweenAdapterGenerated.cs @@ -6,150 +6,150 @@ namespace PrimeTween { [PublicAPI] public static partial class DOTweenAdapter { - public static Tween DOShadowStrength([NotNull] this UnityEngine.Light target, Single endValue, float duration) => Tween.LightShadowStrength(target, endValue, duration, defaultDotweenEase); + public static Tween DOShadowStrength([NotNull] this UnityEngine.Light target, Single endValue, float duration) => Tween.LightShadowStrength(target, endValue, duration); - public static Tween DOIntensity([NotNull] this UnityEngine.Light target, Single endValue, float duration) => Tween.LightIntensity(target, endValue, duration, defaultDotweenEase); + public static Tween DOIntensity([NotNull] this UnityEngine.Light target, Single endValue, float duration) => Tween.LightIntensity(target, endValue, duration); - public static Tween DOColor([NotNull] this UnityEngine.Light target, UnityEngine.Color endValue, float duration) => Tween.LightColor(target, endValue, duration, defaultDotweenEase); + public static Tween DOColor([NotNull] this UnityEngine.Light target, UnityEngine.Color endValue, float duration) => Tween.LightColor(target, endValue, duration); - public static Tween DOOrthoSize([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraOrthographicSize(target, endValue, duration, defaultDotweenEase); + public static Tween DOOrthoSize([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraOrthographicSize(target, endValue, duration); - public static Tween DOColor([NotNull] this UnityEngine.Camera target, UnityEngine.Color endValue, float duration) => Tween.CameraBackgroundColor(target, endValue, duration, defaultDotweenEase); + public static Tween DOColor([NotNull] this UnityEngine.Camera target, UnityEngine.Color endValue, float duration) => Tween.CameraBackgroundColor(target, endValue, duration); - public static Tween DOAspect([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraAspect(target, endValue, duration, defaultDotweenEase); + public static Tween DOAspect([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraAspect(target, endValue, duration); - public static Tween DOFarClipPlane([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraFarClipPlane(target, endValue, duration, defaultDotweenEase); + public static Tween DOFarClipPlane([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraFarClipPlane(target, endValue, duration); - public static Tween DOFieldOfView([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraFieldOfView(target, endValue, duration, defaultDotweenEase); + public static Tween DOFieldOfView([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraFieldOfView(target, endValue, duration); - public static Tween DONearClipPlane([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraNearClipPlane(target, endValue, duration, defaultDotweenEase); + public static Tween DONearClipPlane([NotNull] this UnityEngine.Camera target, Single endValue, float duration) => Tween.CameraNearClipPlane(target, endValue, duration); - public static Tween DOPixelRect([NotNull] this UnityEngine.Camera target, UnityEngine.Rect endValue, float duration) => Tween.CameraPixelRect(target, endValue, duration, defaultDotweenEase); + public static Tween DOPixelRect([NotNull] this UnityEngine.Camera target, UnityEngine.Rect endValue, float duration) => Tween.CameraPixelRect(target, endValue, duration); - public static Tween DORect([NotNull] this UnityEngine.Camera target, UnityEngine.Rect endValue, float duration) => Tween.CameraRect(target, endValue, duration, defaultDotweenEase); + public static Tween DORect([NotNull] this UnityEngine.Camera target, UnityEngine.Rect endValue, float duration) => Tween.CameraRect(target, endValue, duration); - public static Tween DOMove([NotNull] this UnityEngine.Transform target, UnityEngine.Vector3 endValue, float duration) => Tween.Position(target, endValue, duration, defaultDotweenEase); + public static Tween DOMove([NotNull] this UnityEngine.Transform target, UnityEngine.Vector3 endValue, float duration) => Tween.Position(target, endValue, duration); - public static Tween DOMoveX([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.PositionX(target, endValue, duration, defaultDotweenEase); + public static Tween DOMoveX([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.PositionX(target, endValue, duration); - public static Tween DOMoveY([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.PositionY(target, endValue, duration, defaultDotweenEase); + public static Tween DOMoveY([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.PositionY(target, endValue, duration); - public static Tween DOMoveZ([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.PositionZ(target, endValue, duration, defaultDotweenEase); + public static Tween DOMoveZ([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.PositionZ(target, endValue, duration); - public static Tween DOLocalMove([NotNull] this UnityEngine.Transform target, UnityEngine.Vector3 endValue, float duration) => Tween.LocalPosition(target, endValue, duration, defaultDotweenEase); + public static Tween DOLocalMove([NotNull] this UnityEngine.Transform target, UnityEngine.Vector3 endValue, float duration) => Tween.LocalPosition(target, endValue, duration); - public static Tween DOLocalMoveX([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.LocalPositionX(target, endValue, duration, defaultDotweenEase); + public static Tween DOLocalMoveX([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.LocalPositionX(target, endValue, duration); - public static Tween DOLocalMoveY([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.LocalPositionY(target, endValue, duration, defaultDotweenEase); + public static Tween DOLocalMoveY([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.LocalPositionY(target, endValue, duration); - public static Tween DOLocalMoveZ([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.LocalPositionZ(target, endValue, duration, defaultDotweenEase); + public static Tween DOLocalMoveZ([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.LocalPositionZ(target, endValue, duration); - public static Tween DORotateQuaternion([NotNull] this UnityEngine.Transform target, UnityEngine.Quaternion endValue, float duration) => Tween.Rotation(target, endValue, duration, defaultDotweenEase); + public static Tween DORotateQuaternion([NotNull] this UnityEngine.Transform target, UnityEngine.Quaternion endValue, float duration) => Tween.Rotation(target, endValue, duration); - public static Tween DOLocalRotateQuaternion([NotNull] this UnityEngine.Transform target, UnityEngine.Quaternion endValue, float duration) => Tween.LocalRotation(target, endValue, duration, defaultDotweenEase); + public static Tween DOLocalRotateQuaternion([NotNull] this UnityEngine.Transform target, UnityEngine.Quaternion endValue, float duration) => Tween.LocalRotation(target, endValue, duration); - public static Tween DOScale([NotNull] this UnityEngine.Transform target, UnityEngine.Vector3 endValue, float duration) => Tween.Scale(target, endValue, duration, defaultDotweenEase); + public static Tween DOScale([NotNull] this UnityEngine.Transform target, UnityEngine.Vector3 endValue, float duration) => Tween.Scale(target, endValue, duration); - public static Tween DOScaleX([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.ScaleX(target, endValue, duration, defaultDotweenEase); + public static Tween DOScaleX([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.ScaleX(target, endValue, duration); - public static Tween DOScaleY([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.ScaleY(target, endValue, duration, defaultDotweenEase); + public static Tween DOScaleY([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.ScaleY(target, endValue, duration); - public static Tween DOScaleZ([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.ScaleZ(target, endValue, duration, defaultDotweenEase); + public static Tween DOScaleZ([NotNull] this UnityEngine.Transform target, Single endValue, float duration) => Tween.ScaleZ(target, endValue, duration); - public static Tween DOColor([NotNull] this UnityEngine.SpriteRenderer target, UnityEngine.Color endValue, float duration) => Tween.Color(target, endValue, duration, defaultDotweenEase); + public static Tween DOColor([NotNull] this UnityEngine.SpriteRenderer target, UnityEngine.Color endValue, float duration) => Tween.Color(target, endValue, duration); - public static Tween DOFade([NotNull] this UnityEngine.SpriteRenderer target, Single endValue, float duration) => Tween.Alpha(target, endValue, duration, defaultDotweenEase); + public static Tween DOFade([NotNull] this UnityEngine.SpriteRenderer target, Single endValue, float duration) => Tween.Alpha(target, endValue, duration); - public static Tween DOTimeScale([NotNull] this PrimeTween.Tween target, Single endValue, float duration) => Tween.TweenTimeScale(target, endValue, duration, defaultDotweenEase); + public static Tween DOTimeScale([NotNull] this PrimeTween.Tween target, Single endValue, float duration) => Tween.TweenTimeScale(target, endValue, duration); - public static Tween DOTimeScale([NotNull] this PrimeTween.Sequence target, Single endValue, float duration) => Tween.TweenTimeScale(target, endValue, duration, defaultDotweenEase); + public static Tween DOTimeScale([NotNull] this PrimeTween.Sequence target, Single endValue, float duration) => Tween.TweenTimeScale(target, endValue, duration); #if !UNITY_2019_1_OR_NEWER || UNITY_UGUI_INSTALLED - public static Tween DOValue([NotNull] this UnityEngine.UI.Slider target, Single endValue, float duration) => Tween.UISliderValue(target, endValue, duration, defaultDotweenEase); + public static Tween DOValue([NotNull] this UnityEngine.UI.Slider target, Single endValue, float duration) => Tween.UISliderValue(target, endValue, duration); - public static Tween DONormalizedPos([NotNull] this UnityEngine.UI.ScrollRect target, UnityEngine.Vector2 endValue, float duration) => Tween.UINormalizedPosition(target, endValue, duration, defaultDotweenEase); + public static Tween DONormalizedPos([NotNull] this UnityEngine.UI.ScrollRect target, UnityEngine.Vector2 endValue, float duration) => Tween.UINormalizedPosition(target, endValue, duration); - public static Tween DOHorizontalNormalizedPos([NotNull] this UnityEngine.UI.ScrollRect target, Single endValue, float duration) => Tween.UIHorizontalNormalizedPosition(target, endValue, duration, defaultDotweenEase); + public static Tween DOHorizontalNormalizedPos([NotNull] this UnityEngine.UI.ScrollRect target, Single endValue, float duration) => Tween.UIHorizontalNormalizedPosition(target, endValue, duration); - public static Tween DOVerticalNormalizedPos([NotNull] this UnityEngine.UI.ScrollRect target, Single endValue, float duration) => Tween.UIVerticalNormalizedPosition(target, endValue, duration, defaultDotweenEase); + public static Tween DOVerticalNormalizedPos([NotNull] this UnityEngine.UI.ScrollRect target, Single endValue, float duration) => Tween.UIVerticalNormalizedPosition(target, endValue, duration); - public static Tween DOPivotX([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIPivotX(target, endValue, duration, defaultDotweenEase); + public static Tween DOPivotX([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIPivotX(target, endValue, duration); - public static Tween DOPivotY([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIPivotY(target, endValue, duration, defaultDotweenEase); + public static Tween DOPivotY([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIPivotY(target, endValue, duration); - public static Tween DOPivot([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UIPivot(target, endValue, duration, defaultDotweenEase); + public static Tween DOPivot([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UIPivot(target, endValue, duration); - public static Tween DOAnchorMax([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UIAnchorMax(target, endValue, duration, defaultDotweenEase); + public static Tween DOAnchorMax([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UIAnchorMax(target, endValue, duration); - public static Tween DOAnchorMin([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UIAnchorMin(target, endValue, duration, defaultDotweenEase); + public static Tween DOAnchorMin([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UIAnchorMin(target, endValue, duration); - public static Tween DOAnchorPos3D([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector3 endValue, float duration) => Tween.UIAnchoredPosition3D(target, endValue, duration, defaultDotweenEase); + public static Tween DOAnchorPos3D([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector3 endValue, float duration) => Tween.UIAnchoredPosition3D(target, endValue, duration); - public static Tween DOAnchorPos3DX([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPosition3DX(target, endValue, duration, defaultDotweenEase); + public static Tween DOAnchorPos3DX([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPosition3DX(target, endValue, duration); - public static Tween DOAnchorPos3DY([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPosition3DY(target, endValue, duration, defaultDotweenEase); + public static Tween DOAnchorPos3DY([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPosition3DY(target, endValue, duration); - public static Tween DOAnchorPos3DZ([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPosition3DZ(target, endValue, duration, defaultDotweenEase); + public static Tween DOAnchorPos3DZ([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPosition3DZ(target, endValue, duration); - public static Tween DOScale([NotNull] this UnityEngine.UI.Shadow target, UnityEngine.Vector2 endValue, float duration) => Tween.UIEffectDistance(target, endValue, duration, defaultDotweenEase); + public static Tween DOScale([NotNull] this UnityEngine.UI.Shadow target, UnityEngine.Vector2 endValue, float duration) => Tween.UIEffectDistance(target, endValue, duration); - public static Tween DOFade([NotNull] this UnityEngine.UI.Shadow target, Single endValue, float duration) => Tween.Alpha(target, endValue, duration, defaultDotweenEase); + public static Tween DOFade([NotNull] this UnityEngine.UI.Shadow target, Single endValue, float duration) => Tween.Alpha(target, endValue, duration); - public static Tween DOColor([NotNull] this UnityEngine.UI.Shadow target, UnityEngine.Color endValue, float duration) => Tween.Color(target, endValue, duration, defaultDotweenEase); + public static Tween DOColor([NotNull] this UnityEngine.UI.Shadow target, UnityEngine.Color endValue, float duration) => Tween.Color(target, endValue, duration); - public static Tween DOPreferredSize([NotNull] this UnityEngine.UI.LayoutElement target, UnityEngine.Vector2 endValue, float duration) => Tween.UIPreferredSize(target, endValue, duration, defaultDotweenEase); + public static Tween DOPreferredSize([NotNull] this UnityEngine.UI.LayoutElement target, UnityEngine.Vector2 endValue, float duration) => Tween.UIPreferredSize(target, endValue, duration); - public static Tween DOFlexibleSize([NotNull] this UnityEngine.UI.LayoutElement target, UnityEngine.Vector2 endValue, float duration) => Tween.UIFlexibleSize(target, endValue, duration, defaultDotweenEase); + public static Tween DOFlexibleSize([NotNull] this UnityEngine.UI.LayoutElement target, UnityEngine.Vector2 endValue, float duration) => Tween.UIFlexibleSize(target, endValue, duration); - public static Tween DOMinSize([NotNull] this UnityEngine.UI.LayoutElement target, UnityEngine.Vector2 endValue, float duration) => Tween.UIMinSize(target, endValue, duration, defaultDotweenEase); + public static Tween DOMinSize([NotNull] this UnityEngine.UI.LayoutElement target, UnityEngine.Vector2 endValue, float duration) => Tween.UIMinSize(target, endValue, duration); - public static Tween DOColor([NotNull] this UnityEngine.UI.Graphic target, UnityEngine.Color endValue, float duration) => Tween.Color(target, endValue, duration, defaultDotweenEase); + public static Tween DOColor([NotNull] this UnityEngine.UI.Graphic target, UnityEngine.Color endValue, float duration) => Tween.Color(target, endValue, duration); - public static Tween DOAnchorPos([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UIAnchoredPosition(target, endValue, duration, defaultDotweenEase); + public static Tween DOAnchorPos([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UIAnchoredPosition(target, endValue, duration); - public static Tween DOAnchorPosX([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPositionX(target, endValue, duration, defaultDotweenEase); + public static Tween DOAnchorPosX([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPositionX(target, endValue, duration); - public static Tween DOAnchorPosY([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPositionY(target, endValue, duration, defaultDotweenEase); + public static Tween DOAnchorPosY([NotNull] this UnityEngine.RectTransform target, Single endValue, float duration) => Tween.UIAnchoredPositionY(target, endValue, duration); - public static Tween DOSizeDelta([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UISizeDelta(target, endValue, duration, defaultDotweenEase); + public static Tween DOSizeDelta([NotNull] this UnityEngine.RectTransform target, UnityEngine.Vector2 endValue, float duration) => Tween.UISizeDelta(target, endValue, duration); - public static Tween DOFade([NotNull] this UnityEngine.CanvasGroup target, Single endValue, float duration) => Tween.Alpha(target, endValue, duration, defaultDotweenEase); + public static Tween DOFade([NotNull] this UnityEngine.CanvasGroup target, Single endValue, float duration) => Tween.Alpha(target, endValue, duration); - public static Tween DOFade([NotNull] this UnityEngine.UI.Graphic target, Single endValue, float duration) => Tween.Alpha(target, endValue, duration, defaultDotweenEase); + public static Tween DOFade([NotNull] this UnityEngine.UI.Graphic target, Single endValue, float duration) => Tween.Alpha(target, endValue, duration); - public static Tween DOFillAmount([NotNull] this UnityEngine.UI.Image target, Single endValue, float duration) => Tween.UIFillAmount(target, endValue, duration, defaultDotweenEase); + public static Tween DOFillAmount([NotNull] this UnityEngine.UI.Image target, Single endValue, float duration) => Tween.UIFillAmount(target, endValue, duration); #endif #if !UNITY_2019_1_OR_NEWER || PHYSICS_MODULE_INSTALLED - public static Tween DOMove([NotNull] this UnityEngine.Rigidbody target, UnityEngine.Vector3 endValue, float duration) => Tween.RigidbodyMovePosition(target, endValue, duration, defaultDotweenEase); + public static Tween DOMove([NotNull] this UnityEngine.Rigidbody target, UnityEngine.Vector3 endValue, float duration) => Tween.RigidbodyMovePosition(target, endValue, duration); - public static Tween DORotate([NotNull] this UnityEngine.Rigidbody target, UnityEngine.Quaternion endValue, float duration) => Tween.RigidbodyMoveRotation(target, endValue, duration, defaultDotweenEase); + public static Tween DORotate([NotNull] this UnityEngine.Rigidbody target, UnityEngine.Quaternion endValue, float duration) => Tween.RigidbodyMoveRotation(target, endValue, duration); #endif #if !UNITY_2019_1_OR_NEWER || PHYSICS2D_MODULE_INSTALLED - public static Tween DOMove([NotNull] this UnityEngine.Rigidbody2D target, UnityEngine.Vector2 endValue, float duration) => Tween.RigidbodyMovePosition(target, endValue, duration, defaultDotweenEase); + public static Tween DOMove([NotNull] this UnityEngine.Rigidbody2D target, UnityEngine.Vector2 endValue, float duration) => Tween.RigidbodyMovePosition(target, endValue, duration); - public static Tween DORotate([NotNull] this UnityEngine.Rigidbody2D target, Single endValue, float duration) => Tween.RigidbodyMoveRotation(target, endValue, duration, defaultDotweenEase); + public static Tween DORotate([NotNull] this UnityEngine.Rigidbody2D target, Single endValue, float duration) => Tween.RigidbodyMoveRotation(target, endValue, duration); #endif - public static Tween DOColor([NotNull] this UnityEngine.Material target, UnityEngine.Color endValue, float duration) => Tween.MaterialColor(target, endValue, duration, defaultDotweenEase); + public static Tween DOColor([NotNull] this UnityEngine.Material target, UnityEngine.Color endValue, float duration) => Tween.MaterialColor(target, endValue, duration); - public static Tween DOFade([NotNull] this UnityEngine.Material target, Single endValue, float duration) => Tween.MaterialAlpha(target, endValue, duration, defaultDotweenEase); + public static Tween DOFade([NotNull] this UnityEngine.Material target, Single endValue, float duration) => Tween.MaterialAlpha(target, endValue, duration); - public static Tween DOOffset([NotNull] this UnityEngine.Material target, UnityEngine.Vector2 endValue, float duration) => Tween.MaterialMainTextureOffset(target, endValue, duration, defaultDotweenEase); + public static Tween DOOffset([NotNull] this UnityEngine.Material target, UnityEngine.Vector2 endValue, float duration) => Tween.MaterialMainTextureOffset(target, endValue, duration); - public static Tween DOTiling([NotNull] this UnityEngine.Material target, UnityEngine.Vector2 endValue, float duration) => Tween.MaterialMainTextureScale(target, endValue, duration, defaultDotweenEase); + public static Tween DOTiling([NotNull] this UnityEngine.Material target, UnityEngine.Vector2 endValue, float duration) => Tween.MaterialMainTextureScale(target, endValue, duration); #if !UNITY_2019_1_OR_NEWER || AUDIO_MODULE_INSTALLED - public static Tween DOFade([NotNull] this UnityEngine.AudioSource target, Single endValue, float duration) => Tween.AudioVolume(target, endValue, duration, defaultDotweenEase); + public static Tween DOFade([NotNull] this UnityEngine.AudioSource target, Single endValue, float duration) => Tween.AudioVolume(target, endValue, duration); - public static Tween DOPitch([NotNull] this UnityEngine.AudioSource target, Single endValue, float duration) => Tween.AudioPitch(target, endValue, duration, defaultDotweenEase); + public static Tween DOPitch([NotNull] this UnityEngine.AudioSource target, Single endValue, float duration) => Tween.AudioPitch(target, endValue, duration); #endif #if UI_ELEMENTS_MODULE_INSTALLED #endif #if TEXT_MESH_PRO_INSTALLED - public static Tween DOMaxVisibleCharacters([NotNull] this TMPro.TMP_Text target, int endValue, float duration) => Tween.TextMaxVisibleCharacters(target, endValue, duration, defaultDotweenEase); + public static Tween DOMaxVisibleCharacters([NotNull] this TMPro.TMP_Text target, int endValue, float duration) => Tween.TextMaxVisibleCharacters(target, endValue, duration); #endif } diff --git a/VirtueSky/PrimeTween/Runtime/Internal/PrimeTweenManager.cs b/VirtueSky/PrimeTween/Runtime/Internal/PrimeTweenManager.cs index a5e7266b..c911598e 100644 --- a/VirtueSky/PrimeTween/Runtime/Internal/PrimeTweenManager.cs +++ b/VirtueSky/PrimeTween/Runtime/Internal/PrimeTweenManager.cs @@ -229,19 +229,13 @@ void checkNotInSequence(List list) { pool.Add(tween); } - internal static Tween createEmpty() { + /// Returns null if target is a destroyed UnityEngine.Object + internal static Tween? delayWithoutDurationCheck([CanBeNull] object target, float duration, bool useUnscaledTime) { #if UNITY_EDITOR if (Constants.warnNoInstance) { - return default; + return null; } #endif - var result = delayWithoutDurationCheck(dummyTarget, 0, false); - Assert.IsTrue(result.HasValue); - return result.Value; - } - - // Returns null if target is a destroyed UnityEngine.Object - internal static Tween? delayWithoutDurationCheck([CanBeNull] object target, float duration, bool useUnscaledTime) { var tween = fetchTween(); tween.propType = PropType.Float; tween.tweenType = TweenType.Delay; diff --git a/VirtueSky/PrimeTween/Runtime/Internal/ReusableTween.cs b/VirtueSky/PrimeTween/Runtime/Internal/ReusableTween.cs index 5d812791..cfe1ba84 100644 --- a/VirtueSky/PrimeTween/Runtime/Internal/ReusableTween.cs +++ b/VirtueSky/PrimeTween/Runtime/Internal/ReusableTween.cs @@ -582,6 +582,7 @@ float calcEasedT(float t, int cyclesDone) { var cyclesTotal = settings.cycles; if (cyclesDone == cyclesTotal) { // Debug.Log("cyclesDone == cyclesTotal"); + Assert.AreNotEqual(-1, cyclesTotal); switch (cycleMode) { case CycleMode.Restart: return evaluate(1f); @@ -644,8 +645,14 @@ internal void ForceComplete() { warnOnCompleteIgnored(true); return; } - cyclesDone = settings.cycles; - ReportOnValueChange(calcEasedT(1f, settings.cycles)); + var cyclesTotal = settings.cycles; + if (cyclesTotal == -1) { + // same as SetRemainingCycles(1) + cyclesTotal = getCyclesDone() + 1; + settings.cycles = cyclesTotal; + } + cyclesDone = cyclesTotal; + ReportOnValueChange(calcEasedT(1f, cyclesTotal)); if (stoppedEmergently) { return; } diff --git a/VirtueSky/PrimeTween/Runtime/Sequence.cs b/VirtueSky/PrimeTween/Runtime/Sequence.cs index 59a684dd..5b084321 100644 --- a/VirtueSky/PrimeTween/Runtime/Sequence.cs +++ b/VirtueSky/PrimeTween/Runtime/Sequence.cs @@ -89,14 +89,17 @@ public float progressTotal { bool tryManipulate() => root.tryManipulate(); - bool validateCanAddChildren() { + bool ValidateCanManipulateSequence() { + if (!tryManipulate()) { + return false; + } if (root.elapsedTimeTotal != 0f) { Debug.LogError(Constants.sequenceAlreadyStarted); return false; } return true; } - + public static Sequence Create(int cycles = 1, CycleMode cycleMode = CycleMode.Restart, Ease sequenceEase = Ease.Linear, bool useUnscaledTime = false, bool useFixedUpdate = false) { #if UNITY_EDITOR if (Constants.warnNoInstance) { @@ -142,22 +145,13 @@ public static Sequence Create(Tween firstTween) { Assert.IsTrue(durationTotal == 0f || float.IsPositiveInfinity(durationTotal)); } - /// Groups with the 'previous' tween (or sequence) in this Sequence.
- /// Grouped tweens and sequences start at the same time and run in parallel.
- /// Chain() operation ends the current group.
+ /// Groups with the 'previous' animation (tween or sequence) in this Sequence.
+ /// Grouped animations start at the same time and run in parallel.
+ /// If the 'previous' operation is Chain(), then will start at the same time with the 'previously' chained animation.
public Sequence Group(Tween tween) { - requireFinite(tween); - if (!tryManipulate() ||!validateCanAddChildren()) { - return this; + if (tryManipulate()) { + Insert(getLastInSelfOrRoot().tween.waitDelay, tween); } - Assert.IsTrue(isAlive); - validate(tween); - validateChildSettings(tween); - Assert.AreEqual(0, tween.tween.waitDelay); - tween.tween.waitDelay = getLastInSelfOrRoot().tween.waitDelay; - addLinkedReference(tween); - setSequence(tween); - duration = Mathf.Max(duration, tween.durationWithWaitDelay); return this; } @@ -194,51 +188,74 @@ Tween getLast() { /// Schedules after all tweens and sequences in this Sequence. public Sequence Chain(Tween tween) { - if (!tryManipulate()) { - return this; + if (tryManipulate()) { + Insert(duration, tween); } - return chain(tween, duration); + return this; } - Sequence chain(Tween other, float waitDelay) { - Assert.IsTrue(isAlive); - validate(other); - validateChildSettings(other); - if (!validateCanAddChildren()) { + /// Places inside this Sequence at time , leaving other animations unchanged.
+ /// Sequence's duration will be increased if the inserted doesn't fit inside the current duration.
+ public Sequence Insert(float atTime, Tween tween) { + if (!ValidateCanAdd(tween)) { return this; } - Assert.AreEqual(0, other.tween.waitDelay); - other.tween.waitDelay = waitDelay; - addLinkedReference(other); - setSequence(other); - duration += other.durationTotal; + if (tween.tween.sequence.IsCreated) { + Debug.LogError($"{Constants.nestTweenTwiceError} Tween: {tween.tween.GetDescription()}"); + return this; + } + setSequence(tween); + Insert_internal(atTime, tween); return this; } + void Insert_internal(float atTime, Tween other) { + Assert.AreEqual(0f, other.tween.waitDelay); + other.tween.waitDelay = atTime; + duration = Mathf.Max(duration, other.durationWithWaitDelay); + addLinkedReference(other); + } + /// Schedules after all previously added tweens. /// https://github.com/KyryloKuzyk/PrimeTween/discussions/4 public Sequence ChainCallback([NotNull] Action callback, bool warnIfTargetDestroyed = true) { + if (tryManipulate()) { + InsertCallback(duration, callback, warnIfTargetDestroyed); + } + return this; + } + + public Sequence InsertCallback(float atTime, Action callback, bool warnIfTargetDestroyed = true) { if (!tryManipulate()) { return this; } - var delay = PrimeTweenManager.createEmpty(); + var maybeDelay = PrimeTweenManager.delayWithoutDurationCheck(PrimeTweenManager.dummyTarget, atTime, false); + Assert.IsTrue(maybeDelay.HasValue); + var delay = maybeDelay.Value; delay.tween.OnComplete(callback, warnIfTargetDestroyed); - return Chain(delay); + return Insert(0f, delay); } /// Schedules after all previously added tweens. Passing 'target' allows to write a non-allocating callback. /// https://github.com/KyryloKuzyk/PrimeTween/discussions/4 public Sequence ChainCallback([NotNull] T target, [NotNull] Action callback, bool warnIfTargetDestroyed = true) where T: class { + if (tryManipulate()) { + InsertCallback(duration, target, callback, warnIfTargetDestroyed); + } + return this; + } + + public Sequence InsertCallback(float atTime, [NotNull] T target, Action callback, bool warnIfTargetDestroyed = true) where T: class { if (!tryManipulate()) { return this; } - var maybeDelay = PrimeTweenManager.delayWithoutDurationCheck(target, 0, false); + var maybeDelay = PrimeTweenManager.delayWithoutDurationCheck(target, atTime, false); if (!maybeDelay.HasValue) { return this; } var delay = maybeDelay.Value; delay.tween.OnComplete(target, callback, warnIfTargetDestroyed); - return Chain(delay); + return Insert(0f, delay); } /// Schedules delay after all previously added tweens. @@ -257,11 +274,6 @@ Tween getLastInSelfOrRoot() { return result; } - static void requireFinite(Tween other) { - requireIsAlive(other); - Assert.IsTrue(other.tween.settings.cycles >= 1, msg: Constants.infiniteTweenInSequenceError); - } - void setSequence(Tween handle) { Assert.IsTrue(IsCreated); Assert.IsTrue(handle.isAlive); @@ -270,35 +282,35 @@ void setSequence(Tween handle) { tween.sequence = this; } - static void validateChildSettings(Tween child) { - if (child.tween._isPaused) { + bool ValidateCanAdd(Tween other) { + if (!ValidateCanManipulateSequence()) { + return false; + } + if (!other.isAlive) { + Debug.LogError(Constants.addDeadTweenToSequenceError); + return false; + } + if (other.tween.settings.cycles == -1) { + Debug.LogError(Constants.infiniteTweenInSequenceError); + return false; + } + if (other.tween._isPaused) { warnIgnoredChildrenSetting(nameof(isPaused)); } // ReSharper disable once CompareOfFloatsByEqualityOperator - if (child.tween.timeScale != 1f) { + if (other.tween.timeScale != 1f) { warnIgnoredChildrenSetting(nameof(timeScale)); } - if (child.tween.settings.useUnscaledTime) { + if (other.tween.settings.useUnscaledTime) { warnIgnoredChildrenSetting(nameof(TweenSettings.useUnscaledTime)); } - if (child.tween.settings.useFixedUpdate) { + if (other.tween.settings.useFixedUpdate) { warnIgnoredChildrenSetting(nameof(TweenSettings.useFixedUpdate)); } void warnIgnoredChildrenSetting(string settingName) { Debug.LogError($"'{settingName}' was ignored after adding tween/sequence to the Sequence. Parent Sequence controls isPaused/timeScale/useUnscaledTime/useFixedUpdate of all its children tweens and sequences.\n"); } - } - - static void validate(Tween other) { - requireIsAlive(other); - requireFinite(other); - if (other.tween.sequence.IsCreated) { - throw new Exception($"A tween can be added to a sequence only once and can only belong to one sequence. Tween: {other.tween.GetDescription()}"); - } - } - - static void requireIsAlive(Tween other) { - Assert.IsTrue(other.isAlive, msg: "It's not allowed to add 'dead' tweens to a sequence."); + return true; } /// Stops all tweens in the Sequence, ignoring callbacks. @@ -310,10 +322,16 @@ public void Stop() { } } - /// Immediately completes the current sequence cycle. Remaining sequence cycles are ignored. + /// Immediately completes the sequence.
+ /// If the sequence has infinite cycles (cycles == -1), completes only the current cycle. To choose where the sequence should stop (at the 'start' or at the 'end') in the case of infinite cycles, use before calling Complete().
public void Complete() { if (isAlive && tryManipulate()) { - SetRemainingCycles(1); + if (cyclesTotal == -1 || root.tween.settings.cycleMode == CycleMode.Restart) { + SetRemainingCycles(1); + } else { + int cyclesLeft = cyclesTotal - cyclesDone; + SetRemainingCycles(cyclesLeft % 2 == 1 ? 1 : 2); + } root.isPaused = false; Assert.IsTrue(root.tween.isMainSequenceRoot()); root.tween.updateSequence(float.MaxValue, false); @@ -371,7 +389,7 @@ internal SequenceChildrenEnumerator getAllChildren() { return enumerator; } - /// Stops the sequence when it reaches the 'end' or returns to the 'beginning' for the next time.
+ /// Stops the sequence when it reaches the 'end' or returns to the 'start' for the next time.
/// For example, if you have an infinite sequence (cycles == -1) with CycleMode.Yoyo/Rewind, and you wish to stop it when it reaches the 'end', then set to true. /// To stop the animation at the 'beginning', set to false.
public void SetRemainingCycles(bool stopAtEndValue) { @@ -521,35 +539,38 @@ public bool MoveNext() { } /// Schedules after all tweens and sequences in this Sequence. - public Sequence Chain(Sequence sequence) => nestSequence(sequence, true); - - /// Groups with the 'previous' tween (or sequence) in this Sequence.
- /// Grouped tweens and sequences start at the same time and run in parallel.
- /// Chain() operation ends the current group.
- public Sequence Group(Sequence sequence) => nestSequence(sequence, false); - - Sequence nestSequence(Sequence other, bool isChainOp) { - requireFinite(other.root); - if (!tryManipulate() || !validateCanAddChildren()) { - return this; + public Sequence Chain(Sequence sequence) { + if (tryManipulate()) { + Insert(duration, sequence); } - Assert.IsTrue(other.isAlive); - ref var otherTweenType = ref other.root.tween.tweenType; - Assert.AreEqual(TweenType.MainSequence, otherTweenType, "Sequence can be nested in other sequence only once."); - otherTweenType = TweenType.NestedSequence; + return this; + } + + /// Groups with the 'previous' animation (tween or sequence) in this Sequence.
+ /// Grouped animations start at the same time and run in parallel.
+ /// If the 'previous' operation is Chain(), then will start at the same time with the 'previously' chained animation.
+ public Sequence Group(Sequence sequence) { + if (tryManipulate()) { + Insert(getLastInSelfOrRoot().tween.waitDelay, sequence); + } + return this; + } - Assert.AreEqual(0f, other.root.tween.waitDelay); - var waitDelayShift = isChainOp ? duration : getLastInSelfOrRoot().tween.waitDelay; - // tests: SequenceNestingDepsChain/SequenceNestingDepsGroup - other.root.tween.waitDelay += waitDelayShift; + /// Places inside this Sequence at time , leaving other animations unchanged.
+ /// Sequence's duration will be increased if the inserted doesn't fit inside the current duration.
+ public Sequence Insert(float atTime, Sequence sequence) { + if (!ValidateCanAdd(sequence.root)) { + return this; + } - addLinkedReference(other.root); - if (isChainOp) { - duration += other.durationTotal; - } else { - duration = Mathf.Max(duration, other.root.durationWithWaitDelay); + ref var otherTweenType = ref sequence.root.tween.tweenType; + if (otherTweenType != TweenType.MainSequence) { + Debug.LogError(Constants.nestSequenceTwiceError); + return this; } - validateChildSettings(other.root); + otherTweenType = TweenType.NestedSequence; + + Insert_internal(atTime, sequence.root); validateSequenceEnumerator(); return this; } diff --git a/VirtueSky/PrimeTween/Runtime/Tween.cs b/VirtueSky/PrimeTween/Runtime/Tween.cs index 78402cf5..cfec0ddb 100644 --- a/VirtueSky/PrimeTween/Runtime/Tween.cs +++ b/VirtueSky/PrimeTween/Runtime/Tween.cs @@ -212,10 +212,11 @@ public void Stop() { } } - /// Immediately sets the tween to the endValue and calls onComplete. + /// Immediately completes the tween.
+ /// If the tween has infinite cycles (cycles == -1), completes only the current cycle. To choose between 'startValue' and 'endValue' in the case of infinite cycles, use before calling Complete().
public void Complete() { // don't warn that tween is dead because dead tween means that it's already 'completed' - if (isAlive && tryManipulate()) { + if (isAlive && tryManipulate()) { tween.ForceComplete(); } } diff --git a/VirtueSky/PrimeTween/Runtime/TweenMethods.cs b/VirtueSky/PrimeTween/Runtime/TweenMethods.cs index d5154d0f..bff3f754 100644 --- a/VirtueSky/PrimeTween/Runtime/TweenMethods.cs +++ b/VirtueSky/PrimeTween/Runtime/TweenMethods.cs @@ -346,44 +346,5 @@ public static Tween TweenTimeScale(Tween tween, TweenSettings settings) { } public static Tween TweenTimeScale(Sequence sequence, TweenSettings settings) => TweenTimeScale(sequence.root, settings); - - #if PRIME_TWEEN_EXPERIMENTAL - /// Similar to position animation with Ease.OutBounce, but gives the ability to customize the bounce behaviour by specifying the exact bounce amplitude, number of bounces, and bounce stiffness. - public static Sequence PositionOutBounce([NotNull] Transform target, Vector3 endValue, float duration, float bounceAmplitude, int numBounces = 2, float stiffness = 0.5f, bool useUnscaledTime = false) - => CustomOutBounce(target, (t, s) => Position(t, s), endValue, duration, bounceAmplitude, numBounces, stiffness, t => t.position, useUnscaledTime); - - /// Similar to position animation with Ease.OutBounce, but gives the ability to customize the bounce behaviour by specifying the exact bounce amplitude, number of bounces, and bounce stiffness. - public static Sequence LocalPositionOutBounce([NotNull] Transform target, Vector3 endValue, float duration, float bounceAmplitude, int numBounces = 2, float stiffness = 0.5f, bool useUnscaledTime = false) - => CustomOutBounce(target, (t, s) => LocalPosition(t, s), endValue, duration, bounceAmplitude, numBounces, stiffness, t => t.localPosition, useUnscaledTime); - - static Sequence CustomOutBounce([NotNull] Transform target, [NotNull] Func, Tween> animFunc, Vector3 endValue, float duration, float bounceAmplitude, int numBounces, float stiffness, [NotNull] Func getPos, bool useUnscaledTime) { - if (bounceAmplitude == 0) { - Debug.LogWarning("Please provide non-zero " + nameof(bounceAmplitude) + "."); - } - if (numBounces < 0 || numBounces > 10) { - Debug.LogError("'" + nameof(numBounces) + "' should be >= 0 and <= 10."); - numBounces = Mathf.Clamp(numBounces, 0, 10); - } - if (stiffness < 0 || stiffness > 5) { - Debug.LogError("'" + nameof(stiffness) + "' should be >= 0 and <= 5."); - stiffness = Mathf.Clamp(stiffness, 0, 5); - } - stiffness += 1; - // move durations: x + x/stiffness + x/stiffness^2 + x/stiffness^3... - float x = 1; - for (int i = 1; i <= numBounces; i++) { - x += 1 / Mathf.Pow(stiffness, i); - } - var curDur = duration / x; - var sequence = Sequence.Create(animFunc(target, new TweenSettings(endValue, curDur, Ease.InSine, useUnscaledTime: useUnscaledTime))); - var bounceVector = (getPos(target) - endValue).normalized * bounceAmplitude; - for (int i = 1; i <= numBounces; i++) { - curDur /= stiffness; - sequence.Chain(animFunc(target, new TweenSettings(endValue + bounceVector, curDur / 2f, Ease.OutSine, 2, CycleMode.Rewind, useUnscaledTime: useUnscaledTime))); - bounceVector /= stiffness * 2; - } - return sequence; - } - #endif // PRIME_TWEEN_EXPERIMENTAL } } \ No newline at end of file