Exemple #1
0
 private void Start()
 {
     // When From is not overwritten and the Tween has no delay, the valueFrom
     // is requested from the inheriter. Then the animation will be set to its
     // first frame. This is done during the Start method so other parameters
     // can be set.
     if (this.OnInitialize() == false)
     {
         this.Decommission();
     }
     else if (this.hasDelay == false || this.goToFirstFrameImmediately == true)
     {
         if (this.didOverwriteFrom == false)
         {
             this.valueFrom = this.OnGetFrom();
         }
         this.OnUpdate(Easer.Apply(this.ease, 0));
     }
 }
Exemple #2
0
 private void Update()
 {
     // When the tween is decommissioned, tweening is aborted.
     if (this.isDecommissioned == true)
     {
         return;
     }
     // When the tween is paused, we'll just wait.
     if (this.isPaused == true)
     {
         return;
     }
     // When the delay is active, the tween will wait for the delay to pass by.
     if (this.hasDelay == true)
     {
         this.delay -= this.useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime;
         if (this.delay <= 0)
         {
             this.hasDelay = false;
             // When the delay is over, the valueFrom is requested from the
             // inheriter. Then the animation will be set to its first frame.
             if (this.didOverwriteFrom == false)
             {
                 this.valueFrom = this.OnGetFrom();
             }
             this.OnUpdate(Easer.Apply(this.ease, 0));
         }
     }
     // When the tween has no duration, the timing will not be done and the
     // animation will be set to its last frame amd decomissioned right away.
     else if (this.hasDuration == false)
     {
         this.OnUpdate(Easer.Apply(this.ease, 1));
         this.Decommission();
         return;
     }
     // Oterwise it is... Showtime!
     else
     {
         // Increase or decrease the time of the tween based on the direction.
         var _timeDelta = (this.useUnscaledTime ? Time.unscaledDeltaTime : Time.deltaTime) / this.duration;
         this.time += this.isPlayingForward == true ? _timeDelta : -_timeDelta;
         // The time will be capped to 1, when pingpong is enabled the tween will
         // play backwards, otherwise when the tween is not infinite, didReachEnd
         // will be set to true.
         if (this.time > 1)
         {
             this.time = 1;
             if (this.hasPingPong == true)
             {
                 this.isPlayingForward = false;
             }
             else if (this.isInfinite == false)
             {
                 this.timeDidReachEnd = true;
             }
             else
             {
                 this.time = 0;
             }
         }
         // When pingpong is enabled, the time will be capped to 0 as well. When
         // it is hit, the tween will play forwards again and didReachEnd will be
         // set to true if the tween is not infinite.
         else if (this.hasPingPong == true && this.time < 0)
         {
             this.time             = 0;
             this.isPlayingForward = true;
             if (this.isInfinite == false)
             {
                 this.timeDidReachEnd = true;
             }
         }
         // The time will be updated on the inheriter.
         this.OnUpdate(Easer.Apply(this.ease, this.time));
         // When the end is reached either the loop count will be decreased, or
         // the tween will be decommissioned, and the oncomplete may be invoked.
         if (this.timeDidReachEnd == true)
         {
             if (this.hasLoopCount == true && this.loopCount > 1)
             {
                 this.timeDidReachEnd = false;
                 this.loopCount      -= 1;
                 this.time            = 0;
             }
             else
             {
                 if (this.hasOnComplete == true)
                 {
                     this.onComplete();
                 }
                 this.Decommission();
             }
         }
     }
 }