59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using System;
|
||
using TMPro;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
|
||
public class Consoles : UIController
|
||
{
|
||
[SerializeField] TextMeshProUGUI con;
|
||
[SerializeField] Transform conGame;
|
||
[SerializeField] Button Btn;
|
||
List<TextMeshProUGUI> list = new List<TextMeshProUGUI>();
|
||
private void Start()
|
||
{
|
||
|
||
for (int i = 0; i < 100; i++)
|
||
{
|
||
show("****连接成功****"+i);
|
||
}
|
||
Btn.onClick.AddListener(() =>
|
||
{
|
||
for (int i = 0; i < list.Count; i++)
|
||
{
|
||
Destroy(list[i].gameObject);
|
||
}
|
||
list.Clear();
|
||
});
|
||
}
|
||
public override void show(string str,string colorr = "白色",Action ac = null)
|
||
{
|
||
TextMeshProUGUI conTex = Instantiate(con, conGame);
|
||
DateTimeOffset dateTimeOffset = DateTimeOffset.Now; // 以当前时间为准
|
||
string formattedString = dateTimeOffset.ToString("yyyy-MM-dd HH:mm:ss");
|
||
string colors = "<color=#FF0000>";//红色:FF0000,白色:FFFFFF
|
||
switch (colorr)
|
||
{
|
||
case "白色":
|
||
colors = "<color=#FFFFFF>";
|
||
break;
|
||
case "红色":
|
||
colors = "<color=#FF0000>";
|
||
break;
|
||
}
|
||
string tempStr = "<color=#02EFFE>" + formattedString+ ":</color>" + colors + str+"</color>";
|
||
conTex.text = tempStr;
|
||
list.Add(conTex);
|
||
ac?.Invoke();
|
||
StartCoroutine(ScrollToBottom());
|
||
}
|
||
IEnumerator ScrollToBottom()
|
||
{
|
||
yield return new WaitForEndOfFrame();
|
||
transform.GetComponent<ScrollRect>().verticalNormalizedPosition = 0f;
|
||
}
|
||
}
|