1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-20 01:06:02 +08:00

[BUGFIX] Fixed OnWaypointChange being called multiple times (as if the tween was going backwards) when restarting a path loop set to Restart

This commit is contained in:
Demigiant 2019-02-28 16:03:39 +01:00
parent acacc85b29
commit 3b1a1b3599
16 changed files with 15 additions and 5 deletions

View File

@ -11,6 +11,7 @@ public class PathsBezier : BrainBase
public Ease easeType = Ease.Linear;
public bool loop = true;
public LoopType loopType = LoopType.Restart;
public PathType pathType = PathType.CubicBezier;
public int wpsToUse = 0;
public Vector3[] wps0 = new[] {
new Vector3(1, 1, 0), // wp
@ -61,7 +62,8 @@ public class PathsBezier : BrainBase
Debug.Log("Creating CubicBezier path");
Vector3[] wps = wpsToUse == 0 ? wps0 : wpsToUse == 1 ? wps1 : wps2;
target.DOPath(wps, duration, PathType.CubicBezier).SetOptions(closedPath).SetLookAt(0.001f)
.SetLoops(loop ? -1 : 1, loopType).SetEase(easeType);
target.DOPath(wps, duration, pathType).SetOptions(closedPath).SetLookAt(0.001f)
.SetLoops(loop ? -1 : 1, loopType).SetEase(easeType)
.OnWaypointChange(x=> Debug.Log("Waypoint changed ► " + x));
}
}

View File

@ -32,7 +32,7 @@ namespace DG.Tweening
public class DOTween
{
/// <summary>DOTween's version</summary>
public static readonly string Version = "1.2.210"; // Last version before modules: 1.1.755
public static readonly string Version = "1.2.211"; // Last version before modules: 1.1.755
///////////////////////////////////////////////
// Options ////////////////////////////////////

View File

@ -137,12 +137,20 @@ namespace DG.Tweening.Plugins
t.miscInt = newWaypointIndex;
if (t.onWaypointChange != null) {
// If more than one waypoint changed, dispatch multiple callbacks
bool isBackwards = newWaypointIndex < prevWPIndex;
// bool isBackwards = newWaypointIndex < prevWPIndex;
bool isBackwards = t.isBackwards;
if (t.loopType == LoopType.Yoyo) {
isBackwards = !t.isBackwards && t.loops > 1 && t.completedLoops % 2 != 0
|| t.isBackwards && t.loops > 1 && t.completedLoops % 2 == 0;
}
if (isBackwards) {
// for (int i = prevWPIndex - 1; i > newWaypointIndex - 1; --i) Tween.OnTweenCallback(t.onWaypointChange, i);
for (int i = prevWPIndex - 1; i > newWaypointIndex - 1; --i) Tween.OnTweenCallback(t.onWaypointChange, i);
} else {
for (int i = prevWPIndex + 1; i < newWaypointIndex + 1; ++i) Tween.OnTweenCallback(t.onWaypointChange, i);
// for (int i = prevWPIndex + 1; i < newWaypointIndex + 1; ++i) Tween.OnTweenCallback(t.onWaypointChange, i);
for (int i = prevWPIndex + 1; i < newWaypointIndex; ++i) Tween.OnTweenCallback(t.onWaypointChange, i);
}
Tween.OnTweenCallback(t.onWaypointChange, newWaypointIndex);
}
}
}

Binary file not shown.