Example #1
0
    void SetState(eGameOverPanelState newState)
    {
        stateStartTime = realTime;

        switch (newState)
        {
        case eGameOverPanelState.idle:
            gameObject.SetActive(false);
            if (idleCallback != null)
            {
                idleCallback();
                idleCallback = null;
            }
            break;

        case eGameOverPanelState.fadeIn:
            gameObject.SetActive(true);
            levelRT.localScale = new Vector3(1, 0, 1);
            infoText.text      = "Final Level: " //+ AsteraX.GAME_LEVEL
                                 + "\nFinal Score: " + AsteraX.SCORE.ToString("N0");
            infoText.color     = Color.clear;
            img.color          = Color.clear;
            levelRT.localScale = new Vector3(1, 0, 1);
            infoText.color     = Color.clear;
            stateDuration      = fadeTime * 0.2f;
            nextState          = eGameOverPanelState.fadeIn2;
            break;

        case eGameOverPanelState.fadeIn2:
            img.color          = Color.black;
            levelRT.localScale = new Vector3(1, 0, 1);
            infoText.color     = Color.clear;
            stateDuration      = fadeTime * 0.6f;
            nextState          = eGameOverPanelState.fadeIn3;
            break;

        case eGameOverPanelState.fadeIn3:
            img.color          = Color.black;
            levelRT.localScale = new Vector3(1, 1, 1);
            infoText.color     = Color.clear;
            stateDuration      = fadeTime * 0.2f;
            nextState          = eGameOverPanelState.display;
            break;

        case eGameOverPanelState.display:
            stateDuration = 999999;
            nextState     = eGameOverPanelState.none;
            if (displayCallback != null)
            {
                displayCallback();
                displayCallback = null;
            }
            break;
        }

        state = newState;
    }
    static public void AdvanceLevel(AsteraX.CallbackDelegate displayCB, AsteraX.CallbackDelegate idleCB)
    {
        if (S == null)
        {
            Debug.LogError("LevelAdvancePanel:AdvanceLevel() - Called while S is null.");
            return;
        }

        S.displayCallback = displayCB;
        S.idleCallback    = idleCB;

        S.SetState(eLevelAdvanceState.fadeIn);
    }
    void SetState(eLevelAdvanceState newState)
    {
        stateStartTime = realTime;

        switch (newState)
        {
        case eLevelAdvanceState.idle:
            gameObject.SetActive(false);
            if (idleCallback != null)
            {
                idleCallback();
                idleCallback = null;
            }
            break;

        case eLevelAdvanceState.fadeIn:
            gameObject.SetActive(true);
            // Set text
            levelText.text     = "Level " + AsteraX.GAME_LEVEL;
            levelRT.localScale = new Vector3(1, 0, 1);
            AsteraX.LevelInfo lvlInfo = AsteraX.GetLevelInfo();
            infoText.text  = "Asteroids: " + lvlInfo.numInitialAsteroids + "\tChildren: " + lvlInfo.numSubAsteroids;
            infoText.color = Color.clear;
            // Set initial state
            img.color          = Color.clear;
            levelRT.localScale = new Vector3(1, 0, 1);
            infoText.color     = Color.clear;
            // Set timiing and advancement
            stateDuration = fadeTime * 0.2f;
            nextState     = eLevelAdvanceState.fadeIn2;
            break;

        case eLevelAdvanceState.fadeIn2:
            // Set initial state
            img.color          = Color.black;
            levelRT.localScale = new Vector3(1, 0, 1);
            infoText.color     = Color.clear;
            // Set timiing and advancement
            stateDuration = fadeTime * 0.6f;
            nextState     = eLevelAdvanceState.fadeIn3;
            break;

        case eLevelAdvanceState.fadeIn3:
            // Set initial state
            img.color          = Color.black;
            levelRT.localScale = new Vector3(1, 1, 1);
            infoText.color     = Color.clear;
            // Set timiing and advancement
            stateDuration = fadeTime * 0.2f;
            nextState     = eLevelAdvanceState.display;
            break;

        case eLevelAdvanceState.display:
            stateDuration = displayTime;
            nextState     = eLevelAdvanceState.fadeOut;
            if (displayCallback != null)
            {
                displayCallback();
                displayCallback = null;
            }
            break;

        case eLevelAdvanceState.fadeOut:
            // Set initial state
            img.color          = Color.black;
            levelRT.localScale = new Vector3(1, 1, 1);
            infoText.color     = Color.white;
            // Set timiing and advancement
            stateDuration = fadeTime * 0.2f;
            nextState     = eLevelAdvanceState.fadeOut2;
            break;

        case eLevelAdvanceState.fadeOut2:
            // Set initial state
            img.color          = Color.black;
            levelRT.localScale = new Vector3(1, 1, 1);
            infoText.color     = Color.clear;
            // Set timiing and advancement
            stateDuration = fadeTime * 0.6f;
            nextState     = eLevelAdvanceState.fadeOut3;
            break;

        case eLevelAdvanceState.fadeOut3:
            // Set initial state
            img.color          = Color.black;
            levelRT.localScale = new Vector3(1, 0, 1);
            infoText.color     = Color.clear;
            // Set timiing and advancement
            stateDuration = fadeTime * 0.2f;
            nextState     = eLevelAdvanceState.idle;
            break;
        }

        state = newState;
    }
    void SetState(eGameOverPanelState newState)
    {
        stateStartTime = realTime;

        switch (newState)
        {
        case eGameOverPanelState.idle:
            gameObject.SetActive(false);
            if (idleCallback != null)
            {
                idleCallback();
                idleCallback = null;
            }
            break;

        case eGameOverPanelState.fadeIn:
            gameObject.SetActive(true);
            // Set text
            levelRT.localScale = new Vector3(1, 0, 1);

            // This is a ternary operator
            levelText.text = AsteraX.GOT_HIGH_SCORE ? "High Score!" : "Game Over";

            infoText.text = "Final Level: " + AsteraX.GAME_LEVEL +
                            "\nFinal Score: " + AsteraX.SCORE.ToString("N0");
            infoText.color = Color.clear;
            // Set initial state
            img.color          = Color.clear;
            levelRT.localScale = new Vector3(1, 0, 1);
            infoText.color     = Color.clear;
            // Set timiing and advancement
            stateDuration = fadeTime * 0.2f;
            nextState     = eGameOverPanelState.fadeIn2;
            break;

        case eGameOverPanelState.fadeIn2:
            // Set initial state
            img.color          = Color.black;
            levelRT.localScale = new Vector3(1, 0, 1);
            infoText.color     = Color.clear;
            // Set timiing and advancement
            stateDuration = fadeTime * 0.6f;
            nextState     = eGameOverPanelState.fadeIn3;
            break;

        case eGameOverPanelState.fadeIn3:
            // Set initial state
            img.color          = Color.black;
            levelRT.localScale = new Vector3(1, 1, 1);
            infoText.color     = Color.clear;
            // Set timiing and advancement
            stateDuration = fadeTime * 0.2f;
            nextState     = eGameOverPanelState.display;
            break;

        case eGameOverPanelState.display:
            stateDuration = 999999;     // A very long time
            nextState     = eGameOverPanelState.none;
            if (displayCallback != null)
            {
                displayCallback();
                displayCallback = null;
            }
            break;
        }

        state = newState;
    }