50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using UnityEngine.Events;
|
|
using Sirenix.OdinInspector;
|
|
using Cysharp.Threading.Tasks;
|
|
using System;
|
|
namespace BITKit.UX
|
|
{
|
|
public class UXLabel : UXElement<Label>, IProvider<string>
|
|
{
|
|
const string keyword = "{x}";
|
|
[Header(Constant.Header.Settings)]
|
|
[SerializeReference, SubclassSelector] public References format;
|
|
public override T Get<T>()
|
|
{
|
|
if (typeof(T) == typeof(string))
|
|
{
|
|
if (visualElement.text is T t)
|
|
{
|
|
return t;
|
|
}
|
|
}
|
|
return base.Get<T>();
|
|
}
|
|
public async void Set(string t)
|
|
{
|
|
try
|
|
{
|
|
if (format is not null)
|
|
{
|
|
t = format.Get().Replace(keyword, t);
|
|
}
|
|
await UniTask.SwitchToMainThread(cancellationToken);
|
|
visualElement.text = t;
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
if (e is not OperationCanceledException)
|
|
throw;
|
|
}
|
|
}
|
|
string IProvider<string>.Get()
|
|
{
|
|
UniTask.SwitchToMainThread();
|
|
return visualElement.text;
|
|
}
|
|
}
|
|
} |