mirror of
https://github.com/Cardidi/dotween-upm-fork.git
synced 2025-12-20 01:06:02 +08:00
Fixed extremely rare bug where callbacks were called twice in some cases
This commit is contained in:
parent
96065a6e65
commit
92cd11eb72
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -11,17 +11,120 @@ using UnityEngine.UI;
|
||||
|
||||
public class TempTests : BrainBase
|
||||
{
|
||||
public Transform target;
|
||||
public float TimeScale = 1;
|
||||
public int ConcurrentRunningSequences = 10000;
|
||||
public int loops = 1;
|
||||
public LoopType loopType = LoopType.Restart;
|
||||
|
||||
IEnumerator Start()
|
||||
int _createdSequenceCount;
|
||||
int _completedSequenceCount;
|
||||
|
||||
int _callbackZeroCount;
|
||||
int _callbackOneCount;
|
||||
int _callbackTwoCount;
|
||||
int _callbackThreeCount;
|
||||
|
||||
bool _isTestingInProgress = false;
|
||||
float _time;
|
||||
|
||||
void Start()
|
||||
{
|
||||
yield return new WaitForSeconds(0.8f);
|
||||
DOTween.Init();
|
||||
DOTween.SetTweensCapacity(200, 30000);
|
||||
}
|
||||
|
||||
Tween t = target.DOMoveX(2, 2);
|
||||
// t.OnUpdate(t.Complete);
|
||||
t.OnComplete(()=> Debug.Log("COMPLETE"));
|
||||
yield return new WaitForSeconds(0.4f);
|
||||
void Update()
|
||||
{
|
||||
Time.timeScale = TimeScale;
|
||||
}
|
||||
|
||||
t.Complete();
|
||||
void OnGUI()
|
||||
{
|
||||
GUILayout.Label((Time.realtimeSinceStartup - _time).ToString("n3"));
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (!_isTestingInProgress)
|
||||
{
|
||||
if (GUILayout.Button("Start Testing"))
|
||||
{
|
||||
_isTestingInProgress = true;
|
||||
_time = Time.realtimeSinceStartup;
|
||||
|
||||
for (int i = 0; i < ConcurrentRunningSequences; i++)
|
||||
{
|
||||
StartSequence();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("Stop Testing"))
|
||||
{
|
||||
_isTestingInProgress = false;
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.Label(string.Format("Created Sequences: {0}", _createdSequenceCount.ToString("n0")));
|
||||
GUILayout.Label(string.Format("Completed Sequences: {0}", _completedSequenceCount.ToString("n0")));
|
||||
|
||||
GUILayout.Space(20);
|
||||
|
||||
GUILayout.Label(string.Format("Callback 0 Count: {0}", _callbackZeroCount.ToString("n0")));
|
||||
GUILayout.Label(string.Format("Callback 1 Count: {0}", _callbackOneCount.ToString("n0")));
|
||||
GUILayout.Label(string.Format("Callback 2 Count: {0}", _callbackTwoCount.ToString("n0")));
|
||||
GUILayout.Label(string.Format("Callback 3 Count: {0}", _callbackThreeCount.ToString("n0")));
|
||||
}
|
||||
|
||||
void StartSequence()
|
||||
{
|
||||
_createdSequenceCount++;
|
||||
int added0 = 0;
|
||||
int added1 = 0;
|
||||
int added2 = 0;
|
||||
int added3 = 0;
|
||||
int check = loops - 1;
|
||||
|
||||
DOTween.Sequence()
|
||||
.SetLoops(loops, LoopType.Restart)
|
||||
.AppendCallback(() =>
|
||||
{
|
||||
if (added0 > check) LogError(0);
|
||||
_callbackZeroCount++;
|
||||
added0++;
|
||||
})
|
||||
// .AppendInterval(0.25f) // THIS WORKS
|
||||
.AppendInterval(UnityEngine.Random.Range(0.25f, 1.5f))
|
||||
.AppendCallback(() =>
|
||||
{
|
||||
if (added1 > check) LogError(1);
|
||||
_callbackOneCount++;
|
||||
added1++;
|
||||
})
|
||||
.AppendInterval(0.5f)
|
||||
.AppendCallback(() =>
|
||||
{
|
||||
if (added2 > check) LogError(2);
|
||||
_callbackTwoCount++;
|
||||
added2++;
|
||||
})
|
||||
.AppendInterval(0.25f)
|
||||
.AppendCallback(() =>
|
||||
{
|
||||
if (added3 > check) LogError(3);
|
||||
_callbackThreeCount++;
|
||||
added3++;
|
||||
})
|
||||
.OnComplete(()=> {
|
||||
_completedSequenceCount++;
|
||||
if (_isTestingInProgress) StartSequence();
|
||||
});
|
||||
}
|
||||
|
||||
void LogError(int index)
|
||||
{
|
||||
Debug.LogError(index + " already added");
|
||||
// Debug.Log("currUseInvers-currPrevPosIsInverse: " + Sequence.currUseInverse + " - " + Sequence.currPrevPosIsInverse);
|
||||
// Debug.Log("currFrom-to: " + Sequence.currFrom.ToString("n10") + " - " + Sequence.currTo.ToString("n10"));
|
||||
// Debug.Log("currCallbackStart-End time: " + Sequence.currCallbackTime.ToString("n10") + " - " + Sequence.currCallbackEndTime.ToString("n10"));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -32,7 +32,7 @@ namespace DG.Tweening
|
||||
public class DOTween
|
||||
{
|
||||
/// <summary>DOTween's version</summary>
|
||||
public static readonly string Version = "1.1.695";
|
||||
public static readonly string Version = "1.1.700";
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// Options ////////////////////////////////////
|
||||
|
||||
@ -286,7 +286,14 @@ namespace DG.Tweening
|
||||
for (int i = 0; i < len; ++i) {
|
||||
if (!s.active) return true; // Killed by some internal callback
|
||||
ABSSequentiable sequentiable = s._sequencedObjs[i];
|
||||
if (sequentiable.sequencedPosition > toPos || sequentiable.sequencedEndPosition < fromPos) continue;
|
||||
// if (sequentiable.sequencedPosition > toPos || sequentiable.sequencedEndPosition < fromPos) continue;
|
||||
// Fix rare case with high FPS when a tween/callback might happen in same exact time as it's set
|
||||
// This fixes it but should check for backwards tweens and loops
|
||||
if (
|
||||
sequentiable.sequencedPosition > toPos
|
||||
|| sequentiable.sequencedPosition > 0 && sequentiable.sequencedEndPosition <= fromPos
|
||||
|| sequentiable.sequencedPosition <= 0 && sequentiable.sequencedEndPosition < fromPos
|
||||
) continue;
|
||||
if (sequentiable.tweenType == TweenType.Callback) {
|
||||
if (updateMode == UpdateMode.Update) {
|
||||
// Debug.Log("<color=#FFEC03>FORWARD Callback > " + s.id + " - s.isBackwards: " + s.isBackwards + ", useInverse/prevInverse: " + useInverse + "/" + prevPosIsInverse + " - " + fromPos + " > " + toPos + "</color>");
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user