Created
February 12, 2025 03:08
-
-
Save inoook/3910b77f7649593007bc7b798dcdd6ea to your computer and use it in GitHub Desktop.
Log
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Logger : MonoBehaviour | |
{ | |
public static Logger INSTANCE = null; | |
public static void Log(string str) | |
{ | |
INSTANCE._Log(str); | |
} | |
public static void Clear() | |
{ | |
INSTANCE._Clear(); | |
} | |
public static string GetLog() | |
{ | |
return INSTANCE._GetLogStr(); | |
} | |
private void Awake() | |
{ | |
INSTANCE = this; | |
} | |
List<string> logList = new List<string>(); | |
[SerializeField] int maxLog = 20; | |
string logStr = ""; | |
public void _Log(string csvStr) | |
{ | |
string timeCodeStr = $"{System.DateTime.Now:yyyyMMdd_HHmm_ss}"; | |
Append($"{timeCodeStr}\t,{csvStr}"); | |
} | |
void Append(string log) | |
{ | |
logList.Insert(0, log); | |
if (logList.Count > maxLog) | |
{ | |
logList.RemoveAt(logList.Count - 1); | |
} | |
logStr = string.Join(System.Environment.NewLine, logList); | |
} | |
void _Clear() | |
{ | |
logStr = ""; | |
logList.Clear(); | |
} | |
string _GetLogStr() | |
{ | |
return logStr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment