1
This commit is contained in:
60
Unity/Scripts/UX/Debuger/UXDebuger.cs
Normal file
60
Unity/Scripts/UX/Debuger/UXDebuger.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using UnityEngine.UIElements;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Linq;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public sealed class UXDebuger : UXElement<ListView>, IDebuger
|
||||
{
|
||||
List<string> texts = new();
|
||||
Dictionary<string, string> textDict = new();
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
visualElement.itemsSource = texts;
|
||||
visualElement.makeItem = MakeItem;
|
||||
visualElement.bindItem = BindItem;
|
||||
}
|
||||
public void Log(string context)
|
||||
{
|
||||
texts.Add(context);
|
||||
}
|
||||
public async void Log(string title, string context)
|
||||
{
|
||||
//await UniTask.SwitchToThreadPool();
|
||||
textDict.Insert(title, context);
|
||||
texts.Clear();
|
||||
texts.AddRange(textDict.Select(x => $"{x.Key}:{x.Value}"));
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(BITApp.CancellationTokenSource.Token);
|
||||
}
|
||||
catch (System.OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
VisualElement MakeItem()
|
||||
{
|
||||
return new Label();
|
||||
}
|
||||
void BindItem(VisualElement element, int index)
|
||||
{
|
||||
var label = element as Label;
|
||||
label.text = texts[index];
|
||||
}
|
||||
void Awake()
|
||||
{
|
||||
DI.Register<IDebuger>(this);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user