44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Lean.Pool;
|
|
using UnityEngine;
|
|
|
|
namespace Ichni.Editor
|
|
{
|
|
public class LogWindow : MonoBehaviour
|
|
{
|
|
public GameObject logTextPrefab;
|
|
|
|
public RectTransform textRect;
|
|
public Queue<LogText> logTexts;
|
|
public int logTextCapacity = 4;
|
|
|
|
private void Start()
|
|
{
|
|
logTexts = new Queue<LogText>();
|
|
}
|
|
|
|
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<LogText>();
|
|
if (color == default) color = Color.white;
|
|
logText.SetLogText(text, color);
|
|
logTexts.Enqueue(logText);
|
|
}
|
|
|
|
private void CheckLogTextCapacity()
|
|
{
|
|
if (logTexts.Count >= logTextCapacity)
|
|
{
|
|
LeanPool.Despawn(logTexts.Dequeue().gameObject);
|
|
}
|
|
}
|
|
}
|
|
} |