Esempio n. 1
0
    private static IEnumerator UncoverScreen(float destX, float destY)
    {
        if (lastScreen == null || isAnimating)
        {
            yield return(null);
        }
        isAnimating = true;

        lastScreen.willHide();
        currentScreen.willShow();

        if (backdrop != null)
        {
            lastScreen.AddChild(backdrop);
            backdrop.MoveToBack();
        }

        Futile.stage.AddChild(currentScreen);
        lastScreen.MoveToFront();

        switch (defaultAnimationType)
        {
        case AnimationType.Linear:
            while (lastScreen.x != destX || lastScreen.y != destY)
            {
                if (lastScreen.x > destX)
                {
                    lastScreen.x -= Mathf.Min(lastScreen.x - destX, PUSH_SPEED_X);
                }
                else if (currentScreen.x < destX)
                {
                    lastScreen.x -= Mathf.Max(lastScreen.x - destX, -1f * PUSH_SPEED_X);
                }

                if (currentScreen.y > destY)
                {
                    lastScreen.y -= Mathf.Min(lastScreen.y - destY, PUSH_SPEED_Y);
                }
                else if (currentScreen.y < destY)
                {
                    lastScreen.y -= Mathf.Max(lastScreen.y - destY, -1f * PUSH_SPEED_Y);
                }

                yield return(new WaitForEndOfFrame());
            }
            break;

        case AnimationType.Interpolated:
            while (lastScreen.x != destX || lastScreen.y != destY)
            {
                if (lastScreen.x == 0 && destX != 0)
                {
                    lastScreen.x += (destX < 0 ? -1f : 1f) * PUSH_SPEED_X;
                }
                else if (Mathf.Abs(lastScreen.x) < Mathf.Abs(destX))
                {
                    lastScreen.x += (destX - lastScreen.x) / INTERPOLATION;
                }

                if (lastScreen.y == 0 && destY != 0)
                {
                    lastScreen.y += (destY < 0 ? -1f : 1f) * PUSH_SPEED_Y;
                }
                else if (Mathf.Abs(lastScreen.y) < Mathf.Abs(destY))
                {
                    lastScreen.y += (destY - lastScreen.y) / INTERPOLATION;
                }

                if (Mathf.Abs(lastScreen.x - destX) < CLOSE_ENOUGH)
                {
                    lastScreen.x = destX;
                }
                if (Mathf.Abs(lastScreen.y - destY) < CLOSE_ENOUGH)
                {
                    lastScreen.y = destY;
                }

                yield return(new WaitForEndOfFrame());
            }
            break;

        default:
            throw new FutileException("Invalid animation type set in ScreenManager!");
        }

        lastScreen.RemoveFromContainer();
        lastScreen.didHide();

        currentScreen.didShow();

        isAnimating = false;
    }
Esempio n. 2
0
    private static IEnumerator AnimateScreens(bool cover = false)
    {
        if (isAnimating)
        {
            yield return(null);
        }
        isAnimating = true;

        if (lastScreen != null)
        {
            lastScreen.willHide();
        }
        currentScreen.willShow();

        if (cover && backdrop != null)
        {
            currentScreen.AddChild(backdrop);
            backdrop.MoveToBack();
        }

        Futile.stage.AddChild(currentScreen);

        //ideally would put these in sub-functions, but not sure how that plays with the C# yields
        //would also prefer to rewrite this to not assume(0,0) as the target, but zoom to any target
        if (defaultAnimationType == AnimationType.Linear)
        {
            while (currentScreen.x != 0f || currentScreen.y != 0f)
            {
                if (currentScreen.x > 0f)
                {
                    if (lastScreen != null && !cover)
                    {
                        lastScreen.x -= Mathf.Min(currentScreen.x, PUSH_SPEED_X);
                    }
                    currentScreen.x -= Mathf.Min(currentScreen.x, PUSH_SPEED_X);
                }
                else if (currentScreen.x < 0f)
                {
                    if (lastScreen != null && !cover)
                    {
                        lastScreen.x -= Mathf.Max(currentScreen.x, -1f * PUSH_SPEED_X);
                    }
                    currentScreen.x -= Mathf.Max(currentScreen.x, -1f * PUSH_SPEED_X);
                }

                if (currentScreen.y > 0f)
                {
                    if (lastScreen != null && !cover)
                    {
                        lastScreen.y -= Mathf.Min(currentScreen.y, PUSH_SPEED_Y);
                    }
                    currentScreen.y -= Mathf.Min(currentScreen.y, PUSH_SPEED_Y);
                }
                else if (currentScreen.y < 0f)
                {
                    if (lastScreen != null && !cover)
                    {
                        lastScreen.y -= Mathf.Max(currentScreen.y, -1f * PUSH_SPEED_Y);
                    }
                    currentScreen.y -= Mathf.Max(currentScreen.y, -1f * PUSH_SPEED_Y);
                }

                yield return(new WaitForEndOfFrame());
            }
        }
        else if (defaultAnimationType == AnimationType.Interpolated)
        {
            while (currentScreen.x != 0.0f || currentScreen.y != 0.0f)
            {
                if (Mathf.Abs(currentScreen.x) > 0.0f)
                {
                    float dx = (0.0f - currentScreen.x) / INTERPOLATION;
                    // Debug.Log ("DX = " + dx);

                    currentScreen.x += dx;
                    if (lastScreen != null && !cover)
                    {
                        lastScreen.x += dx;
                    }

                    if (Mathf.Abs(currentScreen.x) < CLOSE_ENOUGH)
                    {
                        currentScreen.x = 0.0f;
                    }
                }

                if (Mathf.Abs(currentScreen.y) > 0.0f)
                {
                    float dy = (0.0f - currentScreen.y) / INTERPOLATION;
                    currentScreen.y += dy;
                    if (lastScreen != null && !cover)
                    {
                        lastScreen.y += dy;
                    }

                    if (Mathf.Abs(currentScreen.y) < CLOSE_ENOUGH)
                    {
                        currentScreen.y = 0.0f;
                    }
                }

                yield return(new WaitForEndOfFrame());
            }
        }
        else
        {
            throw new FutileException("Invalid animation type set in ScreenManager!");
        }

        if (lastScreen != null)
        {
            lastScreen.RemoveFromContainer();
            lastScreen.didHide();
        }
        if (backdrop != null)
        {
            currentScreen.RemoveChild(backdrop);
        }
        currentScreen.didShow();

        isAnimating = false;
    }