Exemplo n.º 1
0
 /// <summary>
 /// Interpolates between 2 points 2D
 /// </summary>
 /// <param name="to"> Destination point</param>
 /// <param name="target"> Target to be interpolated</param>
 /// <param name="speed"> /speed is the time it takes to travel</param>
 public static IEnumerator InterpolatePointE(Transform target, Vector2 to, float time, Easings.Functions interpolationFunction = Easings.Functions.Linear)
 {
     Easings.Function interpolator = Easings.GetInterpolator(interpolationFunction);
     float fraction = 0;
     float speed = 1 / time;
     bool isUnscaledTime = GeneralHelper.IsPaused();
     Vector2 from = target.position;
     float easedValue;
     while (fraction < 1)
     {
         fraction.To1(speed, isUnscaledTime, interpolator, out easedValue);
         target.transform.position = Vector2.Lerp(from, to, easedValue);
         yield return null;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Moves from one size to another dynamically
 /// </summary>
 /// <param name="transform"> Transform obj to be scaled</param>
 /// <param name="scaleTo"> Scale to</param>
 /// <param name="time"> Time it takes to scale</param>
 /// <param name="interpolationFunction"> Scaling interpolator</param>
 /// <param name="isUnscaledTime"> Is not paused</param>
 /// <returns></returns>
 public static IEnumerator InterpolateScaleE(Transform transform, Vector3 scaleTo, float time = 1, Easings.Functions interpolationFunction = Easings.Functions.Linear)
 {
     Vector3 currntScale = transform.localScale;
     Easings.Function interpolator = Easings.GetInterpolator(interpolationFunction);
     float fraction = 0;
     float speed = 1 / time;
     bool isUnscaledTime = GeneralHelper.IsPaused();
     float easedValue;
     while (fraction < 1)
     {
         fraction.To1(speed, isUnscaledTime, interpolator, out easedValue);
         Vector3 newScale = Vector3.Lerp(currntScale, scaleTo, easedValue);
         transform.localScale = newScale;
         yield return null;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Moves from one size to another dynamically
 /// </summary>
 /// <param name="transform"> Transform obj to be scaled</param>
 /// <param name="scaleTo"> Scale to</param>
 /// <param name="time"> Time it takes to scale</param>
 /// <param name="interpolationFunction"> Scaling interpolator</param>
 /// <param name="isUnscaledTime"> Is not paused</param>
 /// <returns></returns>
 public static IEnumerator InterpolateRectPositionE(RectTransform rectTransform, Vector3 pointTo, float time = 1, Easings.Functions interpolationFunction = Easings.Functions.Linear)
 {
     //rectTransform.position = new Vector3(0, 0, 0);
     Vector3 currentPosition = rectTransform.localPosition;
     Easings.Function interpolator = Easings.GetInterpolator(interpolationFunction);
     float fraction = 0;
     float speed = 1 / time;
     bool isUnscaledTime = GeneralHelper.IsPaused();
     float easedValue;
     while (fraction < 1)
     {
         fraction = fraction.To1(speed, isUnscaledTime, interpolator, out easedValue);
         Vector3 newPosition = Vector3.Lerp(currentPosition, pointTo, easedValue);
         rectTransform.localPosition = newPosition;
         yield return null;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Moves from one size to another dynamically
 /// </summary>
 /// <param name="transform"> Transform obj to be scaled</param>
 /// <param name="scaleTo"> Scale to</param>
 /// <param name="time"> Time it takes to scale</param>
 /// <param name="interpolationFunction"> Scaling interpolator</param>
 /// <param name="isUnscaledTime"> Is not paused</param>
 /// <returns></returns>
 public static IEnumerator InterpolateScaleE(RectTransform rectTransform, Vector2 scaleTo, float time = 1, Easings.Functions interpolationFunction = Easings.Functions.Linear)
 {
     //rectTransform.position = new Vector3(0, 0, 0);
     Vector2 currntScale = rectTransform.sizeDelta;
     Easings.Function interpolator = Easings.GetInterpolator(interpolationFunction);
     float fraction = 0;
     float speed = 1 / time;
     bool isUnscaledTime = GeneralHelper.IsPaused();
     float easedValue;
     while (fraction < 1)
     {
         fraction = fraction.To1(speed, isUnscaledTime, interpolator, out easedValue);
         Vector2 newScale = Vector2.Lerp(currntScale, scaleTo, easedValue);
         rectTransform.sizeDelta = newScale;
         yield return null;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Interpolates Text color from one to another
 /// </summary>
 /// <param name="target">Target image</param>
 /// <param name="colorTo"> Color to interpolate to</param>
 /// <param name="time"> Interpolation time</param>
 /// <param name="interpolationFunction"> Interpolating function</param>
 /// <returns></returns>
 public static IEnumerator InterpolateColorE(Text target, Color colorTo, float time, Easings.Functions interpolationFunction = Easings.Functions.SineEaseIn, float delay = 0)
 {
     Color colorFrom = target.color;
     Color newColor;
     Easings.Function interpolator = Easings.GetInterpolator(interpolationFunction);
     float fraction = 0;
     float speed = 1 / time;
     float easedValue;
     bool isUnscaledTime = GeneralHelper.IsPaused();
     while (fraction < 1)
     {
         fraction.To1(speed, isUnscaledTime, interpolator, out easedValue);
         newColor = Color.Lerp(colorFrom, colorTo, easedValue);
         target.color = newColor;
         yield return null;
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Curved interpolation of a point in 2D
 /// </summary>
 /// <param name="transform"></param>
 /// <param name="locationTo"></param>
 /// <param name="time"></param>
 /// <param name="interpolationType"></param>
 /// <param name="rotationNormalised"></param>
 /// <param name="offsetZ"></param>
 /// <param name="isUnscaledTime"></param>
 /// <returns></returns>
 public static IEnumerator FancyInterpolation(Transform target, Vector3 locationTo, float time, Easings.Functions interpolationType = Easings.Functions.QuarticEaseInOut,
     bool rotationNormalised = true, float offsetZ = 0, bool isUnscaledTime = false)
 {
     const int functionsCount = 21; // based on Easings.Functions
     Easings.Functions typeOfInterpolationX = (Easings.Functions)UnityEngine.Random.Range(0, functionsCount);
     Easings.Functions typeOfInterpolationY = (Easings.Functions)UnityEngine.Random.Range(0, functionsCount);
     Easings.Function interpolatorX = Easings.GetInterpolator(typeOfInterpolationX);
     Easings.Function interpolatorY = Easings.GetInterpolator(typeOfInterpolationY);
     Easings.Function interpolatorFraction = Easings.GetInterpolator(interpolationType);
     float fraction = 0;
     float speed = 1 / time;
     Vector3 currentPosition = target.position + Vector3.forward * offsetZ;
     Quaternion currentRotation = target.rotation;
     Quaternion rotationTo = Quaternion.Euler(Vector3.zero);
     float totalDisanceX = locationTo.x - currentPosition.x;
     float totalDisanceY = locationTo.y - currentPosition.y;
     if (rotationNormalised)
     {
         while (fraction < 1)
         {
             float resultX;
             Vector3 offsetToMoveBy = FancyInterpolationSplitResult(totalDisanceX, totalDisanceY, fraction, speed, isUnscaledTime,
             interpolatorFraction, interpolatorX, interpolatorY, out resultX);
             target.position = currentPosition + offsetToMoveBy;
             Quaternion newRotation = Quaternion.Lerp(currentRotation, rotationTo, resultX);
             target.rotation = newRotation;
             yield return null;
         }
     }
     else
     {
         while (fraction < 1)
         {
             float resultX; // not used
             Vector3 offsetToMoveBy = FancyInterpolationSplitResult(totalDisanceX, totalDisanceY, fraction, speed, isUnscaledTime,
             interpolatorFraction, interpolatorX, interpolatorY, out resultX);
             target.position = currentPosition + offsetToMoveBy;
             yield return null;
         }
     }
 }