Note inspector调整,Static Window可开关,Log可复制清空
This commit is contained in:
@@ -3,20 +3,30 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Lean.Pool;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class LogWindow : MonoBehaviour
|
||||
public class LogWindow : StaticWindow
|
||||
{
|
||||
public GameObject logTextPrefab;
|
||||
|
||||
List<string> savedTexts;
|
||||
|
||||
public RectTransform textRect;
|
||||
public Button copyAllTextsButton;
|
||||
public Button removeAllTextsButton;
|
||||
public Queue<LogText> logTexts;
|
||||
public int logTextCapacity = 4;
|
||||
|
||||
private void Start()
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
savedTexts = new List<string>();
|
||||
logTexts = new Queue<LogText>();
|
||||
copyAllTextsButton.onClick.AddListener(CopyAllText);
|
||||
removeAllTextsButton.onClick.AddListener(RemoveAllText);
|
||||
}
|
||||
|
||||
public static void Log(string text, Color color = default)
|
||||
@@ -29,6 +39,7 @@ namespace Ichni.Editor
|
||||
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);
|
||||
}
|
||||
@@ -40,5 +51,26 @@ namespace Ichni.Editor
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user