BITKit/Packages/Runtime~/Unity/Extensions/UGUI/UGUITable.cs

44 lines
1.2 KiB
C#
Raw Normal View History

2023-06-05 19:57:17 +08:00
using System.Data;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.Text;
using Cysharp.Threading.Tasks;
namespace BITKit.UX
{
public class UGUITable : Provider, IProvider<DataTable>
{
public TMP_Text text;
public DataTable Get()
{
throw new System.NotImplementedException();
}
public override void Set<T>(T obj)
{
if (obj is DataTable t)
{
Set(t);
}
else
{
throw new System.NotImplementedException();
}
}
public async void Set(DataTable t)
{
StringBuilder table = new();
t.Rows.Count.ForEach(row =>
{
StringBuilder line = new();
t.Columns.Count.ForEach(col =>
{
line.Append(t.Rows[row][col] as string);
});
table.AppendLine(line.ToString());
});
await UniTask.SwitchToMainThread(BITApp.CancellationTokenSource.Token);
text.text = table.ToString();
}
}
}