using System; using System.Collections; using System.Collections.Generic; using Lean.Pool; using UnityEngine; using UnityEngine.Serialization; using UnityEngine.UI; namespace Ichni.Editor { public class LogWindow : StaticWindow { public GameObject logTextPrefab; List savedTexts; public RectTransform textRect; public Button copyAllTextsButton; public Button removeAllTextsButton; public Queue logTexts; public int logTextCapacity = 4; protected override void Start() { base.Start(); savedTexts = new List(); logTexts = new Queue(); copyAllTextsButton.onClick.AddListener(CopyAllText); removeAllTextsButton.onClick.AddListener(RemoveAllText); } public static void Log(string text, Color color = default) { EditorManager.instance.uiManager.mainPage.logWindow.AddLog(text, color); } private void AddLog(string text, Color color = default) { CheckLogTextCapacity(); LogText logText = LeanPool.Spawn(logTextPrefab, textRect).GetComponent(); if (color == default) color = Color.white; savedTexts.Add(text); logText.SetLogText(text, color); logTexts.Enqueue(logText); } private void CheckLogTextCapacity() { if (logTexts.Count >= logTextCapacity) { LeanPool.Despawn(logTexts.Dequeue().gameObject); } } private void CopyAllText() { string allText = ""; foreach (string text in savedTexts) { allText += text + "\n"; } GUIUtility.systemCopyBuffer = allText; } private void RemoveAllText() { foreach (LogText logText in logTexts) { LeanPool.Despawn(logText.gameObject); } logTexts.Clear(); savedTexts.Clear(); } } }