@@ -3,23 +3,26 @@ using System.Collections.Generic;
|
||||
using Lean.Pool;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class LogText : MonoBehaviour
|
||||
{
|
||||
public TMP_Text logText;
|
||||
|
||||
|
||||
public void SetLogText(string text, Color color)
|
||||
{
|
||||
logText.text = text;
|
||||
logText.color = color;
|
||||
|
||||
|
||||
string logFilePath = EditorManager.instance.projectInformation.projectPath + "/Logs/EditorLog.txt";
|
||||
|
||||
|
||||
// if(!ES3.FileExists(logFilePath)) System.IO.File.Create(logFilePath).Dispose();
|
||||
//
|
||||
// System.IO.File.AppendAllText(logFilePath, text + "\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using Lean.Pool;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
@@ -13,18 +14,17 @@ namespace Ichni.Editor
|
||||
public GameObject logTextPrefab;
|
||||
|
||||
List<string> savedTexts;
|
||||
|
||||
public RectTransform textRect;
|
||||
public Button copyAllTextsButton;
|
||||
public Button removeAllTextsButton;
|
||||
public Queue<LogText> logTexts;
|
||||
public List<LogText> logTexts; // 改为 List
|
||||
public int logTextCapacity = 4;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
savedTexts = new List<string>();
|
||||
logTexts = new Queue<LogText>();
|
||||
logTexts = new List<LogText>(); // 初始化为 List
|
||||
copyAllTextsButton.onClick.AddListener(CopyAllText);
|
||||
removeAllTextsButton.onClick.AddListener(RemoveAllText);
|
||||
}
|
||||
@@ -36,19 +36,37 @@ namespace Ichni.Editor
|
||||
|
||||
private void AddLog(string text, Color color = default)
|
||||
{
|
||||
CheckLogTextCapacity();
|
||||
LogText logText = LeanPool.Spawn(logTextPrefab, textRect).GetComponent<LogText>();
|
||||
if (color == default) color = Color.white;
|
||||
savedTexts.Add(text);
|
||||
logText.SetLogText(text, color);
|
||||
logTexts.Enqueue(logText);
|
||||
}
|
||||
|
||||
private void CheckLogTextCapacity()
|
||||
{
|
||||
if (logTexts.Count >= logTextCapacity)
|
||||
// 插入到头部
|
||||
logTexts.Insert(0, logText);
|
||||
|
||||
// 超出容量则移除最后一个
|
||||
if (logTexts.Count > logTextCapacity)
|
||||
{
|
||||
LeanPool.Despawn(logTexts.Dequeue().gameObject);
|
||||
LogText logText1 = logTexts[logTexts.Count - 1];
|
||||
RectTransform rt = logText1.GetComponent<RectTransform>();
|
||||
rt.DOComplete();
|
||||
rt.DOAnchorPos(new Vector2(0, -23 * (logTexts.Count - 1)), 0.2f).SetEase(Ease.OutCubic);
|
||||
logText1.logText.DOColor(new Color(0, 0, 0, 0), 0.2f).OnComplete(() =>
|
||||
{
|
||||
LeanPool.Despawn(logText1.gameObject);
|
||||
});
|
||||
|
||||
logTexts.RemoveAt(logTexts.Count - 1);
|
||||
|
||||
}
|
||||
logText.logText.color = new Color(0, 0, 0, 0);
|
||||
logText.logText.DOColor(color, 0.2f);
|
||||
// 更新所有 log 的位置
|
||||
for (int i = 0; i < logTexts.Count; i++)
|
||||
{
|
||||
RectTransform rt = logTexts[i].GetComponent<RectTransform>();
|
||||
rt.DOComplete();
|
||||
rt.DOAnchorPos(new Vector2(0, -23 * i), 0.2f).SetEase(Ease.OutCubic);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user