private void OnApplicationQuit() { if (ShouldCollectData) { //To collect the final state of the game and also know how long the player played MetricsEvents.CollectTimedData(); WriteToFile(); if (_fileStreamWriter != null) { _fileStreamWriter.Close(); _fileStreamWriter = null; } } }
void Update() { if (ShouldCollectData) { //update timers here _variableCollectTimer += Time.deltaTime; _writeToFileTimer += Time.deltaTime; //then active timed functions if (_variableCollectTimer >= _intervalBetweenTimedVariables) { MetricsEvents.CollectTimedData(); _variableCollectTimer = 0f; } if (_writeToFileTimer >= _intervalBetweenWritingToFile) { WriteToFile(); _writeToFileTimer = 0; } } }