feat: add Localization extensions

pull/577/head
DESKTOP-2DOE206\Dexsper 2024-04-26 01:32:57 +06:00
parent 2e225fb841
commit 996a2cfa5b
5 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d2a30a3e9c8f5c0479d5aa1b92caeb64
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,32 @@
#if UNITASK_LOCALIZATION_SUPPORT
using Cysharp.Threading.Tasks.Linq;
using UnityEngine.Localization;
namespace Cysharp.Threading.Tasks
{
public static partial class LocalizationAsyncExtensions
{
public static IUniTaskAsyncEnumerable<string> OnValueChangedAsAsyncEnumerable(
this LocalizedString localizedString)
{
return UniTaskAsyncEnumerable.Create<string>(async (writer, cancellationToken) =>
{
async void Handler(string newValue)
{
await writer.YieldAsync(newValue);
}
localizedString.StringChanged += Handler;
cancellationToken.Register(() => localizedString.StringChanged -= Handler);
while (!cancellationToken.IsCancellationRequested)
{
await UniTask.Yield();
}
});
}
}
}
#endif

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b2739fb850114ecca748faa678ee0ee1
timeCreated: 1714073055

View File

@ -0,0 +1,24 @@
{
"name": "UniTask.Localization",
"rootNamespace": "",
"references": [
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:eec0964c48f6f4e40bc3ec2257ccf8c5",
"GUID:5c01796d064528144a599661eaab93a6"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [
{
"name": "com.unity.localization",
"expression": "",
"define": "UNITASK_LOCALIZATION_SUPPORT"
}
],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 966856f46ac0e9642a80e1d2352ea9fc
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: