// Update is called once per frame void Update() { // laps. if (_currLap < _lapsTexts.Length) { _currLapTime += Time.deltaTime; _totalTime += Time.deltaTime; _lapsTexts[_currLap].text = string.Format(LAP_TIME_FORMAT, (int)(_currLapTime / 60), _currLapTime % 60); _totalTimeText.text = string.Format(LAP_TIME_FORMAT, (int)(_totalTime / 60), _totalTime % 60); } // ghost. if (_ghost != null && _recording != null) { if (_recording.Count == 0) { _ghost.SetActive(false); } else { while (_recording.Count > 0 && _recording.Peek().PointInTime < _totalTime) { RecordMovement.RecordBlock block = _recording.Dequeue(); _ghost.transform.position = block.Position; _ghost.transform.rotation = block.Rotation; } } } }
/// <summary> /// Saves the player recording if he broke the record. /// </summary> private void SaveRecording(Queue <RecordMovement.RecordBlock> recording) { GhostJson jsonSave = new GhostJson() { points = new RecordingJson[recording.Count] }; int idx = 0; while (recording.Count != 0) { RecordMovement.RecordBlock currBlock = recording.Dequeue(); jsonSave.points[idx] = new RecordingJson() { pos = new ThreeNumbersSave(currBlock.Position.x, currBlock.Position.y, currBlock.Position.z), rotation = new FourNumbersSave(currBlock.Rotation.x, currBlock.Rotation.y, currBlock.Rotation.z, currBlock.Rotation.w), time = currBlock.PointInTime }; idx++; } string jsonString = JsonUtility.ToJson(jsonSave); File.WriteAllText(RECORDING_FILE_PATH, jsonString); }