Skip to content

Commit

Permalink
Fixed decreasing uint tweens not working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Demigiant committed May 30, 2016
1 parent d151ff5 commit 49678b4
Show file tree
Hide file tree
Showing 50 changed files with 47 additions and 23 deletions.
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 modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween.dll
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween43.dll
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween43.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween46.dll
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween46.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween50.dll
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween50.dll.mdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween43.dll
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween43.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween46.dll
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween46.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween50.dll
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween50.dll.mdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/_Tests PRO/TempPro.unity
Binary file not shown.
2 changes: 1 addition & 1 deletion UnityTests.Unity5/Assets/_Tests/RichText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ IEnumerator Start()

TweenParams tp = new TweenParams().SetEase(Ease.Linear);
tp.SetSpeedBased(speedBased);
txtRichA.DOText("This is a <color=#ff0000>colored <color=#00ff00>text</color></color> and normal text", duration, true, scrambleMode).SetAs(tp);
txtRichA.DOText("This is a <color=#ff0000>colored <color=#00ff00>text</color></color> and normal text. And this is a minor sign: <", duration, true, scrambleMode).SetAs(tp);
txtA.DOText("This is a colored text and normal text", duration, true, scrambleMode).SetAs(tp);
}
}
Binary file modified UnityTests.Unity5/Assets/_Tests/RichText.unity
Binary file not shown.
10 changes: 4 additions & 6 deletions UnityTests.Unity5/Assets/_Tests/TempTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@

public class TempTests : BrainBase
{
public RectTransform target;
public uint test = 1000;
public uint to = 0;

IEnumerator Start ()
{
yield return new WaitForSeconds(0.5f);

target.DOPivot(Vector2.zero, 2);
void Start () {
DOTween.To(()=> test, x=> test = x, to, 2.0f).OnUpdate(()=> Debug.Log("1000 to 0 > " + test));
}
}
Binary file modified UnityTests.Unity5/Assets/_Tests/TempTests.unity
Binary file not shown.
4 changes: 2 additions & 2 deletions _DOTween.Assembly/DOTween/DOTween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace DG.Tweening
public class DOTween
{
/// <summary>DOTween's version</summary>
public static readonly string Version = "1.1.290";
public static readonly string Version = "1.1.300";

///////////////////////////////////////////////
// Options ////////////////////////////////////
Expand Down Expand Up @@ -304,7 +304,7 @@ public static Tweener To(DOGetter<int> getter, DOSetter<int> setter, int endValu
/// <para>Example usage with lambda:</para><code>x=> myProperty = x</code></param>
/// <param name="endValue">The end value to reach</param><param name="duration">The tween's duration</param>
public static Tweener To(DOGetter<uint> getter, DOSetter<uint> setter, uint endValue, float duration)
{ return ApplyTo<uint, uint, NoOptions>(getter, setter, endValue, duration); }
{ return ApplyTo<uint, uint, UintOptions>(getter, setter, endValue, duration); }
/// <summary>Tweens a property or field to the given value using default plugins</summary>
/// <param name="getter">A getter for the field or property to tween.
/// <para>Example usage with lambda:</para><code>()=> myProperty</code></param>
Expand Down
1 change: 1 addition & 0 deletions _DOTween.Assembly/DOTween/DOTween.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<Compile Include="Plugins\LongPlugin.cs" />
<Compile Include="Plugins\Options\PathOptions.cs" />
<Compile Include="Plugins\Options\QuaternionOptions.cs" />
<Compile Include="Plugins\Options\UintOptions.cs" />
<Compile Include="Plugins\Options\Vector3ArrayOptions.cs" />
<Compile Include="Plugins\QuaternionWrapperPlugin.cs" />
<Compile Include="Plugins\UlongPlugin.cs" />
Expand Down
13 changes: 13 additions & 0 deletions _DOTween.Assembly/DOTween/Plugins/Options/UintOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2016/05/30 13:00
// License Copyright (c) Daniele Giardini
// This work is subject to the terms at http://dotween.demigiant.com/license.php

#pragma warning disable 1591
namespace DG.Tweening.Plugins.Options
{
public struct UintOptions
{
public bool isNegativeChangeValue; // Necessary because uints can't obviously be negative
}
}
4 changes: 2 additions & 2 deletions _DOTween.Assembly/DOTween/Plugins/StringPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ StringBuilder Append(string value, int startIndex, int length, bool richTextEnab
int fullLen = value.Length;
int i;
for (i = 0; i < length; ++i) {
Char c = value[i];
char c = value[i];
if (c == '<') {
bool hadOpenTag = hasOpenTag;
char nextChar = value[i + 1];
Expand All @@ -141,7 +141,7 @@ StringBuilder Append(string value, int startIndex, int length, bool richTextEnab
Match m = Regex.Match(s, tagMatch);
if (m.Success) {
if (!hasOpenTag && !hadOpenTag) {
// We have a closing tag without an opening tag, try to find previous correct opening tag an apply it
// We have a closing tag without an opening tag, try to find previous correct opening tag and apply it
char closingTagFirstChar = value[i + 1];
char[] openingTagLookouts;
if (closingTagFirstChar == 'c') openingTagLookouts = new[] { '#', 'c' };
Expand Down
36 changes: 24 additions & 12 deletions _DOTween.Assembly/DOTween/Plugins/UintPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,65 @@
using DG.Tweening.Core.Enums;
using DG.Tweening.Plugins.Core;
using DG.Tweening.Plugins.Options;
using UnityEngine;

#pragma warning disable 1591
namespace DG.Tweening.Plugins
{
public class UintPlugin : ABSTweenPlugin<uint, uint, NoOptions>
public class UintPlugin : ABSTweenPlugin<uint, uint, UintOptions>
{
public override void Reset(TweenerCore<uint, uint, NoOptions> t) { }
public override void Reset(TweenerCore<uint, uint, UintOptions> t) { }

public override void SetFrom(TweenerCore<uint, uint, NoOptions> t, bool isRelative)
public override void SetFrom(TweenerCore<uint, uint, UintOptions> t, bool isRelative)
{
uint prevEndVal = t.endValue;
t.endValue = t.getter();
t.startValue = isRelative ? t.endValue + prevEndVal : prevEndVal;
t.setter(t.startValue);
}

public override uint ConvertToStartValue(TweenerCore<uint, uint, NoOptions> t, uint value)
public override uint ConvertToStartValue(TweenerCore<uint, uint, UintOptions> t, uint value)
{
return value;
}

public override void SetRelativeEndValue(TweenerCore<uint, uint, NoOptions> t)
public override void SetRelativeEndValue(TweenerCore<uint, uint, UintOptions> t)
{
t.endValue += t.startValue;
}

public override void SetChangeValue(TweenerCore<uint, uint, NoOptions> t)
public override void SetChangeValue(TweenerCore<uint, uint, UintOptions> t)
{
t.changeValue = t.endValue - t.startValue;
t.plugOptions.isNegativeChangeValue = t.endValue < t.startValue;
t.changeValue = t.plugOptions.isNegativeChangeValue ? t.startValue - t.endValue : t.endValue - t.startValue;
// t.changeValue = t.endValue - t.startValue;
}

public override float GetSpeedBasedDuration(NoOptions options, float unitsXSecond, uint changeValue)
public override float GetSpeedBasedDuration(UintOptions options, float unitsXSecond, uint changeValue)
{
float res = changeValue / unitsXSecond;
if (res < 0) res = -res;
return res;
}

public override void EvaluateAndApply(NoOptions options, Tween t, bool isRelative, DOGetter<uint> getter, DOSetter<uint> setter, float elapsed, uint startValue, uint changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice)
public override void EvaluateAndApply(UintOptions options, Tween t, bool isRelative, DOGetter<uint> getter, DOSetter<uint> setter, float elapsed, uint startValue, uint changeValue, float duration, bool usingInversePosition, UpdateNotice updateNotice)
{
if (t.loopType == LoopType.Incremental) startValue += (uint)(changeValue * (t.isComplete ? t.completedLoops - 1 : t.completedLoops));
uint v;
if (t.loopType == LoopType.Incremental) {
v = (uint)(changeValue * (t.isComplete ? t.completedLoops - 1 : t.completedLoops));
if (options.isNegativeChangeValue) startValue -= v;
else startValue += v;
}
if (t.isSequenced && t.sequenceParent.loopType == LoopType.Incremental) {
startValue += (uint)(changeValue * (t.loopType == LoopType.Incremental ? t.loops : 1)
v = (uint)(changeValue * (t.loopType == LoopType.Incremental ? t.loops : 1)
* (t.sequenceParent.isComplete ? t.sequenceParent.completedLoops - 1 : t.sequenceParent.completedLoops));
if (options.isNegativeChangeValue) startValue -= v;
else startValue += v;
}

setter((uint)Math.Round(startValue + changeValue * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod)));
v = (uint)Math.Round(changeValue * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod));
if (options.isNegativeChangeValue) setter(startValue - v);
else setter(startValue + v);
}
}
}
Binary file modified _DOTween.Assembly/bin/DOTween.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween.dll.mdb
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween43.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween43.dll.mdb
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween46.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween46.dll.mdb
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween50.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween50.dll.mdb
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/Editor/DOTweenEditor.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/Editor/DOTweenEditor.dll.mdb
Binary file not shown.

0 comments on commit 49678b4

Please sign in to comment.