/// <summary>
        /// Stops the timers and disables control of all racers, also saves the historical records.
        /// </summary>
        public void StopRace()
        {
            m_IsRaceRunning = false;

            foreach (KeyValuePair <IRacer, Checkpoint> racerNextCheckpoint in m_RacerNextCheckpoints)
            {
                racerNextCheckpoint.Key.DisableControl();
                racerNextCheckpoint.Key.PauseTimer();
            }

            TrackRecord.Save(m_HistoricalBestLap);
            TrackRecord.Save(m_HistoricalBestRace);

            // displays game over menu and sets score
            gameOverCanvas.gameObject.SetActive(true);
            gameOverCanvas.SetScore(m_SessionBestLap.time, m_HistoricalBestLap.time);

            // adds coins to total number of coins
            CoinManager coinManager = FindObjectOfType <CoinManager>();

            if (coinManager == null)
            {
                Debug.LogError("Coin Manager missing in scene");
            }
            coinManager.SetCoinsNumber();
        }
Пример #2
0
        /// <summary>
        /// Creates a TrackRecord with default values.
        /// </summary>
        public static TrackRecord CreateDefault()
        {
            TrackRecord defaultRecord = new TrackRecord();

            defaultRecord.time = k_DefaultTime;
            return(defaultRecord);
        }
Пример #3
0
        /// <summary>
        /// Finds and loads a TrackRecord file.
        /// </summary>
        /// <param name="track">The name of the track to be loaded.</param>
        /// <param name="lapCount">The number of laps of the record to be loaded.</param>
        /// <returns>The loaded record.</returns>
        public static TrackRecord Load(string track, int lapCount)
        {
            string folderPath = Path.Combine(Application.persistentDataPath, k_FolderName);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            string dataPath = Path.Combine(folderPath, track + lapCount + k_FileExtension);

            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (FileStream fileStream = File.Open(dataPath, FileMode.OpenOrCreate))
            {
                if (fileStream.Length == 0)
                {
                    return(CreateDefault());
                }
                try
                {
                    TrackRecord loadedRecord = binaryFormatter.Deserialize(fileStream) as TrackRecord;

                    if (loadedRecord == null)
                    {
                        return(CreateDefault());
                    }
                    return(loadedRecord);
                }
                catch (Exception)
                {
                    return(CreateDefault());
                }
            }
        }
Пример #4
0
 void Awake()
 {
     if (checkpoints.Count < 3)
     {
         Debug.LogWarning("There are currently " + checkpoints.Count + " checkpoints set on the Track Manager.  A minimum of 3 is recommended but kart control will not be enabled with 0.");
     }
     m_HistoricalBestLap  = TrackRecord.Load(trackName, 1);
     m_HistoricalBestRace = TrackRecord.Load(trackName, raceLapTotal);
 }
Пример #5
0
        /// <summary>
        /// Stops the timers and disables control of all racers, also saves the historical records.
        /// </summary>
        public void StopRace()
        {
            m_IsRaceRunning = false;

            foreach (KeyValuePair <IRacer, Checkpoint> racerNextCheckpoint in m_RacerNextCheckpoints)
            {
                racerNextCheckpoint.Key.DisableControl();
                racerNextCheckpoint.Key.PauseTimer();
            }

            TrackRecord.Save(m_HistoricalBestLap);
            TrackRecord.Save(m_HistoricalBestRace);
        }
Пример #6
0
        /// <summary>
        /// Stops the timers and disables control of all racers, also saves the historical records.
        /// </summary>
        public void StopRace()
        {
            m_IsRaceRunning = false;

            foreach (KeyValuePair <IRacer, Checkpoint> racerNextCheckpoint in m_RacerNextCheckpoints)
            {
                racerNextCheckpoint.Key.DisableControl();
                racerNextCheckpoint.Key.PauseTimer();
            }

            TrackRecord.Save(m_HistoricalBestLap);
            TrackRecord.Save(m_HistoricalBestRace);

            //show main manu at end of race
            controller.ToggleMainMenu(true);
        }
Пример #7
0
        /// <summary>
        /// Stops the timers and disables control of all racers, also saves the historical records.
        /// </summary>
        public void StopRace()
        {
            m_IsRaceRunning = false;

            foreach (KeyValuePair <IRacer, Checkpoint> racerNextCheckpoint in m_RacerNextCheckpoints)
            {
                racerNextCheckpoint.Key.DisableControl();
                racerNextCheckpoint.Key.PauseTimer();
            }

            TrackRecord.Save(m_HistoricalBestLap);
            TrackRecord.Save(m_HistoricalBestRace);
            BestTime = SessionBestLap;                               //Obtengo el valor de mejor vuelta.
            BestTime = Mathf.Round(SessionBestLap * 100f) / 100f;    //Redondeo para tener solo 2 decimales.
            PlayerPrefs.SetString("Best time", BestTime.ToString()); //Convierto el número flotante a texto.
            PlayerPrefs.Save();                                      //Guardo el valor como texto.
        }
Пример #8
0
        /// <summary>
        /// Saves a record using a file name based on the track name and number of laps.
        /// </summary>
        public static void Save(TrackRecord record)
        {
            string folderPath = Path.Combine(Application.persistentDataPath, k_FolderName);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            string dataPath = Path.Combine(folderPath, record.trackName + record.laps + k_FileExtension);

            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (FileStream fileStream = File.Open(dataPath, FileMode.OpenOrCreate))
            {
                binaryFormatter.Serialize(fileStream, record);
            }
        }