コード例 #1
0
ファイル: Progression.cs プロジェクト: cmeyerhardt/Debris
    public IEnumerator PrepareForChoiceSelection()
    {
        //Initiate Pause in Spawning
        Spawner.pause = true;
        //obstacleSpawner.pause = true;
        //objectSpawner.pause = true;
        //badSpawner.pause = true;
        pauseBreakText.SetActive(true);

        DontClickMe.Fly       = true;
        ObstacleDestroyer.Fly = true;

        //int numBadShapes = badSpawner.transform.childCount;
        //float timer = 0f;
        //while(numBadShapes > 0 && timer < 5f)
        //{
        //    DontClickMe d = badSpawner.GetComponentInChildren<DontClickMe>();
        //    if (d != null)
        //    {
        //        d.Destruct();
        //    }
        //    timer += Time.deltaTime;
        //    yield return null;
        //    numBadShapes = badSpawner.transform.childCount;

        //}


        timer = 0f;
        while (objectSpawner.transform.childCount > 0 && timer < 3f)
        {
            timer += Time.deltaTime;
            yield return(null);
        }

        yield return(new WaitForSeconds(1f));

        pauseBreakText.SetActive(false);
        successToastPanel.Activate(false);

        //Reward player's last round success with obstacles moving down (proportionate to percentage success)
        float total             = numSuccessThisRound + numMissedThisRound;
        int   percentageSuccess = Mathf.RoundToInt(numSuccessThisRound / total * 100f);

        GameObject resultText = null;

        if (percentageSuccess >= 75)
        {
            resultText = doingGreatText;
        }
        else if (percentageSuccess >= 25)
        {
            resultText = doingOkText;
        }
        else
        {
            resultText = doBetterText;
        }
        resultText.SetActive(true);
        yield return(new WaitForSeconds(.5f));

        List <Obstacle> obstacles              = obstacleSpawner.GetComponentsInChildren <Obstacle>(true).ConvertToList().RemoveNullReferences();
        int             numTotalObstacles      = Mathf.Max(0, Mathf.Min(obstacles.Count, 6));
        int             numObstaclesGoodEffect = Mathf.Min(Mathf.RoundToInt(percentageSuccess / 100f * numTotalObstacles), numTotalObstacles);

        float interval = Mathf.Min(.6f, 3f / numTotalObstacles);

        for (int i = 0; i < numTotalObstacles; i++)
        {
            Obstacle o = obstacles[i];
            if (o != null)
            {
                if (i < numObstaclesGoodEffect)
                {
                    bool disabled = !o.gameObject.activeInHierarchy;
                    if (disabled)
                    {
                        o.gameObject.SetActive(true);
                    }

                    if (Random.Range(0, 20) > 0)
                    {
                        //Debug.Log("Moving Down: " + i);
                        ObstacleMovesDown(o);
                    }
                    else
                    {
                        //Debug.Log("Decreasing Size: " + i);
                        ObstacleDecreasesInSize(o);
                    }

                    if (disabled)
                    {
                        o.gameObject.SetActive(false);
                    }
                    yield return(new WaitForSeconds(interval));
                }
                else
                {
                    if (obstacleSpawner.transform.childCount < 30 && Random.Range(0, 20) > 0)
                    {
                        //Debug.Log("Spawning: " + i);
                        _ = obstacleSpawner.Spawn();
                    }
                    else
                    {
                        //Debug.Log("Increasing Size: " + i);
                        ObstacleIncreasesInSize(o);
                    }

                    yield return(new WaitForSeconds(interval));
                }
            }
        }

        resultText.SetActive(false);

        DontClickMe.Fly       = false;
        ObstacleDestroyer.Fly = false;

        yield return(new WaitForSeconds(1f));

        if (CreateChoice())
        {
            if (sceneLoader != null)
            {
                yield return(StartCoroutine(sceneLoader.ProcessTimeScaleChange(0f)));
            }
            else
            {
                Debug.LogWarning("Progression does not have a sceneLoader reference!");
            }

            choiceBeingMade = true;
            if (choiceWindow != null)
            {
                choiceWindow.choiceEvent.AddListener(ChoiceMade);
                windowManager.OpenWindow(choiceWindow);
            }
        }
    }