Пример #1
0
    void AnimateElement(UIPanElement element)
    {
        // If it's not meant to be moving, just quit here
        if (element.state == UIPanState.None)
        {
            return;
        }

        // Calculate how far into the curve we are
        element.progress = Mathf.Clamp(element.progress + (Time.unscaledDeltaTime / element.duration), 0, 1);

        // Set the position and fade
        switch (element.state)
        {
        case UIPanState.MovingOnscreen:
            element.transform.anchoredPosition =
                new Vector3(element.movementCurveXOnscreen.Evaluate(element.progress) * screenSize.x, element.movementCurveYOnscreen.Evaluate(element.progress) * screenSize.y);
            fade.alpha = element.fadeCurve.Evaluate(element.progress);
            break;

        case UIPanState.MovingOffscreen:
            element.transform.anchoredPosition =
                new Vector3(element.movementCurveXOffscreen.Evaluate(element.progress) * screenSize.x, element.movementCurveYOffscreen.Evaluate(element.progress) * screenSize.y);
            fade.alpha = element.fadeCurve.Evaluate(1 - element.progress);
            break;
        }

        // Stop if at completion
        if (element.progress == 1)
        {
            element.progress = 0;
            element.state    = UIPanState.None;
        }
    }
Пример #2
0
    void UpdateOrientation(ScreenOrientation screenOrientation)
    {
        switch (screenOrientation)
        {
        case ScreenOrientation.Portrait:
            // Set new orientation
            // Toggle active UI
            portraitUI.SetActive(true);
            landscapeUI.SetActive(false);
            activeOptions = optionsPortrait;
            activeCredits = creditsPortrait;
            // Sync animation progress/state, position will be synced immediately after this
            optionsPortrait.state    = optionsLandscape.state;
            creditsPortrait.state    = creditsLandscape.state;
            optionsPortrait.progress = optionsLandscape.progress;
            creditsPortrait.progress = creditsLandscape.progress;
            break;

        case ScreenOrientation.LandscapeLeft:
        case ScreenOrientation.LandscapeRight:
            // Set new orientation
            // Toggle active UI
            landscapeUI.SetActive(true);
            portraitUI.SetActive(false);
            activeOptions = optionsLandscape;
            activeCredits = creditsLandscape;
            // Sync animation progress/state, position will be synced immediately after this
            optionsLandscape.state    = optionsPortrait.state;
            creditsLandscape.state    = creditsPortrait.state;
            optionsLandscape.progress = optionsPortrait.progress;
            creditsLandscape.progress = creditsPortrait.progress;
            break;

        default:
            goto case ScreenOrientation.LandscapeRight;
        }
        // Force the menus into the correct locations
        UIPanElement submenu = new UIPanElement();

        if (submenu == null)
        {
            return;
        }

        if (activeCredits != submenu)
        {
            activeCredits.transform.anchoredPosition = new Vector3(activeCredits.movementCurveXOffscreen.Evaluate(1) * screenSize.x, activeCredits.movementCurveYOffscreen.Evaluate(1) * screenSize.y);
        }
        if (activeOptions != submenu)
        {
            activeOptions.transform.anchoredPosition = new Vector3(activeOptions.movementCurveXOffscreen.Evaluate(1) * screenSize.x, activeOptions.movementCurveYOffscreen.Evaluate(1) * screenSize.y);
        }
        if (submenu != null && submenu.progress == 0)
        {
            submenu.transform.anchoredPosition = submenu.cachedLocation;
        }
    }