Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        /// <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);
                CDebug.LogEx($"Wrote object {o.Ref()?.GetType().Name} to file {filePath}", LogLevel.Message, null);
            }
            catch (Exception e)
            {
                CDebug.LogEx($"Failed to write object {o.Ref()?.GetType().Name} to file {name} ({e.GetType().Name})", LogLevel.Warning, null);
            }
        }