iFactory.Godot/BITKit/Scripts/Extensions/LabelExtensions.cs

31 lines
618 B
C#
Raw Normal View History

2023-07-12 15:27:27 +08:00
using System;
2023-07-12 12:11:10 +08:00
using Cysharp.Threading.Tasks;
using Godot;
namespace BITKit;
public static class LabelExtensions
{
public static async void SetTextAsync(this Label self, string text)
{
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
2023-07-12 15:27:27 +08:00
if (self is not null)
self.Text = text;
2023-07-12 12:11:10 +08:00
}
2023-07-12 15:27:27 +08:00
public static async void SetTextAsync(this RichTextLabel self, string text)
2023-07-12 12:11:10 +08:00
{
2023-07-12 15:27:27 +08:00
var path = self.SceneFilePath;
2023-07-12 12:11:10 +08:00
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
2023-07-12 15:27:27 +08:00
try
{
self.Text = text;
}
catch (Exception e)
{
BIT4Log.Warnning(path);
throw;
}
2023-07-12 12:11:10 +08:00
}
}