mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2025-12-20 17:26:03 +08:00
Fixed rare floating point imprecision error when calculating completed loops
This commit is contained in:
parent
ff40e475e8
commit
15400e5ba3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,15 +1,25 @@
|
|||||||
using DG.Tweening;
|
using DG.Tweening;
|
||||||
|
using DG.Tweening.Core;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
public class Temp : BrainBase
|
public class Temp : BrainBase
|
||||||
{
|
{
|
||||||
public RectTransform t;
|
public float lastStepDuration = 0.4f; // 0.4 doesn't work, 0.2 does
|
||||||
|
|
||||||
IEnumerator Start()
|
void Start()
|
||||||
{
|
{
|
||||||
yield return new WaitForSeconds(0.6f);
|
DOTween.Init();
|
||||||
DOTween.To(() => t.anchorMin, (x) => t.anchorMin = x, new Vector2(-1,0) , 2.0f).OnComplete(()=>Debug.Log(t.anchorMin.ToString("N16")));
|
|
||||||
}
|
Sequence timeline = DOTween.Sequence();
|
||||||
|
DOGetter<int> emptyGetter = () => 0;
|
||||||
|
DOSetter<int> emptySetter = value => { };
|
||||||
|
|
||||||
|
timeline.Append(DOTween.To(emptyGetter, emptySetter, 0, 0.2f).OnComplete(() => Debug.LogWarning("step1")));
|
||||||
|
timeline.Append(DOTween.To(emptyGetter, emptySetter, 0, 0.2f).OnComplete(() => Debug.LogWarning("step2")));
|
||||||
|
timeline.Append(DOTween.To(emptyGetter, emptySetter, 0, 0.4f).OnComplete(() => Debug.LogWarning("step3")));
|
||||||
|
timeline.Append(DOTween.To(emptyGetter, emptySetter, 0, 0.2f).OnComplete(() => Debug.LogWarning("step4")));
|
||||||
|
timeline.Append(DOTween.To(emptyGetter, emptySetter, 0, lastStepDuration).SetId("last").OnComplete(() => Debug.LogWarning("step5"))).OnComplete(() => Debug.LogWarning("timeline"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
@ -538,7 +538,8 @@ namespace DG.Tweening.Core
|
|||||||
t.delayComplete = true;
|
t.delayComplete = true;
|
||||||
t.elapsedDelay = t.delay;
|
t.elapsedDelay = t.delay;
|
||||||
// int toCompletedLoops = (int)(to / t.duration); // With very small floats creates floating points imprecisions
|
// int toCompletedLoops = (int)(to / t.duration); // With very small floats creates floating points imprecisions
|
||||||
int toCompletedLoops = Mathf.FloorToInt(to / t.duration); // Takes care of floating points imprecision ((int)Math.Floot doesn't suffice)
|
// int toCompletedLoops = Mathf.FloorToInt(to / t.duration); // Still generates imprecision with some values (like 0.4)
|
||||||
|
int toCompletedLoops = (int)((decimal)to / (decimal)t.duration); // Takes care of floating points imprecision
|
||||||
float toPosition = to % t.duration;
|
float toPosition = to % t.duration;
|
||||||
if (t.loops != -1 && toCompletedLoops >= t.loops) {
|
if (t.loops != -1 && toCompletedLoops >= t.loops) {
|
||||||
toCompletedLoops = t.loops;
|
toCompletedLoops = t.loops;
|
||||||
|
|||||||
@ -32,7 +32,7 @@ namespace DG.Tweening
|
|||||||
public class DOTween
|
public class DOTween
|
||||||
{
|
{
|
||||||
/// <summary>DOTween's version</summary>
|
/// <summary>DOTween's version</summary>
|
||||||
public static readonly string Version = "1.0.620";
|
public static readonly string Version = "1.0.625";
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
// Options ////////////////////////////////////
|
// Options ////////////////////////////////////
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user