public void StartLogging(string folder) { if (PlayerPrefs.GetInt(playerprefstoggle, 1) == 0) { enabled = false; return; } try { string foldername = Path.Combine(folder, "logs"); Directory.CreateDirectory(foldername); string filename = Path.Combine(foldername, DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv"); writer = new StreamWriter(filename, false, Encoding.UTF8); writer.WriteLine("\"Total Time\",\"Scene Time\",\"Scene\",\"Yaw\",\"Pitch\",\"Roll\",\"Extra Information\""); enabled = true; } catch (Exception e) { if (writer != null) { writer.Close(); writer = null; } DebugText.LogException("Could not create logfile", e); enabled = false; return; } startTime = Time.time; currentScene = "unkown_scene"; sceneTime = startTime; intervalTime = 0f; extraInformation = new Queue <string>(); }
public void RefreshFolder() { if (dataFolder == null || dataFolder == "") { Debug.LogError("Folder path for scenarios not found"); return; } for (int i = scenarioButtonHolder.childCount - 1; i >= 0; i--) { Destroy(scenarioButtonHolder.GetChild(i).gameObject); } try { Directory.CreateDirectory(dataFolder); Directory.GetLastAccessTime(dataFolder); Directory.GetDirectories(dataFolder); } catch (UnauthorizedAccessException) { PermissionRequester.RequestPermisssion((req) => { if (req) { RefreshFolder(); } else { DebugText.LogError("Cannot access scenario folder without permission"); } }); return; } catch (Exception e) { DebugText.LogException("Cannot access scenario folder", e); return; } string[] dirs = Directory.GetDirectories(dataFolder); foreach (string dir in dirs) { GameObject button = GameObject.Instantiate <GameObject>(scenarioButton, scenarioButtonHolder, false); button.GetComponent <Button>().onClick.AddListener(() => { scenarioManager.LoadScenario(Path.Combine(dataFolder, dir)); }); button.GetComponentInChildren <Text>().text = Path.GetFileName(dir); } }
public static void RequestPermisssion(Action <bool> callback) { #if UNITY_ANDROID && !UNITY_EDITOR try { using (AndroidJavaClass prc = new AndroidJavaClass("aggrathon.vq360.javaplugin.PermissionRequester")) { AndroidJavaClass uac = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject activity = uac.GetStatic <AndroidJavaObject>("currentActivity"); if (prc.CallStatic <bool>("HasExternalPermission", activity)) { if (callback != null) { callback(true); } return; } else { if (instance == null) { GameObject go = new GameObject("Permission Requester"); instance = go.AddComponent <PermissionRequester>(); DontDestroyOnLoad(go); } instance.permissionCallback = callback; prc.CallStatic("GetExternalPermission", activity, instance.name, "PermissionRequestCallback"); } } } catch (Exception e) { DebugText.LogException("Could not request permissions", e); if (callback != null) { callback(false); } } #else if (callback != null) { callback(true); } #endif }
private void OnDisable() { if (writer != null) { while (extraInformation.Count > 0) { logInterval = 0f; Update(); } try { writer.Close(); } catch (Exception e) { DebugText.LogException("Could not close logfile", e); } writer = null; extraInformation = null; } }
void Update() { if (writer == null) { enabled = false; return; } intervalTime -= Time.deltaTime; if (intervalTime <= 0f) { intervalTime += logInterval; try { string extra = extraInformation.Count > 0 ? extraInformation.Dequeue() : ""; Vector3 rot = mainCamera.eulerAngles; writer.WriteLine(string.Format("{0:F2},{1:F2},\"{2}\",{3:F2},{4:F2},{5:F2},\"{6}\"", Time.time - startTime, Time.time - sceneTime, currentScene, rot.y, rot.x, rot.z, extra )); } catch (Exception e) { if (writer != null) { writer.Close(); writer = null; } DebugText.LogException("Could not write to logfile", e); enabled = false; return; } } }