Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
white_lee's avatar
white_lee
Honored Guest
2 years ago

Question about data saving

Hello, how to save the game data in progress (ex. virtual helmet rotation y-axis) in the Oculus Quest2 helmet, and be able to open the folder to find the stored file data after the end. 

I use this C# but not woking, how to test that data can save in helmet :

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
 

 
   // private List<string[]> dataList = new List<string[]>(); // 
   // private string[] header = { "Name", "Age", "Gender" }; //
   // private string filePath; // save path
 
 
public class DataRecorder : MonoBehaviour
{
    private float[] yRotations;
    private int currentIndex = 0;
 
    public DataRecorder dataRecorder; 
 
 
    private void Awake()
    {
        yRotations = new float[1000]; // 
    }
 
    public void RecordData(float yRotation)
    {
        yRotations[currentIndex++] = yRotation;
    }
 

    public string SaveDataToFile()
    {
        string filePath = Path.Combine(Application.persistentDataPath, "data.csv");
 
        using (StreamWriter writer = new StreamWriter(filePath))
        {
            for (int i = 0; i < currentIndex; i++)
            {
                writer.WriteLine(yRotations[i]);
            }
        }
 
        return filePath;
    }
   
    public void OnButtonClick()
    {
       
        float yRotation = transform.rotation.eulerAngles.y;
        dataRecorder.RecordData(yRotation);
    }
 
}
 
 
 
 
/* public float loggingInterval = 1f; // record time(sec)
 public string logFileName = "head_rotation_log.txt"; // 
 
 private float timer = 0f;
 private float lastYRotation = 0f;
 private float currentYRotation = 0f;
 private string logFilePath;
 TimerController IOtime;*/
 
/*void Start()
    {
    logFilePath = Path.Combine(Application.dataPath, logFileName);
    IOtime.timeElapsed = timer;
}*/
 
/* void Update()
{
   currentYRotation = transform.rotation.eulerAngles.y; //
 
    timer += Time.deltaTime;
    if (timer >= loggingInterval)
    {
        float yRotationDelta = currentYRotation - lastYRotation;
        Debug.Log("Y Rotation: " + yRotationDelta + " degrees in " + loggingInterval + " seconds");
 
        using (StreamWriter writer = new StreamWriter(logFilePath, true))
        {
            writer.WriteLine("Y Rotation: " + yRotationDelta + " degrees in " + loggingInterval + " seconds");
        }
 
        lastYRotation = currentYRotation;
        timer = 0f;
    }
}*/
 
 
 
 
 
 
 
 

 

 
Replies have been turned off for this discussion