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

[BUGFIX] Fixed bug with DOJump when in a Sequence that contained a DOMove before the jump

+ Implemented test version of WaitForCompletionCY
This commit is contained in:
Demigiant 2018-06-01 16:04:49 +02:00
parent 53bc29474c
commit bc02db900d
58 changed files with 196 additions and 137 deletions

View File

@ -108,5 +108,18 @@
and returns the total number of tweens involved. and returns the total number of tweens involved.
</summary> </summary>
</member> </member>
<member name="T:DG.Tweening.TweenExtensions53">
<summary>
Methods that extend Tween objects and allow to control or get data from them.
These require at least Unity 5.3
</summary>
</member>
<member name="M:DG.Tweening.TweenExtensions53.WaitForCompletionCY(DG.Tweening.Tween)">
<summary>
Returns a <see cref="T:UnityEngine.CustomYieldInstruction"/> that waits until the tween is killed or complete.
It can be used inside a coroutine as a yield.
<para>Example usage:</para><code>yield return myTween.WaitForCompletionCY();</code>
</summary>
</member>
</members> </members>
</doc> </doc>

View File

@ -108,5 +108,18 @@
and returns the total number of tweens involved. and returns the total number of tweens involved.
</summary> </summary>
</member> </member>
<member name="T:DG.Tweening.TweenExtensions53">
<summary>
Methods that extend Tween objects and allow to control or get data from them.
These require at least Unity 5.3
</summary>
</member>
<member name="M:DG.Tweening.TweenExtensions53.WaitForCompletionCY(DG.Tweening.Tween)">
<summary>
Returns a <see cref="T:UnityEngine.CustomYieldInstruction"/> that waits until the tween is killed or complete.
It can be used inside a coroutine as a yield.
<para>Example usage:</para><code>yield return myTween.WaitForCompletionCY();</code>
</summary>
</member>
</members> </members>
</doc> </doc>

View File

@ -108,5 +108,18 @@
and returns the total number of tweens involved. and returns the total number of tweens involved.
</summary> </summary>
</member> </member>
<member name="T:DG.Tweening.TweenExtensions53">
<summary>
Methods that extend Tween objects and allow to control or get data from them.
These require at least Unity 5.3
</summary>
</member>
<member name="M:DG.Tweening.TweenExtensions53.WaitForCompletionCY(DG.Tweening.Tween)">
<summary>
Returns a <see cref="T:UnityEngine.CustomYieldInstruction"/> that waits until the tween is killed or complete.
It can be used inside a coroutine as a yield.
<para>Example usage:</para><code>yield return myTween.WaitForCompletionCY();</code>
</summary>
</member>
</members> </members>
</doc> </doc>

View File

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using DG.Tweening.CustomYieldInstructions;
using UnityEngine;
public class CustomYieldInstructions : BrainBase
{
public Transform target;
IEnumerator Start()
{
yield return new WaitForSeconds(1);
Debug.Log("01");
yield return target.DOMoveX(2, 1).WaitForCompletionCY();
Debug.Log("02");
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0e2609f52a4e23643be3f692520e0148
timeCreated: 1527844217
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 06794199ff7400946acd72ccd1ad4fbb
DefaultImporter:
userData:

View File

@ -11,120 +11,18 @@ using UnityEngine.UI;
public class TempTests : BrainBase public class TempTests : BrainBase
{ {
public float TimeScale = 1; public Transform target;
public int ConcurrentRunningSequences = 10000;
public int loops = 1;
public LoopType loopType = LoopType.Restart;
int _createdSequenceCount; IEnumerator Start()
int _completedSequenceCount;
int _callbackZeroCount;
int _callbackOneCount;
int _callbackTwoCount;
int _callbackThreeCount;
bool _isTestingInProgress = false;
float _time;
void Start()
{ {
DOTween.Init(); yield return new WaitForSeconds(1);
DOTween.SetTweensCapacity(200, 30000);
}
void Update() Sequence s = DOTween.Sequence()
{ .OnStart(() => Debug.Log("START"))
Time.timeScale = TimeScale; .Append(target.DOMoveX(2, 1).OnStart(() => Debug.Log("Append X")))
} .SetDelay(1)
.Join(target.DOMoveY(2, 1).OnStart(() => Debug.Log("Join y")))
void OnGUI() .SetDelay(2)
{ .OnComplete(()=> Debug.Log("COMPLETE"));
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"));
} }
} }

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CY/@EntryIndexedValue">CY</s:String></wpf:ResourceDictionary>

View File

@ -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.1.735"; public static readonly string Version = "1.1.745";
/////////////////////////////////////////////// ///////////////////////////////////////////////
// Options //////////////////////////////////// // Options ////////////////////////////////////

View File

@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("DOTweenEditor")] [assembly: InternalsVisibleTo("DOTweenEditor")]
[assembly: InternalsVisibleTo("DOTween43")] [assembly: InternalsVisibleTo("DOTween43")]
[assembly: InternalsVisibleTo("DOTween46")] [assembly: InternalsVisibleTo("DOTween46")]
[assembly: InternalsVisibleTo("DOTween50")]
[assembly: InternalsVisibleTo("DOTweenPro")] [assembly: InternalsVisibleTo("DOTweenPro")]
[assembly: InternalsVisibleTo("DOTweenProEditor")] [assembly: InternalsVisibleTo("DOTweenProEditor")]

View File

@ -461,19 +461,21 @@ namespace DG.Tweening
public static Sequence DOJump(this Rigidbody target, Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) public static Sequence DOJump(this Rigidbody target, Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping = false)
{ {
if (numJumps < 1) numJumps = 1; if (numJumps < 1) numJumps = 1;
float startPosY = target.position.y; float startPosY = 0;
float offsetY = -1; float offsetY = -1;
bool offsetYSet = false; bool offsetYSet = false;
Sequence s = DOTween.Sequence(); Sequence s = DOTween.Sequence();
#if COMPATIBLE #if COMPATIBLE
Tween yTween = DOTween.To(() => target.position, x => target.MovePosition(x.value), new Vector3(0, jumpPower, 0), duration / (numJumps * 2)) Tween yTween = DOTween.To(() => target.position, x => target.MovePosition(x.value), 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)
.OnStart(()=> startPosY = target.position.y);
s.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
Tween yTween = DOTween.To(() => target.position, target.MovePosition, new Vector3(0, jumpPower, 0), duration / (numJumps * 2)) Tween yTween = DOTween.To(() => target.position, target.MovePosition, 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)
.OnStart(() => startPosY = target.position.y);
s.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)
@ -972,7 +974,7 @@ namespace DG.Tweening
public static Sequence DOJump(this Transform target, Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) public static Sequence DOJump(this Transform target, Vector3 endValue, float jumpPower, int numJumps, float duration, bool snapping = false)
{ {
if (numJumps < 1) numJumps = 1; if (numJumps < 1) numJumps = 1;
float startPosY = target.position.y; float startPosY = 0;
float offsetY = -1; float offsetY = -1;
bool offsetYSet = false; bool offsetYSet = false;
@ -981,7 +983,8 @@ namespace DG.Tweening
Sequence s = DOTween.Sequence(); Sequence s = DOTween.Sequence();
Tween yTween = DOTween.To(() => target.position, x => target.position = x, new Vector3(0, jumpPower, 0), duration / (numJumps * 2)) Tween yTween = 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)
.OnStart(()=> startPosY = target.position.y);
s.Append(DOTween.To(() => target.position, x => target.position = x, new Vector3(endValue.x, 0, 0), duration) 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)
).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)

View File

@ -178,33 +178,35 @@ namespace DG.Tweening
public static Sequence DOJump(this Rigidbody2D target, Vector2 endValue, float jumpPower, int numJumps, float duration, bool snapping = false) public static Sequence DOJump(this Rigidbody2D target, Vector2 endValue, float jumpPower, int numJumps, float duration, bool snapping = false)
{ {
if (numJumps < 1) numJumps = 1; if (numJumps < 1) numJumps = 1;
float startPosY = target.position.y; float startPosY = 0;
float offsetY = -1; float offsetY = -1;
bool offsetYSet = false; bool offsetYSet = false;
Sequence s = DOTween.Sequence(); Sequence s = DOTween.Sequence();
#if COMPATIBLE #if COMPATIBLE
s.Append(DOTween.To(() => target.position, x => target.position = x.value, new Vector3(endValue.x, 0, 0), duration) Tween yTween = DOTween.To(() => target.position, x => target.position = x.value, new Vector2(0, jumpPower), duration / (numJumps * 2))
.SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative()
.SetLoops(numJumps * 2, LoopType.Yoyo)
.OnStart(() => startPosY = target.position.y);
s.Append(DOTween.To(() => target.position, x => target.position = x.value, new Vector2(endValue.x, 0), duration)
#else #else
Tween yTween = DOTween.To(() => target.position, x => target.position = x, new Vector2(0, jumpPower), duration / (numJumps * 2))
.SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative()
.SetLoops(numJumps * 2, LoopType.Yoyo)
.OnStart(() => startPosY = target.position.y);
s.Append(DOTween.To(() => target.position, x => target.position = x, new Vector2(endValue.x, 0), duration) s.Append(DOTween.To(() => target.position, x => target.position = x, new Vector2(endValue.x, 0), duration)
#endif #endif
.SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear) .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)
.OnUpdate(() => { ).Join(yTween)
if (!offsetYSet) { .SetTarget(target).SetEase(DOTween.defaultEaseType);
offsetYSet = true; yTween.OnUpdate(() => {
offsetY = s.isRelative ? endValue.y : endValue.y - startPosY; if (!offsetYSet) {
} offsetYSet = true;
Vector2 pos = target.position; offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
pos.y += DOVirtual.EasedValue(0, offsetY, s.ElapsedDirectionalPercentage(), Ease.OutQuad); }
target.position = pos; Vector3 pos = target.position;
}) pos.y += DOVirtual.EasedValue(0, offsetY, yTween.ElapsedPercentage(), Ease.OutQuad);
#if COMPATIBLE target.MovePosition(pos);
).Join(DOTween.To(() => target.position, x => target.position = x.value, new Vector3(0, jumpPower, 0), duration / (numJumps * 2)) });
#else
).Join(DOTween.To(() => target.position, x=> target.position = x, new Vector2(0, jumpPower), duration / (numJumps * 2))
#endif
.SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad)
.SetLoops(numJumps * 2, LoopType.Yoyo).SetRelative()
).SetTarget(target).SetEase(DOTween.defaultEaseType);
return s; return s;
} }

View File

@ -0,0 +1,26 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2018/06/01 10:55
// License Copyright (c) Daniele Giardini
// This work is subject to the terms at http://dotween.demigiant.com/license.php
using UnityEngine;
#pragma warning disable 1591
namespace DG.Tweening.CustomYieldInstructions
{
public class WaitForCompletion : CustomYieldInstruction
{
public override bool keepWaiting {
get {
return _tween.active && !_tween.isComplete;
}
}
readonly Tween _tween;
public WaitForCompletion(Tween tween)
{
_tween = tween;
}
}
}

View File

@ -67,8 +67,10 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CustomYieldInstructions\WaitForCompletion.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShortcutExtensions50.cs" /> <Compile Include="ShortcutExtensions50.cs" />
<Compile Include="TweenExtensions53.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DOTween\DOTween.csproj"> <ProjectReference Include="..\DOTween\DOTween.csproj">
@ -77,6 +79,7 @@
<Private>False</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>set BinDir=bin.Global\DOTween <PostBuildEvent>set BinDir=bin.Global\DOTween

View File

@ -0,0 +1,37 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2018/06/01 10:49
// License Copyright (c) Daniele Giardini
// This work is subject to the terms at http://dotween.demigiant.com/license.php
using DG.Tweening.Core;
using DG.Tweening.CustomYieldInstructions;
using UnityEngine;
namespace DG.Tweening
{
/// <summary>
/// Methods that extend Tween objects and allow to control or get data from them.
/// These require at least Unity 5.3
/// </summary>
public static class TweenExtensions53
{
#region Custom Yield Instructions
/// <summary>
/// Returns a <see cref="CustomYieldInstruction"/> that waits until the tween is killed or complete.
/// It can be used inside a coroutine as a yield.
/// <para>Example usage:</para><code>yield return myTween.WaitForCompletionCY();</code>
/// </summary>
public static CustomYieldInstruction WaitForCompletionCY(this Tween t)
{
if (!t.active) {
if (Debugger.logPriority > 0) Debugger.LogInvalidTween(t);
return null;
}
return new WaitForCompletion(t);
}
#endregion
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -108,5 +108,18 @@
and returns the total number of tweens involved. and returns the total number of tweens involved.
</summary> </summary>
</member> </member>
<member name="T:DG.Tweening.TweenExtensions53">
<summary>
Methods that extend Tween objects and allow to control or get data from them.
These require at least Unity 5.3
</summary>
</member>
<member name="M:DG.Tweening.TweenExtensions53.WaitForCompletionCY(DG.Tweening.Tween)">
<summary>
Returns a <see cref="T:UnityEngine.CustomYieldInstruction"/> that waits until the tween is killed or complete.
It can be used inside a coroutine as a yield.
<para>Example usage:</para><code>yield return myTween.WaitForCompletionCY();</code>
</summary>
</member>
</members> </members>
</doc> </doc>