15 public partial struct Tween {
17 private TweenInstance _instance;
19 private Tween(
bool isSingle) {
20 _instance = Pool<TweenInstance>.Spawn();
21 _id = _instance.instanceId;
22 _instance.returnToPoolUponStop = isSingle;
29 return new Tween(isSingle:
true);
37 return new Tween(isSingle:
false);
47 #region PUBLIC PROPERTIES
56 return _instance !=
null && _id == _instance.instanceId;
66 return _instance.runnerIndex != -1;
76 return _instance.direction;
80 _instance.direction = value;
81 _instance.dstPercent = value ==
Direction.Backward ? 0 : 1;
91 return Mathf.Abs((_instance.curPercent - _instance.dstPercent) / _instance.velPercent);
102 return _instance.curPercent;
107 if (_instance.curPercent == value) {
111 if (value < 0 || value > 1) {
112 throw new ArgumentException(
"Progress must be a value from 0 - 1");
115 if (_instance.curPercent == 0.0f) {
116 if (_instance.OnLeaveStart !=
null) {
117 _instance.OnLeaveStart();
119 }
else if (_instance.curPercent == 1.0f) {
120 if (_instance.OnLeaveEnd !=
null) {
121 _instance.OnLeaveEnd();
125 _instance.curPercent = value;
127 if (_instance.curPercent == 0.0f) {
128 if (_instance.OnReachStart !=
null) {
129 _instance.OnReachStart();
131 }
else if (_instance.curPercent == 1.0f) {
132 if (_instance.OnReachEnd !=
null) {
133 _instance.OnReachEnd();
137 if (_instance.runnerIndex == -1) {
138 _instance.interpolatePercent();
144 #region PUBLIC METHODS
154 if (_instance.interpolatorCount >= _instance.interpolators.Length) {
155 Utils.DoubleCapacity(ref _instance.interpolators);
158 _instance.interpolators[_instance.interpolatorCount++] = interpolator;
167 _instance.velPercent = 1.0f / seconds;
177 _instance.velPercent = unitsPerSecond / _instance.interpolators[0].length;
186 _instance.smoothType = type;
187 _instance.smoothFunction =
null;
196 _instance.smoothType = 0;
197 _instance.smoothFunction = curve.Evaluate;
207 _instance.smoothType = 0;
208 _instance.smoothFunction = smoothFunction;
224 _instance.OnProgress += action;
234 _instance.OnLeaveStart += action;
244 _instance.OnReachStart += action;
254 _instance.OnLeaveEnd += action;
264 _instance.OnReachEnd += action;
275 if (_instance.curPercent == _instance.dstPercent) {
309 if (destinationPercent < 0 || destinationPercent > 1) {
310 throw new ArgumentException(
"Destination percent must be within the range [0-1]");
314 _instance.dstPercent = destinationPercent;
328 return _instance.yieldInstruction;
337 if (_instance.runnerIndex != -1) {
353 if (
isValid && _instance.returnToPoolUponStop) {
372 private void throwIfInvalid() {
377 throw new InvalidOperationException(
"Tween is invalid. Make sure you use Tween.Single or Tween.Persistant to create your Tween instead of the default constructor.");
379 throw new InvalidOperationException(
"Tween is invalid or was recycled. Make sure to use Tween.Persistant if you want to keep a tween around after it finishes playing.");
using Leap.Unity.Interaction. Internal
static TweenRunner instance
void ScheduleForRecycle(TweenInstance instance)
void RemoveTween(TweenInstance instance)
void AddTween(TweenInstance instance)
Implement this interface to add your own interpolators to Tween!
Tween Play()
Starts playing this Tween. It will continue from the same position it left off on,...
void Pause()
Pauses this Tween. It retains its position and direction.
Direction direction
Gets or sets whether or not this Tween is moving forwards or backwards.
bool isRunning
Returns whether or not the Tween is currently running.
Tween Play(Direction direction)
Starts playing this Tween in a specific direction. It will condition from the same position it left o...
Tween OverTime(float seconds)
Specifies that this Tween should travel from begining to end over a certain number of seconds.
Tween Smooth(Func< float, float > smoothFunction)
Specifies that this Tween should use the given Function for its smoothing. The function should map fr...
float timeLeft
Gets how much time is left before the Tween stops.
Tween OnProgress(Action< float > action)
Specifies an action to be called every step of the Tween. This callback happens after:
Tween AddInterpolator(IInterpolator interpolator)
Adds a new Interpolator to this Tween. This Interpolator will have it's Interpolate method called eve...
static Tween Persistent()
Creates a persistant Tween that will not ever auto-release itself. You must specifically call Release...
Tween OnReachEnd(Action action)
Specifies an action to be called whenever this Tween reaches the end.
Tween OnLeaveStart(Action action)
Specifies an action to be called whenever this Tween is Played forward when at the start.
static Tween Single()
Create a single-use Tween that will auto-release itself as soon as it is finished playing.
static Tween AfterDelay(float delay, Action onReachEnd)
Create a single-use Tween that will fire onReachEnd after the specified delay in seconds.
Tween Smooth(SmoothType type=SmoothType.Smooth)
Specifies that this Tween should the given smoothing method.
Tween Value(float a, float b, Action< float > onValue)
Tween Play(float destinationPercent)
Starts playing this Tween towards a destination percent. Once it reaches that value,...
Tween AtRate(float unitsPerSecond)
Specifies that this Tween should travel at the given rate. This rate is measured against the FIRST in...
bool isValid
Returns whether or not this Tween is considered valid. A Tween can become invalid under the following...
void Release()
Forces this Tween to be recycled right away. Once this method is called, the Tween will be invalid an...
Tween OnLeaveEnd(Action action)
Specifies an action to be called whenever this Tween is Played backwards when at the end.
void Stop()
Stops this Tween. If it is not a persistant Tween, it will be recycled right away.
float progress
Gets or sets how far along completion this Tween is. This value is a percent that ranges from 0 to 1.
Tween Smooth(AnimationCurve curve)
Specifies that this Tween should use the given Animation curve for its smoothing. The curve should ma...
TweenInstance.TweenYieldInstruction Yield()
Returns a custom yield instruction that can be yielded to in order to wait for the completion of this...
Tween OnReachStart(Action action)
Specifies an action to be called whenever this Tween reaches the start.