protected IEnumerator SmoothMove(Vector2 startPosition, Vector2 endPosition, movingFunc func)
 {
     for (float f = 1; f > 0; f -= 0.03125f)
     {
         GetComponent <RectTransform>().anchoredPosition = Vector2.Lerp(endPosition, startPosition, func(f));
         yield return(new WaitForSecondsRealtime(0.03125f));
     }
     GetComponent <RectTransform>().anchoredPosition = endPosition;
 }
Esempio n. 2
0
 private IEnumerator SmoothMove(Vector2 startPosition, Vector2 endPosition, movingFunc func)
 {
     if (timeScaleIndependent)
     {
         if (inversedInterpolation)
         {
             for (float f = translationDuration; f > 0; f -= 0.03125f) // 32 calls per second
             {
                 GetComponent <RectTransform>().anchoredPosition = Vector2.Lerp(endPosition, startPosition, func(f * translationDurationInversed));
                 yield return(new WaitForSecondsRealtime(0.03125f));
             }
         }
         else
         {
             for (float f = 0; f < translationDuration; f += 0.03125f)
             {
                 GetComponent <RectTransform>().anchoredPosition = Vector2.Lerp(startPosition, endPosition, func(f * translationDurationInversed));
                 yield return(new WaitForSecondsRealtime(0.03125f));
             }
         }
     }
     else
     {
         if (inversedInterpolation)
         {
             for (float f = translationDuration; f > 0; f -= Time.deltaTime)
             {
                 GetComponent <RectTransform>().anchoredPosition = Vector2.Lerp(endPosition, startPosition, func(f * translationDurationInversed));
                 yield return(null);
             }
         }
         else
         {
             for (float f = 0; f < translationDuration; f += Time.deltaTime)
             {
                 GetComponent <RectTransform>().anchoredPosition = Vector2.Lerp(startPosition, endPosition, func(f * translationDurationInversed));
                 yield return(null);
             }
         }
     }
     GetComponent <RectTransform>().anchoredPosition = endPosition;
 }
    //---------------------------------
    protected virtual void Awake()
    {
        if (moveAtStart)
        {
            GetComponent <RectTransform>().anchoredPosition = startPosition;
        }
        defaultPosition = GetComponent <RectTransform>().anchoredPosition;
        switch (line)
        {
        case lines.Top:
        {
            bias = new Vector2(0, stepSize);
            break;
        }

        case lines.Right:
        {
            bias = new Vector2(stepSize, 0);
            break;
        }

        case lines.Local_Center:
        {
            bias = defaultPosition.normalized * stepSize;
            break;
        }

        case lines.Bottom_Right:
        {
            bias = new Vector2(stepSize, -stepSize);
            break;
        }

        case lines.Top_Right:
        {
            bias = new Vector2(stepSize, stepSize);
            break;
        }
        }
        newPosition = defaultPosition + bias;
        switch (function)
        {
        case functions.Linear:
        {
            movingFunction = Linear;
            break;
        }

        case functions.Square:
        {
            movingFunction = Square;
            break;
        }

        case functions.Cubic:
        {
            movingFunction = Cubic;
            break;
        }
        }
        activeMovement = SmoothMove(newPosition, defaultPosition, movingFunction);
    }
Esempio n. 4
0
    //---------------------------------
    private void Awake()
    {
        if (moveAtStart)
        {
            GetComponent <RectTransform>().anchoredPosition = startPosition;
        }
        if (fillEntireScreen)
        {
            GetComponent <RectTransform>().sizeDelta = new Vector2(Screen.width, Screen.height);
        }
        translationDurationInversed = 1f / translationDuration;
        defaultPosition             = GetComponent <RectTransform>().anchoredPosition;
        switch (line)
        {
        case lines.Top:
        {
            bias = new Vector2(0, stepSize);
            break;
        }

        case lines.Right:
        {
            bias = new Vector2(stepSize, 0);
            break;
        }

        case lines.Local_Center:
        {
            bias = defaultPosition.normalized * stepSize;
            break;
        }

        case lines.Bottom_Right:
        {
            bias = new Vector2(stepSize, -stepSize);
            break;
        }

        case lines.Top_Right:
        {
            bias = new Vector2(stepSize, stepSize);
            break;
        }
        }
        newPosition = defaultPosition + bias;
        switch (function)
        {
        case functions.Linear:
        {
            movingFunction = SimpleFunctions.Linear;
            break;
        }

        case functions.Square:
        {
            movingFunction = SimpleFunctions.Square;
            break;
        }

        case functions.Cubic:
        {
            movingFunction = SimpleFunctions.Cubic;
            break;
        }

        case functions.SmoothStep:
        {
            movingFunction = SimpleFunctions.SmoothStep;
            break;
        }

        case functions.SquareRoot:
        {
            movingFunction = SimpleFunctions.SquareRoot;
            break;
        }

        case functions.SquareNegativePlusOneXY:
        {
            movingFunction = SimpleFunctions.SquareNegativePlusOneXY;
            break;
        }
        }
        activeMovement = SmoothMove(newPosition, defaultPosition, movingFunction);
    }