기능 검색 기능
This commit is contained in:
66
Assets/Scripts/XRLib/UI/CommandLocalizationHelper.cs
Normal file
66
Assets/Scripts/XRLib/UI/CommandLocalizationHelper.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using Studio.Command;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Localization;
|
||||
using UnityEngine.Localization.Components;
|
||||
using UnityEngine.Localization.Settings;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace Studio
|
||||
{
|
||||
public class CommandLocalizationHelper : LocalizeStringEvent
|
||||
{
|
||||
protected override void OnEnable()
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
return;
|
||||
|
||||
base.OnEnable();
|
||||
}
|
||||
|
||||
public void Localization(string id, Action<string> onCompleted)
|
||||
{
|
||||
var localizedString = new LocalizedString()
|
||||
{
|
||||
TableReference = "Command",
|
||||
TableEntryReference = id
|
||||
};
|
||||
|
||||
AsyncOperationHandle<string> stringOperation = localizedString.GetLocalizedStringAsync();
|
||||
stringOperation.Completed += (op) =>
|
||||
{
|
||||
if (op.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
onCompleted?.Invoke(op.Result);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Not exist in table");
|
||||
onCompleted?.Invoke(id);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetLocalizedAllLocales(string id)
|
||||
{
|
||||
var result = new List<string>();
|
||||
var locales = LocalizationSettings.AvailableLocales.Locales;
|
||||
|
||||
foreach (var locale in locales)
|
||||
{
|
||||
var handle = LocalizationSettings.StringDatabase.GetTableEntryAsync("Command", id, locale);
|
||||
await handle.Task;
|
||||
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded && handle.Result.Entry != null)
|
||||
{
|
||||
result.Add(handle.Result.Entry.GetLocalizedString());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4bd9ae3f3097fe1469025dda7574bf9d
|
||||
Reference in New Issue
Block a user