Ejemplo n.º 1
0
    /// <summary>
    /// Positions are determined by the spline positions of Train Controller.
    /// </summary>
    /// <returns></returns>
    public List <Vector3> GetTrainControllerPositions()
    {
        List <Vector3> positions = new List <Vector3>();

#if TRAIN_CONTROLLER
        WSMGameStudio.Splines.Spline spline = editorTarget.dataSource.GetComponent <WSMGameStudio.Splines.Spline>();

        if (spline)
        {
            int steps = WSMGameStudio.Splines.SplineDefaultValues.StepsPerCurve * spline.CurveCount;

            for (int i = 0; i <= steps; i++)
            {
                float t = i / (float)steps;

                Vector3 position = spline.GetPoint(t);

                positions.Add(position);
            }
        }
#else
        Debug.LogError("Train Controller selected, but scripting define symbol TRAIN_CONTROLLER isn't set");
#endif

        return(positions);
    }
        // 20190621: Changed FixedUPdate to update.
        private void Update()
        {
            FollowSpline();
            if (_progress == 1 && currentSpline.name != "EndingSpline")
            {
                Collider[] colliders          = Physics.OverlapSphere(gameObject.transform.position, checkSphereRadius);
                bool       nextSplineSelected = false;
                // Switch to the next spline
                // For chapter 4: Check if a portal is reached.
                if (GameObject.Find("CheckWinController").GetComponent <CheckWin>().level.Contains("D"))
                {
                    if (ReachedDiscontinuity(gameObject.transform.position.x))
                    {
                        currentSpline      = FindDestinationSpline(gameObject.transform.position.x);
                        nextSplineSelected = true;
                    }
                }

                if (!nextSplineSelected)
                {
                    foreach (Collider collider in colliders)
                    {
                        if (collider.gameObject.name.Contains("Spline") && collider.gameObject.name != currentSpline.gameObject.name)
                        {
                            GameObject nextSplineObject = collider.gameObject;
                            currentSpline = nextSplineObject.GetComponent <Spline>();
                            break;
                        }
                    }
                }


                _distance = currentSpline.GetTotalDistance();
                _progress = 0;
            }

            else if (currentSpline.name == "EndingSpline")
            {
                // Ask scoreboard to display the end result.
                if (!endLevel)
                {
                    GameObject.Find("TrackSound").GetComponent <ClickSound>().StopSound();
                    // Start displaying results.
                    scoreboardButtons.SetActive(true);
                    GameObject.Find("ScoreBar").GetComponent <Animator>().Play("pullDownScorePanel");
                    GameObject.Find("AccuracyBar").GetComponent <Animator>().Play("closeAccuracyPanel");
                    endLevel = true;
                    if (GameObject.Find("CheckWinController").GetComponent <CheckWin>().win)
                    {
                        GameObject.Find("ResultMessage").GetComponent <TextMeshProUGUI>().text = "Cleared!";
                        // Start Confetti effect.
                        gameObject.transform.GetChild(2).gameObject.SetActive(true);
                    }
                    else
                    {
                        GameObject.Find("ResultMessage").GetComponent <TextMeshProUGUI>().text  = "Try again next time.";
                        GameObject.Find("ButtonNextLevel").GetComponent <Button>().interactable = false;
                    }

                    GameObject.Find("DarkProgressBar").GetComponent <Animator>().Play("Idle");

                    string levelStr = GameObject.Find("CheckWinController").GetComponent <CheckWin>().level;

                    int    currentLevel = int.Parse(GameObject.Find("CheckWinController").GetComponent <CheckWin>().level.Substring(1));
                    int    nextLevel    = currentLevel + 1;
                    string nextLevelStr = levelStr[0] + nextLevel.ToString();
                    if (!GameDataManager.currentPlayer.levelProgress.ContainsKey(nextLevelStr))
                    {
                        GameObject.Find("ButtonNextLevel").GetComponent <Button>().interactable = false;
                        GameObject.Find("FinishedAllLevelsText").GetComponent <TextMeshProUGUI>().text
                            = "You have reached the end of this level. \nPlease return to the menu for more levels.";
                    }
                    CheckWin checkWinController = GameObject.Find("CheckWinController").GetComponent <CheckWin>();


                    if (checkWinController.win)
                    {
                        int    starObtained  = checkWinController.starCount;
                        int    scoreObtained = checkWinController.sumScore;
                        Player currentPlayer = GameDataManager.currentPlayer;
                        if (starObtained > GameDataManager.currentPlayer.levelStar[GameDataManager.currentLevel])
                        {
                            // update highest star obtained
                            GameDataManager.currentPlayer.levelStar[GameDataManager.currentLevel] = starObtained;
                        }

                        if (scoreObtained > GameDataManager.currentPlayer.levelHiScore[GameDataManager.currentLevel])
                        {
                            // update highest score obtained
                            GameDataManager.currentPlayer.levelHiScore[GameDataManager.currentLevel] = scoreObtained;
                        }
                    }



                    GameDataManager.currentPlayer.SavePlayer();
                }
                speed -= 0.5f;
                if (speed < 0)
                {
                    speed = 0;
                }
            }
        }