コード例 #1
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);

            // 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
ファイル: TrackManager.cs プロジェクト: Hennns/FormulaOne
 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
ファイル: TrackManager.cs プロジェクト: cupOJ/MathRace
        /// <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
ファイル: TrackManager.cs プロジェクト: Hennns/FormulaOne
        /// <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);
            }
        }