private void saveToJson() { string fileName = $"Position{positions.Count - 1}"; string filePath = Path.Combine(jsonStoragePath, fileName); Vector3 position = headset.position; cameraData data = new cameraData(); data.x = position.x; data.y = position.y; data.z = position.z; string jsonCameraData = JsonUtility.ToJson(data); if (!File.Exists(filePath)) { File.WriteAllText(filePath, jsonCameraData); } }
private void loadCameraPositions() { string[] contents = Directory.GetFiles(jsonStoragePath); for (int i = 0; i < contents.Length; i++) { string fileName = contents[i]; string filePath = Path.Combine(jsonStoragePath, fileName); using (StreamReader reader = new StreamReader(filePath)) { string jsonContents = reader.ReadToEnd(); cameraData data = JsonUtility.FromJson <cameraData>(jsonContents); Vector3 positionData = new Vector3(data.x, data.y, data.z); positions.Add(positionData); } } if (positions.Count > 0) { headset.position = positions[0]; } if (global.cameraArray[3] != 255) { global.cameraArray[3] = 255; } }