예제 #1
0
    /* Tutorial: https://answers.unity.com/questions/1604527/instantiate-an-array-of-gameobjects-with-a-time-de.html
     * Method goes trough the Dictionary in the opposite ordner and coulors them back to the old colour
     */
    private IEnumerator MakePathDisappear(IntroductionTilesManager tileOptions, CameraFollow cam)
    {
        Dictionary <int, List <Hexagon> > colorList = tileOptions.GetTiles();

        float stopTime = Time.fixedTime + tileOptions.GetTimeBeforeFadingStarts(); // wait for the specified seconds

        while (stopTime > Time.fixedTime && !skipButton.IsButtonPressed())         // if button was pressed, then continue instantly
        {
            yield return(new WaitForSeconds(TIME_TO_CHECK_AGAIN));
        }


        int highestKey = 0;

        try
        {
            highestKey = (int)colorList.Keys.Max();
        }
        catch
        {
            // find an idea how to deal with the problem of tiles.Keys.Max(), if there's no value at all
        }

        for (int i = highestKey; i >= 0; i--)
        {
            if (colorList.TryGetValue(i, out List <Hexagon> hexagonList)) // if the key is available, then procceed
            {
                for (int k = 0; k < hexagonList.Count; k++)
                {
                    Hexagon hexagon = hexagonList[k];

                    if (tileOptions.CameraShouldFollow())
                    {
                        cam.SetTarget(hexagon.transform);
                    }

                    if (!hexagon.IsCheckpointTile())  // if there was no choosing of checkpoints or the hexagon is not a checkpoint anyway, then get it's colour back
                    {
                        if (tileColors.TryGetValue(hexagon, out Color hexagonColor))
                        {
                            hexagon.SetColor(hexagonColor);
                        }
                    }
                }

                stopTime = Time.fixedTime + tileOptions.GetTimeForEachTileFading(); // wait for the specified seconds
                while (stopTime > Time.fixedTime && !skipButton.IsButtonPressed())  // if button was pressed, then continue instantly
                {
                    yield return(new WaitForSeconds(TIME_TO_CHECK_AGAIN));
                }
            }
        }
        tileOptions.SetFinished(true);
    }
예제 #2
0
    /*  Tutorial: https://answers.unity.com/questions/1604527/instantiate-an-array-of-gameobjects-with-a-time-de.html
     *  This method will colour all the incoming tiles
     *  Works : tiles are colored in with a delay
     **/
    private IEnumerator SetColor(IntroductionTilesManager tileOptions, bool waitForChoosingCheckPoints, CameraFollow cam)
    {
        float stopTime = Time.fixedTime + tileOptions.GetStartingTime();   // wait for the specified seconds

        while (stopTime > Time.fixedTime && !skipButton.IsButtonPressed()) // if button was pressed, then continue instantly
        {
            yield return(new WaitForSeconds(TIME_TO_CHECK_AGAIN));
        }

        Dictionary <int, List <Hexagon> > colorList = tileOptions.GetTiles();
        int numberOfLists    = colorList.Count;
        int countActualSteps = 0;

        for (int i = 0; i < numberOfLists; i++)
        {
            if (colorList.TryGetValue(i, out List <Hexagon> hexagonList)) // if the key is available, then just procceed
            {
                List <Hexagon> hexagons = hexagonList;

                for (int k = 0; k < hexagons.Count; k++)
                {
                    hexagons[k].SetColor(tileOptions.GetColor());
                    if (tileOptions.CameraShouldFollow())
                    {
                        cam.SetTarget(hexagons[k].transform);
                    }

                    if (countActualSteps == colorList.Count - 1)
                    {
                        cam.GetBackInPosition();
                        while (!cam.GetCameraReachedFinalPosition() && !skipButton.IsButtonPressed())  // wait for the user to finish watching the introduction screen
                        {
                            yield return(new WaitForSeconds(TIME_TO_CHECK_AGAIN));
                        }
                    }
                }

                stopTime = Time.fixedTime + tileOptions.GetTimeToNextTile();       // wait for the specified seconds
                while (stopTime > Time.fixedTime && !skipButton.IsButtonPressed()) // if button was pressed, then continue instantly
                {
                    yield return(new WaitForSeconds(TIME_TO_CHECK_AGAIN));
                }
                countActualSteps++;
            }
            else
            {
                numberOfLists++;    // if this key doesn't exist, increase the number to keep looking for every available list
            }
        }
        tileOptions.SetReadyForCheckpoints(true);

        while (!IsReadyForCheckpoints())
        {
            yield return(new WaitForSeconds(TIME_TO_CHECK_AGAIN));
        }

        if (waitForChoosingCheckPoints)
        {
            while (!checkpointsHasBeenMarked)
            {
                yield return(new WaitForSeconds(TIME_TO_CHECK_AGAIN));
            }
        }

        StartCoroutine(MakePathDisappear(tileOptions, cam)); //start the disappering backwards
    }