1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2026-03-01 21:29:08 +08:00

Optimized DOJump methods (now they work with SetDelay and OnUpdate)

This commit is contained in:
Daniele Giardini 2015-07-08 12:05:50 +02:00
parent eae6a855c0
commit 78356c2c89
49 changed files with 73 additions and 61 deletions

View File

@ -9,15 +9,20 @@ using UnityEngine.UI;
public class TempTests : BrainBase public class TempTests : BrainBase
{ {
public Transform trans; public Transform target;
public Renderer rend; public float delay = 0;
IEnumerator Start() void Start()
{ {
yield return new WaitForSeconds(1); Tween t = target.DOJump(new Vector3(4, 3, 0), 2, 1, 1).SetRelative();
if (delay > 0) t.SetDelay(delay);
t.OnStart(()=>Debug.Log("Start"));
t.OnComplete(()=>Debug.Log("Complete"));
DOTween.Sequence()
.Append(rend.material.DOFade(0, 0.5f)) // Tween t = DOTween.Sequence().Append(target.DOMoveX(2, 1).SetRelative());
.Append(rend.material.DOFade(1, 1f)); // if (delay > 0) t.SetDelay(delay);
// t.OnStart(()=>Debug.Log("Start"));
// t.OnComplete(()=>Debug.Log("Complete"));
} }
} }

View File

@ -39,7 +39,8 @@ namespace DG.Tweening
internal static Sequence DoPrepend(Sequence inSequence, Tween t) internal static Sequence DoPrepend(Sequence inSequence, Tween t)
{ {
if (t.loops == -1) t.loops = 1; if (t.loops == -1) t.loops = 1;
float tFullTime = t.delay + (t.duration * t.loops); // float tFullTime = t.delay + (t.duration * t.loops);
float tFullTime = t.duration * t.loops;
inSequence.duration += tFullTime; inSequence.duration += tFullTime;
int len = inSequence._sequencedObjs.Count; int len = inSequence._sequencedObjs.Count;
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
@ -55,17 +56,17 @@ namespace DG.Tweening
{ {
TweenManager.AddActiveTweenToSequence(t); TweenManager.AddActiveTweenToSequence(t);
// If t has a delay add it as an interval // // If t has a delay add it as an interval
atPosition += t.delay; // atPosition += t.delay;
inSequence.lastTweenInsertTime = atPosition; // inSequence.lastTweenInsertTime = atPosition;
t.isSequenced = t.creationLocked = true; t.isSequenced = t.creationLocked = true;
t.sequenceParent = inSequence; t.sequenceParent = inSequence;
if (t.loops == -1) t.loops = 1; if (t.loops == -1) t.loops = 1;
float tFullTime = t.duration * t.loops; float tFullTime = t.duration * t.loops;
t.autoKill = false; t.autoKill = false;
t.delay = t.elapsedDelay = 0; // t.delay = t.elapsedDelay = 0;
t.delayComplete = true; // t.delayComplete = true;
t.isSpeedBased = false; t.isSpeedBased = false;
t.sequencedPosition = atPosition; t.sequencedPosition = atPosition;
t.sequencedEndPosition = atPosition + tFullTime; t.sequencedEndPosition = atPosition + tFullTime;

View File

@ -442,13 +442,22 @@ namespace DG.Tweening
float startPosY = target.position.y; float startPosY = target.position.y;
float offsetY = -1; float offsetY = -1;
bool offsetYSet = false; bool offsetYSet = false;
Sequence s = DOTween.Sequence() Sequence s = DOTween.Sequence();
#if COMPATIBLE #if COMPATIBLE
.Append(DOTween.To(() => target.position, x => target.MovePosition(x.value), new Vector3(endValue.x, 0, 0), duration) s.Append(DOTween.To(() => target.position, x => target.MovePosition(x.value), new Vector3(endValue.x, 0, 0), duration)
#else #else
.Append(DOTween.To(() => target.position, target.MovePosition, new Vector3(endValue.x, 0, 0), duration) s.Append(DOTween.To(() => target.position, target.MovePosition, new Vector3(endValue.x, 0, 0), duration)
#endif #endif
.SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear) .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)
.OnUpdate(() => {
if (!offsetYSet) {
offsetYSet = false;
offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
}
Vector3 pos = target.position;
pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad);
target.MovePosition(pos);
})
#if COMPATIBLE #if COMPATIBLE
).Join(DOTween.To(() => target.position, x => target.MovePosition(x.value), new Vector3(0, 0, endValue.z), duration) ).Join(DOTween.To(() => target.position, x => target.MovePosition(x.value), new Vector3(0, 0, endValue.z), duration)
#else #else
@ -463,15 +472,6 @@ namespace DG.Tweening
.SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad) .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad)
.SetLoops(numJumps * 2, LoopType.Yoyo).SetRelative() .SetLoops(numJumps * 2, LoopType.Yoyo).SetRelative()
).SetTarget(target).SetEase(DOTween.defaultEaseType); ).SetTarget(target).SetEase(DOTween.defaultEaseType);
s.OnUpdate(() => {
if (!offsetYSet) {
offsetYSet = false;
offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
}
Vector3 pos = target.position;
pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad);
target.MovePosition(pos);
});
return s; return s;
} }
@ -803,24 +803,26 @@ namespace DG.Tweening
float startPosY = target.position.y; float startPosY = target.position.y;
float offsetY = -1; float offsetY = -1;
bool offsetYSet = false; bool offsetYSet = false;
Sequence s = DOTween.Sequence()
.Append(DOTween.To(() => target.position, x => target.position = x, new Vector3(endValue.x, 0, 0), duration)
Sequence s = DOTween.Sequence();
s.Append(DOTween.To(() => target.position, x => target.position = x, new Vector3(endValue.x, 0, 0), duration)
.SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear) .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)
.OnUpdate(() => {
if (!offsetYSet) {
offsetYSet = false;
offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
}
Vector3 pos = target.position;
pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad);
target.position = pos;
})
).Join(DOTween.To(() => target.position, x => target.position = x, new Vector3(0, 0, endValue.z), duration) ).Join(DOTween.To(() => target.position, x => target.position = x, new Vector3(0, 0, endValue.z), duration)
.SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear) .SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear)
).Join(DOTween.To(() => target.position, x => target.position = x, new Vector3(0, jumpPower, 0), duration / (numJumps * 2)) ).Join(DOTween.To(() => target.position, x => target.position = x, new Vector3(0, jumpPower, 0), duration / (numJumps * 2))
.SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative() .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative()
.SetLoops(numJumps * 2, LoopType.Yoyo) .SetLoops(numJumps * 2, LoopType.Yoyo)
).SetTarget(target).SetEase(DOTween.defaultEaseType); ).SetTarget(target).SetEase(DOTween.defaultEaseType);
s.OnUpdate(() => {
if (!offsetYSet) {
offsetYSet = false;
offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
}
Vector3 pos = target.position;
pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad);
target.position = pos;
});
return s; return s;
} }
/// <summary>Tweens a Transform's localPosition to the given value, while also applying a jump effect along the Y axis. /// <summary>Tweens a Transform's localPosition to the given value, while also applying a jump effect along the Y axis.
@ -837,24 +839,24 @@ namespace DG.Tweening
float startPosY = target.localPosition.y; float startPosY = target.localPosition.y;
float offsetY = -1; float offsetY = -1;
bool offsetYSet = false; bool offsetYSet = false;
Sequence s = DOTween.Sequence() Sequence s = DOTween.Sequence();
.Append(DOTween.To(() => target.localPosition, x => target.localPosition = x, new Vector3(endValue.x, 0, 0), duration) s.Append(DOTween.To(() => target.localPosition, x => target.localPosition = x, new Vector3(endValue.x, 0, 0), duration)
.SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear) .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)
.OnUpdate(() => {
if (!offsetYSet) {
offsetYSet = false;
offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
}
Vector3 pos = target.localPosition;
pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad);
target.localPosition = pos;
})
).Join(DOTween.To(() => target.localPosition, x => target.localPosition = x, new Vector3(0, 0, endValue.z), duration) ).Join(DOTween.To(() => target.localPosition, x => target.localPosition = x, new Vector3(0, 0, endValue.z), duration)
.SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear) .SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear)
).Join(DOTween.To(() => target.localPosition, x => target.localPosition = x, new Vector3(0, jumpPower, 0), duration / (numJumps * 2)) ).Join(DOTween.To(() => target.localPosition, x => target.localPosition = x, new Vector3(0, jumpPower, 0), duration / (numJumps * 2))
.SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative() .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative()
.SetLoops(numJumps * 2, LoopType.Yoyo) .SetLoops(numJumps * 2, LoopType.Yoyo)
).SetTarget(target).SetEase(DOTween.defaultEaseType); ).SetTarget(target).SetEase(DOTween.defaultEaseType);
s.OnUpdate(() => {
if (!offsetYSet) {
offsetYSet = false;
offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
}
Vector3 pos = target.localPosition;
pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad);
target.localPosition = pos;
});
return s; return s;
} }

View File

@ -540,8 +540,12 @@ namespace DG.Tweening
{ {
if (t == null || !t.active || t.creationLocked) return t; if (t == null || !t.active || t.creationLocked) return t;
t.delay = delay; if (t.tweenType == TweenType.Sequence) {
t.delayComplete = delay <= 0; (t as Sequence).PrependInterval(delay);
} else {
t.delay = delay;
t.delayComplete = delay <= 0;
}
return t; return t;
} }

View File

@ -105,13 +105,22 @@ namespace DG.Tweening
float startPosY = target.position.y; float startPosY = target.position.y;
float offsetY = -1; float offsetY = -1;
bool offsetYSet = false; bool offsetYSet = false;
Sequence s = DOTween.Sequence() Sequence s = DOTween.Sequence();
#if COMPATIBLE #if COMPATIBLE
.Append(DOTween.To(() => target.position, x => target.MovePosition(x.value), new Vector3(endValue.x, 0, 0), duration) s.Append(DOTween.To(() => target.position, x => target.MovePosition(x.value), new Vector3(endValue.x, 0, 0), duration)
#else #else
.Append(DOTween.To(() => target.position, target.MovePosition, new Vector2(endValue.x, 0), duration) s.Append(DOTween.To(() => target.position, target.MovePosition, new Vector2(endValue.x, 0), duration)
#endif #endif
.SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear) .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)
.OnUpdate(() => {
if (!offsetYSet) {
offsetYSet = false;
offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
}
Vector2 pos = target.position;
pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad);
target.MovePosition(pos);
})
#if COMPATIBLE #if COMPATIBLE
).Join(DOTween.To(() => target.position, x => target.MovePosition(x.value), new Vector3(0, jumpPower, 0), duration / (numJumps * 2)) ).Join(DOTween.To(() => target.position, x => target.MovePosition(x.value), new Vector3(0, jumpPower, 0), duration / (numJumps * 2))
#else #else
@ -120,15 +129,6 @@ namespace DG.Tweening
.SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad) .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad)
.SetLoops(numJumps * 2, LoopType.Yoyo).SetRelative() .SetLoops(numJumps * 2, LoopType.Yoyo).SetRelative()
).SetTarget(target).SetEase(DOTween.defaultEaseType); ).SetTarget(target).SetEase(DOTween.defaultEaseType);
s.OnUpdate(() => {
if (!offsetYSet) {
offsetYSet = false;
offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
}
Vector2 pos = target.position;
pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad);
target.MovePosition(pos);
});
return s; return s;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.