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, IDebuger { List texts = new(); Dictionary 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(this); } } }