using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Text.RegularExpressions; using System.Text; using Cysharp.Threading.Tasks; using System.Threading.Tasks; using System.Threading; namespace BITKit.Transfcodes { public sealed class DeUnicode : Transcode { public bool isMainThread; public new bool enabled; CancellationToken cancellationToken; void Start() { cancellationToken = gameObject.GetCancellationTokenOnDestroy(); } public override async void Set(string t) { if (enabled) { if (isMainThread) { await UniTask.SwitchToMainThread(cancellationToken); } else { await UniTask.SwitchToTaskPool(); } output?.Set(FromUnicodeString(t)); } else { output?.Set(t); } } public static string FromUnicodeString(string str) { try { return new Regex(@"\\u([0-9A-F]{4})", RegexOptions.IgnoreCase | RegexOptions.Compiled).Replace( str, x => string.Empty + Convert.ToChar(Convert.ToUInt16(x.Result("$1"), 16))); } catch (System.Exception e) { Debug.LogWarning(str); Debug.LogException(e); return str; } } } }