public void EndSession(bool displayText) { Debug.Log("EndSession()"); endTime = Time.time; //TODO: Attempt time sessionEnded = true; //sessionStarted = false; sessionData.sessionPaused = false; freezePlayer = true; GlobalControl.instance.sessionData = sessionData; uiManager.sessionStatusText.text = "(S) Session status: Ended"; if (displayText) { uiManager.dialogBox.GetComponent <DialogBox>().returnToMenu = true; uiManager.OpenDialogBox("Session terminé."); } saveSessionData.SaveData(); //Write data right before closing file saveSessionData.stopSavingData(); //Stop saving data }
//CHECK IF PLAYER HAS REACHED THE RIGHT CHECKPOINT - NEEDS REFACTORING //public void CheckpointValidation() //{ // //Checkpoint checkpoint = lastCheckpoint.GetComponent<Checkpoint>(); // if (onCheckpoint) // { // Checkpoint checkpoint = lastCheckpoint.GetComponent<Checkpoint>(); // if (checkpoint.ID == lastCheckpointCollected + 1) // this is the next valid checkpoint // { // //Debug.Log(checkpointsText.ElementAt(checkpoint.ID - 1)); // uiManager.routeValidationText.text = checkpointsTextS0.ElementAt(checkpoint.ID - 1); //UI info // checkpoint.isCollected = true; // lastCheckpointCollected++; // Debug.Log("lastcheckpointcolleted: " + lastCheckpointCollected + " checkpoint.ID: = " + checkpoint.ID); // //Display information UI // gameManager.freezePlayer = false; // uiManager.dialogBox.GetComponent<DialogBox>().instructionsText.text = checkpointsTextS0.ElementAt(checkpoint.ID - 1); //send the checkpoitn text to the dialog box // uiManager.dialogBox.gameObject.SetActive(true); // if (checkpoint.ID == allCheckpoints.Count) //if this is the last checkpoint go back to the menu // { // gameManager.EndSession(true); // uiManager.dialogBox.GetComponent<DialogBox>().returnToMenu = true; // } // } // else // { // if (lastCheckpointCollected == 0) // no checkpoint has been collected // { // Debug.Log("Return to start"); // uiManager.OpenDialogBox("Incorrect - return to start"); // intersectionManager.GotoCoord(routeManager.routeStart.ElementAt(0), routeManager.routeStart.ElementAt(1)); //Place player at start of route // uiManager.routeValidationText.text = "Incorrect - return to start"; // } // else // { // Debug.Log("Return to previous checkpoint: " + lastCheckpointCollected); // // go to the previous checkpoint // //Display information UI // uiManager.OpenDialogBox("Incorrect - return to last checkpoint"); // List<string> previousCheckpointCoord = routeManager.SplitCoordinates(allCheckpoints[lastCheckpointCollected - 1]); // intersectionManager.GotoCoord(previousCheckpointCoord[0], previousCheckpointCoord[1]); // Debug.Log("Goto called"); // //gameManager.freezePlayer = true; // //intersectionManager.GotoCoord(allCheckpoints[lastCheckpointCollected - 1], "e"); // uiManager.routeValidationText.text = "Incorrect - return to last checkpoint"; // } // } // } // else //not on checkpoint // { // if (lastCheckpointCollected == 0) // no checkpoint has been collected // { // Debug.Log("Return to start"); // uiManager.OpenDialogBox("Incorrect - return to start"); // intersectionManager.GotoCoord(routeManager.routeStart.ElementAt(0), routeManager.routeStart.ElementAt(1)); //Place player at start of route // uiManager.routeValidationText.text = "Incorrect - return to start"; // } // else // { // Debug.Log("Return to previous checkpoint: " + lastCheckpointCollected); // // go to the previous checkpoint // uiManager.OpenDialogBox("Incorrect - return to last checkpoint"); // List<string> previousCheckpointCoord = routeManager.SplitCoordinates(allCheckpoints[lastCheckpointCollected - 1]); // intersectionManager.GotoCoord(previousCheckpointCoord[0], previousCheckpointCoord[1]); // //intersectionManager.GotoCoord(allCheckpoints[lastCheckpointCollected - 1], "e"); // uiManager.routeValidationText.text = "Incorrect - return to last checkpoint"; // } // } // gameManager.freezePlayer = false; //} public void CheckpointValidationNew() { if (gameManager.sessionStarted) { Debug.Log("Inside CheckpointValidationNew"); //Checkpoint checkpoint = lastCheckpoint.GetComponent<Checkpoint>(); if (onCheckpoint) { Checkpoint checkpoint = lastCheckpoint.GetComponent <Checkpoint>(); if (checkpoint.ID == lastCheckpointCollected + 1) // this is the next valid checkpoint { //Debug.Log(checkpointsText.ElementAt(checkpoint.ID - 1)); if (gameManager.sessionData.selectedRoute == 0) { uiManager.routeValidationText.text = checkpointsTextS0.ElementAt(checkpoint.ID - 1); } else { uiManager.routeValidationText.text = checkpointsTextS6.ElementAt(checkpoint.ID - 1); } //UI info checkpoint.isCollected = true; lastCheckpointCollected++; Debug.Log("lastcheckpointcolleted: " + lastCheckpointCollected + " checkpoint.ID: = " + checkpoint.ID); //Display information UI gameManager.freezePlayer = false; if (gameManager.sessionData.selectedRoute == 0) { uiManager.dialogBoxCheckpoint.GetComponent <CheckpointDialogBox>().instructionsText.text = checkpointsTextS0.ElementAt(checkpoint.ID - 1).Replace("|", System.Environment.NewLine); //send the checkpoitn text to the dialog box } else { uiManager.dialogBoxCheckpoint.GetComponent <CheckpointDialogBox>().instructionsText.text = checkpointsTextS6.ElementAt(checkpoint.ID - 1).Replace("|", System.Environment.NewLine); //send the checkpoitn text to the dialog box } uiManager.dialogBoxCheckpoint.gameObject.SetActive(true); uiManager.dialogBoxCheckpoint.GetComponent <CheckpointDialogBox>().dialogBoxBtn.Select(); uiManager.dialogBoxCheckpoint.GetComponent <CheckpointDialogBox>().dialogBoxBtn.OnSelect(null); if (checkpoint.ID == allCheckpoints.Count) //if this is the last checkpoint go back to the menu { //gameManager.EndSession(false); - REPLACE WITH BELOW //endTime = Time.time; gameManager.sessionEnded = true; //sessionStarted = false; gameManager.sessionData.sessionPaused = false; //gameManager.freezePlayer = true; GlobalControl.instance.sessionData = gameManager.sessionData; uiManager.sessionStatusText.text = "(S) Session status: Ended"; saveSessionData.SaveData(); //Write data right before closing file saveSessionData.stopSavingData(); //Stop saving data uiManager.dialogBoxCheckpoint.GetComponent <CheckpointDialogBox>().returnToMenu = true; } } else { returnToWhere(); } } else //not on checkpoint { returnToWhere(); } } }