Exemplo n.º 1
0
        /// <summary>
        /// Create a new scale animation.
        /// </summary>
        /// <param name="transformAnimator">The TransformAnimator of the transform to animate</param>
        /// <param name="startScale">The start scale</param>
        /// <param name="endScale">The end scale</param>
        /// <param name="speed">The speed of the animation. When the scale has a difference of 1 unit with the speed of 1 it takes 1 second to animate </param>
        /// <param name="easeFunction">The ease functions to use for the interpolation</param>
        /// <returns>it self</returns>
        public static TransformAnimatorSpeedSequence CreateScaleAnimation(TransformAnimator transformAnimator,
                                                                          Vector3 startScale, Vector3 endScale, float speed, Func <float, float> easeFunction = null)
        {
            easeFunction = WhenNullUseDefault(easeFunction);
            var dist = Vector3.Distance(startScale, endScale);

            return(new TransformAnimatorSpeedSequence(speed, dist,
                                                      t => transformAnimator.Transform.localScale = Vector3.Lerp(startScale, endScale, easeFunction(t))));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new rotation animation.
        /// </summary>
        /// <param name="transformAnimator">The TransformAnimator of the transform to animate</param>
        /// <param name="startRotation">The start rotation</param>
        /// <param name="endRotation">The end rotation</param>
        /// <param name="speed">The speed of the animation. When the rotation distance is 1 Euler angle and the speed is 1 second the animation will take 1 second.</param>
        /// <param name="easeFunction">The ease functions to use for the interpolation</param>
        /// <returns>it self</returns>
        public static TransformAnimatorSpeedSequence CreateRotationAnimation(TransformAnimator transformAnimator,
                                                                             Quaternion startRotation, Quaternion endRotation, float speed, Func <float, float> easeFunction = null)
        {
            easeFunction = WhenNullUseDefault(easeFunction);
            var dist = Quaternion.Angle(startRotation, endRotation);

            return(new TransformAnimatorSpeedSequence(speed, dist,
                                                      t => transformAnimator.Transform.rotation =
                                                          Quaternion.Lerp(startRotation, endRotation, easeFunction(t))));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a custom animation.
 /// <remarks>
 /// The t value of the animation is calculated as follow: <code>travelTime * speed / travelDistance</code>
 /// </remarks>
 /// </summary>
 /// <param name="transformAnimator">The TransformAnimator of the transform to animate</param>
 /// <param name="animation">The action to call every step. The step will get the t [0,1] value as a parameter.</param>
 /// <param name="speed">The speed of the animation.</param>
 /// <param name="distance">The distance the animation needs to travel.</param>
 /// <param name="easeFunction">The ease functions to use for the interpolation</param>
 /// <returns>it self</returns>
 public static TransformAnimatorSpeedSequence CreateCustomAnimation(TransformAnimator transformAnimator,
                                                                    Action <float> animation, float speed, float distance, Func <float, float> easeFunction = null)
 {
     easeFunction = WhenNullUseDefault(easeFunction);
     return(new TransformAnimatorSpeedSequence(speed, distance, t => animation?.Invoke(easeFunction(t))));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="transformAnimator">The transform animator for the transform</param>
 /// <param name="duration">Duration of the animations</param>
 public TransformAnimatorDurationSequence(TransformAnimator transformAnimator, float duration) : base(duration)
 {
     _transformAnimator = transformAnimator;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Create a transform animation
 /// </summary>
 /// <param name="transform">The transform to animate</param>
 /// <returns>A transform animation</returns>
 public static TransformAnimator Animate(this Transform transform)
 {
     return(TransformAnimator.Create(transform));
 }