Skip to content

Commit c45548e

Browse files
committed
reversed and Restart()
1 parent 7d99cc0 commit c45548e

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

TweenSharp.cs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class TweenSharp: TSTimeDef
1111
public Action onUpdate = null;
1212
public Action<object> onUpdateArg = null;
1313
public object onUpdateParams = null;
14+
public bool reversed = false;
1415

1516
/*
1617
, onCompleteScope:1,
@@ -107,24 +108,43 @@ public TweenSharp(object target, float duration, Dictionary<string, object> args
107108
}
108109
}
109110

110-
111111
TSScheduler.Register(this);
112112
}
113113

114+
public void Restart()
115+
{
116+
startTime = Time.realtimeSinceStartup;
117+
}
118+
114119
public override bool Update(float time)
115120
{
116121
if (startTime + delay < time)
117122
{
118123
int len = propertyNames.Count;
119-
float timePassed = time - startTime - delay;
124+
float timePassed;
120125
bool finished = false;
121126

122-
if (timePassed > duration)
127+
if (reversed)
128+
{
129+
timePassed = duration - (time - startTime - delay);
130+
if (timePassed <= 0)
131+
{
132+
timePassed = 0;
133+
finished = true;
134+
}
135+
}
136+
else
123137
{
124-
timePassed = duration;
125-
finished = true;
138+
timePassed = time - startTime - delay;
139+
140+
if (timePassed > duration)
141+
{
142+
timePassed = duration;
143+
finished = true;
144+
}
126145
}
127146

147+
128148
for (int i = 0; i < len; i++)
129149
{
130150
float startVal = propertyStartValues[i];

0 commit comments

Comments
 (0)