/// <summary> /// Writes arbitrary binary data to a dated debug file /// </summary> public static void BinaryWrite(byte[] b, string name) { try { string fileName = DateTime.Now.ToString(DateFormat) + "_" + name + ".bin"; string filePath = Path.Combine(CoreParams.PersistentDataPath, CoreParams.DebugPath, fileName); if (!Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } File.WriteAllBytes(filePath, b); } catch (Exception e) { CDebug.LogEx($"Failed to write binary data to file {name} ({e.GetType().Name})", LogLevel.Warning, null); } }
/// <summary> /// Writes arbitrary text to a dated debug file /// </summary> public static void TextWrite(string s, string name) { try { string fileName = DateTime.Now.ToString(DateFormat) + "_" + name + ".txt"; string filePath = Path.Combine(CoreParams.PersistentDataPath, CoreParams.DebugPath, fileName); if (!Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } File.WriteAllText(filePath, s, Encoding.UTF8); } catch (Exception e) { CDebug.LogEx($"Failed to write text to file {name} ({e.GetType().Name})", LogLevel.Warning, null); } }
/// <summary> /// Serializes an arbitrary object to json, then writes it to a dated debug file /// </summary> public static void JsonWrite(object o, string name) { try { string fileName = DateTime.Now.ToString(DateFormat) + "_" + name + ".json"; string filePath = Path.Combine(CoreParams.PersistentDataPath, CoreParams.DebugPath, fileName); string jsonData = JsonStringify(o, true); if (!Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } File.WriteAllText(filePath, jsonData); } catch (Exception e) { CDebug.LogEx($"Failed to write object {o.Ref()?.GetType().Name} to file {name} ({e.GetType().Name})", LogLevel.Warning, null); } }
public static void TakeScreenshot() { try { string fileName = $"{Application.productName}_{DateTime.Now.ToString(DateFormat)}.png"; string filePath = Path.Combine(CoreParams.ScreenshotsPath, fileName); if (!Directory.Exists(Path.GetDirectoryName(filePath))) { Directory.CreateDirectory(Path.GetDirectoryName(filePath)); } ScreenCapture.CaptureScreenshot(filePath); Debug.Log("Saved screenshot to " + filePath); } catch (Exception e) { CDebug.LogEx($"Failed to take screenshot ({e.GetType().Name})", LogLevel.Warning, null); } }