Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 84d138d

Browse files
author
Yuncong Zhang
committed
Tmp store.
1 parent 863b798 commit 84d138d

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

Runtime/animation/animation_controller.cs

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ public TickerFuture forward(float? from = null) {
155155

156156
return true;
157157
});
158+
D.assert(
159+
this._ticker != null,
160+
"AnimationController.forward() called after AnimationController.dispose()\n" +
161+
"AnimationController methods should not be used after calling dispose."
162+
);
158163
this._direction = _AnimationDirection.forward;
159164
if (from != null) {
160165
this.setValue(from.Value);
@@ -175,6 +180,11 @@ public TickerFuture reverse(float? from = null) {
175180

176181
return true;
177182
});
183+
D.assert(
184+
this._ticker != null,
185+
"AnimationController.reverse() called after AnimationController.dispose()\n" +
186+
"AnimationController methods should not be used after calling dispose."
187+
);
178188
this._direction = _AnimationDirection.reverse;
179189
if (from != null) {
180190
this.setValue(from.Value);
@@ -184,11 +194,27 @@ public TickerFuture reverse(float? from = null) {
184194
}
185195

186196
public TickerFuture animateTo(float target, TimeSpan? duration = null, Curve curve = null) {
197+
D.assert(
198+
this._ticker != null,
199+
"AnimationController.animateTo() called after AnimationController.dispose()\n" +
200+
"AnimationController methods should not be used after calling dispose."
201+
);
187202
curve = curve ?? Curves.linear;
188203

189204
this._direction = _AnimationDirection.forward;
190205
return this._animateToInternal(target, duration: duration, curve: curve);
191206
}
207+
208+
TickerFuture animateBack(float target, TimeSpan? duration, Curve curve = null) {
209+
D.assert(
210+
this._ticker != null,
211+
"AnimationController.animateBack() called after AnimationController.dispose()\n" +
212+
"AnimationController methods should not be used after calling dispose."
213+
);
214+
curve = curve ?? Curves.linear;
215+
this._direction = _AnimationDirection.reverse;
216+
return this._animateToInternal(target, duration, curve);
217+
}
192218

193219
TickerFuture _animateToInternal(float target, TimeSpan? duration = null, Curve curve = null) {
194220
curve = curve ?? Curves.linear;
@@ -236,7 +262,7 @@ TickerFuture _animateToInternal(float target, TimeSpan? duration = null, Curve c
236262
new _InterpolationSimulation(this._value, target, simulationDuration.Value, curve));
237263
}
238264

239-
public TickerFuture repeat(float? min = null, float? max = null, TimeSpan? period = null) {
265+
public TickerFuture repeat(float? min = null, float? max = null, bool reverse = false, TimeSpan? period = null) {
240266
min = min ?? this.lowerBound;
241267
max = max ?? this.upperBound;
242268
period = period ?? this.duration;
@@ -252,7 +278,11 @@ public TickerFuture repeat(float? min = null, float? max = null, TimeSpan? perio
252278

253279
return true;
254280
});
255-
return this.animateWith(new _RepeatingSimulation(min.Value, max.Value, period.Value));
281+
282+
D.assert(max >= min);
283+
D.assert(max <= this.upperBound && min >= this.lowerBound);
284+
D.assert(reverse != null);
285+
return this.animateWith(new _RepeatingSimulation(this._value, min.Value, max.Value, reverse, period.Value));
256286
}
257287

258288
public TickerFuture fling(float velocity = 1.0f) {
@@ -395,21 +425,32 @@ public override bool isDone(float timeInSeconds) {
395425
}
396426

397427
class _RepeatingSimulation : Simulation {
398-
internal _RepeatingSimulation(float min, float max, TimeSpan period) {
428+
internal _RepeatingSimulation(float initialValue, float min, float max, bool reverse, TimeSpan period) {
399429
this._min = min;
400430
this._max = max;
401431
this._periodInSeconds = (float) period.Ticks / TimeSpan.TicksPerSecond;
432+
this._initialT = (max == min) ? 0.0f : (initialValue / (max - min)) * (period.Ticks / TimeSpan.TicksPerSecond);
402433
D.assert(this._periodInSeconds > 0.0f);
434+
D.assert(this._initialT >= 0.0f);
403435
}
404436

405437
readonly float _min;
406438
readonly float _max;
407439
readonly float _periodInSeconds;
440+
readonly bool _reverse;
441+
readonly float _initialT;
408442

409443
public override float x(float timeInSeconds) {
410444
D.assert(timeInSeconds >= 0.0f);
411-
float t = (timeInSeconds / this._periodInSeconds) % 1.0f;
412-
return MathUtils.lerpFloat(this._min, this._max, t);
445+
float totalTimeInSeconds = timeInSeconds + this._initialT;
446+
float t = (totalTimeInSeconds / this._periodInSeconds) % 1.0f;
447+
bool _isPlayingReverse = ((int)(totalTimeInSeconds / this._periodInSeconds)) % 2 == 1;
448+
449+
if (this._reverse && _isPlayingReverse) {
450+
return MathUtils.lerpFloat(this._max, this._min, t);
451+
} else {
452+
return MathUtils.lerpFloat(this._min, this._max, t);
453+
}
413454
}
414455

415456
public override float dx(float timeInSeconds) {

0 commit comments

Comments
 (0)