Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using UnityEngine;
- namespace M3D.Utilities
- {
- public class Logger
- {
- private static string logFilePath = "Assets/debug.log";
- public static string SystemTime { get { return DateTime.Now.ToString("HH:mm:ss"); } }
- // Pulisce il file di log all'inizio
- public static void ClearLog()
- {
- if (File.Exists(logFilePath))
- {
- File.Delete(logFilePath);
- }
- }
- public static void Log(string message)
- {
- try
- {
- using (StreamWriter writer = new StreamWriter(logFilePath, true))
- {
- writer.WriteLine($"[{SystemTime}] {message}");
- }
- }
- catch (Exception ex)
- {
- Debug.LogError($"[{SystemTime}] Logger failed: {ex.Message}");
- }
- }
- public static void LogWarning(string message)
- {
- using (StreamWriter writer = new StreamWriter(logFilePath, true))
- {
- //writer.WriteLine($"{System.DateTime.Now}: {message}");
- writer.WriteLine($"[{SystemTime}] !!! WARNING !!! {message}");
- }
- }
- public static void LogError(string message)
- {
- using (StreamWriter writer = new StreamWriter(logFilePath, true))
- {
- //writer.WriteLine($"{System.DateTime.Now}: {message}");
- writer.WriteLine($"[{SystemTime}] *** ERROR *** {message}");
- }
- }
- public static void SaveTexturePNG(Texture2D texture, string fileName)
- {
- byte[] bytes = texture.EncodeToPNG();
- string filePath = System.IO.Path.Combine(Application.dataPath, fileName + ".png");
- System.IO.File.WriteAllBytes(filePath, bytes);
- Debug.Log($"Saved texture to: {filePath}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment