コード例 #1
0
 private void Start()
 {
     // Invokes the OnInitialize on the Tween driver. If returned false, the
     // Tween is not ready to play or is incompatible. Then we'll decommission.
     if (this.OnInitialize() == false)
     {
         this.Decommission();
     }
     // 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.
     else if (this.hasDelay == false || this.goToFirstFrameImmediately == true)
     {
         if (this.didOverwriteFrom == false)
         {
             this.valueFrom = this.OnGetFrom();
         }
         this.OnUpdate(Easer.Apply(this.ease, 0));
     }
 }
コード例 #2
0
 private static float BounceInOut(float time)
 {
     return(time < 0.5f ? (1 - Easer.BounceOut(1 - 2 * time)) / 2 : (1 + Easer.BounceOut(2 * time - 1)) / 2);
 }
コード例 #3
0
 private static float BounceIn(float time)
 {
     return(1 - Easer.BounceOut(1 - time));
 }
コード例 #4
0
        public static float Apply(EaseType ease, float time)
        {
            switch (ease)
            {
            default:
                return(0);

            case EaseType.Linear:
                return(Easer.Linear(time));

            case EaseType.SineIn:
                return(Easer.SineIn(time));

            case EaseType.SineOut:
                return(Easer.SineOut(time));

            case EaseType.SineInOut:
                return(Easer.SineInOut(time));

            case EaseType.QuadIn:
                return(Easer.QuadIn(time));

            case EaseType.QuadOut:
                return(Easer.QuadOut(time));

            case EaseType.QuadInOut:
                return(Easer.QuadInOut(time));

            case EaseType.CubicIn:
                return(Easer.CubicIn(time));

            case EaseType.CubicOut:
                return(Easer.CubicOut(time));

            case EaseType.CubicInOut:
                return(Easer.CubicInOut(time));

            case EaseType.QuartIn:
                return(Easer.QuartIn(time));

            case EaseType.QuartOut:
                return(Easer.QuartOut(time));

            case EaseType.QuartInOut:
                return(Easer.QuartInOut(time));

            case EaseType.QuintIn:
                return(Easer.QuintIn(time));

            case EaseType.QuintOut:
                return(Easer.QuintOut(time));

            case EaseType.QuintInOut:
                return(Easer.QuintInOut(time));

            case EaseType.ExpoIn:
                return(Easer.ExpoIn(time));

            case EaseType.ExpoOut:
                return(Easer.ExpoOut(time));

            case EaseType.ExpoInOut:
                return(Easer.ExpoInOut(time));

            case EaseType.CircIn:
                return(Easer.CircIn(time));

            case EaseType.CircOut:
                return(Easer.CircOut(time));

            case EaseType.CircInOut:
                return(Easer.CircInOut(time));

            case EaseType.BackIn:
                return(Easer.BackIn(time));

            case EaseType.BackOut:
                return(Easer.BackOut(time));

            case EaseType.BackInOut:
                return(Easer.BackInOut(time));

            case EaseType.ElasticIn:
                return(Easer.ElasticIn(time));

            case EaseType.ElasticOut:
                return(Easer.ElasticOut(time));

            case EaseType.ElasticInOut:
                return(Easer.ElasticInOut(time));

            case EaseType.BounceIn:
                return(Easer.BounceIn(time));

            case EaseType.BounceOut:
                return(Easer.BounceOut(time));

            case EaseType.BounceInOut:
                return(Easer.BounceInOut(time));
            }
        }
コード例 #5
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 -= 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 = 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();
             }
         }
     }
 }