コード例 #1
0
    public void Progress(float timeStep)
    {
        RectTransform   textTrans             = null;
        bool            textPaused            = false;
        bool            progressText          = false;
        int             textStage             = INVALID_TEXT_STAGE;
        float           stageDuration         = 0f;
        float           stageElapsed          = 0f;
        float           stageRate             = 0f;
        bool            keepStage             = false;
        SpritedStringUI text                  = null;
        Color           textColor             = Color.white;
        Vector3         textScale             = Vector3.one;
        Vector2         textIncreasedScale    = Vector2.zero;
        bool            textRemoved           = false;
        int             textEvolution         = INVALID_TEXT_EVOLUTION;
        float           textElapsed           = 0f;
        Transform       textOriginTrans       = null;
        Vector2         textOriginWorld       = Vector2.zero;
        Vector2         textOriginCanvas      = Vector2.zero;
        Vector3         completeWorldPos      = Vector3.zero;
        Vector2         currentOriginWorldPos = Vector2.zero;
        Vector2         textSpeed             = Vector2.zero;

        if (textTransforms != null)
        {
            for (int i = 0; i < textTransforms.Length; i++)
            {
                textPaused = textPauseds[i];

                /*halmeida - if a text was added during a game pause, I will progress it during the pause and I will continue
                 * progressing it after the game is unpaused, because I don't want it to get stuck in the screen until the next pause.
                 * However, if a text was added when the game was unpaused, I will only progress it while the game is unpaused.*/
                progressText = (textPaused || (!textPaused && !paused));
                if (progressText)
                {
                    textTrans   = textTransforms[i];
                    text        = texts[i];
                    textStage   = textStages[i];
                    stageRate   = 0f;
                    textRemoved = false;
                    switch (textStage)
                    {
                    case TEXT_STAGE_SHOW:
                        stageDuration = textDurationsShow[i];
                        if (stageDuration <= 0f)
                        {
                            stageRate = 1f;
                        }
                        else
                        {
                            stageElapsed  = textStageElapseds[i];
                            stageElapsed += timeStep;
                            stageRate     = stageElapsed / stageDuration;
                            stageRate     = (stageRate > 1f) ? 1f : stageRate;
                            textColor     = text.GetGeneralColor();
                            textColor.a   = Mathf.Lerp(0f, 1f, stageRate);
                            text.SetGeneralColor(textColor);
                            textIncreasedScale   = textIncreasedScales[i];
                            textScale            = textTrans.localScale;
                            textScale.x          = Mathf.Lerp(textIncreasedScale.x, 1f, stageRate);
                            textScale.y          = Mathf.Lerp(textIncreasedScale.y, 1f, stageRate);
                            textTrans.localScale = textScale;
                        }
                        break;

                    case TEXT_STAGE_PLAIN:
                        stageDuration = textDurationsPlain[i];
                        if (stageDuration <= 0f)
                        {
                            stageRate = 1f;
                        }
                        else
                        {
                            stageElapsed  = textStageElapseds[i];
                            stageElapsed += timeStep;
                            stageRate     = stageElapsed / stageDuration;
                            stageRate     = (stageRate > 1f) ? 1f : stageRate;
                        }
                        break;

                    case TEXT_STAGE_HIDE:
                        stageDuration = textDurationsHide[i];
                        if (stageDuration <= 0f)
                        {
                            stageRate = 1f;
                        }
                        else
                        {
                            stageElapsed  = textStageElapseds[i];
                            stageElapsed += timeStep;
                            stageRate     = stageElapsed / stageDuration;
                            stageRate     = (stageRate > 1f) ? 1f : stageRate;
                            textColor     = text.GetGeneralColor();
                            textColor.a   = Mathf.Lerp(1f, 0f, stageRate);
                            text.SetGeneralColor(textColor);
                            textIncreasedScale   = textIncreasedScales[i];
                            textScale            = textTrans.localScale;
                            textScale.x          = Mathf.Lerp(1f, textIncreasedScale.x, stageRate);
                            textScale.y          = Mathf.Lerp(1f, textIncreasedScale.y, stageRate);
                            textTrans.localScale = textScale;
                        }
                        break;

                    case TEXT_STAGE_OVER:
                        RemoveCanvasText(i);
                        textRemoved = true;
                        break;
                    }
                    if (textRemoved)
                    {
                        if (textTransforms != null)
                        {
                            i--;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        textEvolution = textEvolutions[i];
                        if ((textEvolution == TEXT_EVOLUTION_NONE_WAIT) && endWaitingTexts)
                        {
                            textEvolutions[i] = TEXT_EVOLUTION_NONE_GO;
                            textEvolution     = TEXT_EVOLUTION_NONE_GO;
                        }
                        if (stageRate == 1f)
                        {
                            keepStage = ((textEvolution == TEXT_EVOLUTION_NONE_WAIT) && (textStage == TEXT_STAGE_PLAIN));
                            if (!keepStage)
                            {
                                textStage++;
                                textStages[i]        = textStage;
                                textStageElapseds[i] = 0f;
                            }
                            else
                            {
                                textStageElapseds[i] = stageElapsed;
                            }
                        }
                        else
                        {
                            textStageElapseds[i] = stageElapsed;
                        }
                        textElapsed     = textElapseds[i];
                        textElapsed    += timeStep;
                        textElapseds[i] = textElapsed;
                        textOriginTrans = textOriginTransforms[i];
                        textOriginWorld = textOriginPositions[i];
                        if (textOriginTrans != null)
                        {
                            completeWorldPos       = textOriginTrans.position;
                            currentOriginWorldPos  = new Vector2(completeWorldPos.x, completeWorldPos.y);
                            currentOriginWorldPos += textOriginWorld;
                        }
                        else
                        {
                            currentOriginWorldPos = textOriginWorld;
                        }
                        if (TransformWorldToCanvasPosition(currentOriginWorldPos, ref textOriginCanvas))
                        {
                            textSpeed = textSpeeds[i];
                            textTrans.anchoredPosition = textOriginCanvas + (textElapsed * textSpeed);
                        }
                        text.FeedPositionToMaterial();
                    }
                }
            }
        }
        endWaitingTexts = false;
    }