88using SiraUtil . Logging ;
99using TMPro ;
1010using UnityEngine ;
11+ using UnityEngine . ResourceManagement . AsyncOperations ;
1112using UnityEngine . SceneManagement ;
1213using Zenject ;
1314using Object = UnityEngine . Object ;
@@ -16,28 +17,28 @@ namespace SiraLocalizer.UI
1617{
1718 internal class FontLoader : IInitializable , IDisposable
1819 {
19- private static readonly string [ ] kFontNamesToRemove = { "NotoSansJP-Medium SDF" , "NotoSansKR-Medium SDF" , "SourceHanSansCN-Bold-SDF-Common-1(2k)" , "SourceHanSansCN-Bold-SDF-Common-2(2k)" , "SourceHanSansCN-Bold-SDF-Uncommon(2k)" } ;
20- private static readonly FontReplacementStrategy [ ] kFontReplacementStrategies = new [ ]
21- {
20+ private static readonly string [ ] kFontNamesToRemove = [ "NotoSansJP-Medium SDF" , "NotoSansKR-Medium SDF" , "SourceHanSansCN-Bold-SDF-Common-1(2k)" , "SourceHanSansCN-Bold-SDF-Common-2(2k)" , "SourceHanSansCN-Bold-SDF-Uncommon(2k)" ] ;
21+ private static readonly FontReplacementStrategy [ ] kFontReplacementStrategies =
22+ [
2223 new FontReplacementStrategy (
23- new [ ] { "Teko-Medium SDF" } ,
24- new [ ] { "Teko-Medium SDF Latin-1 Supplement" , "Oswald-Medium SDF Cyrillic" , "NotoSansHebrew-Medium SDF" , "SourceHanSans-Medium SDF" } ) ,
24+ [ "Teko-Medium SDF" ] ,
25+ [ "Teko-Medium SDF Latin-1 Supplement" , "Oswald-Medium SDF Cyrillic" , "NotoSansHebrew-Medium SDF" , "SourceHanSans-Medium SDF" ] ) ,
2526 new FontReplacementStrategy (
26- new [ ] { "Teko-Bold SDF" } ,
27- new [ ] { "Teko-Bold SDF Latin-1 Supplement" , "Oswald-Bold SDF Cyrillic" , "NotoSansHebrew-Bold SDF" , "SourceHanSans-Medium SDF" } ) ,
28- } ;
27+ [ "Teko-Bold SDF" ] ,
28+ [ "Teko-Bold SDF Latin-1 Supplement" , "Oswald-Bold SDF Cyrillic" , "NotoSansHebrew-Bold SDF" , "SourceHanSans-Medium SDF" ] ) ,
29+ ] ;
2930
3031 private readonly SiraLog _logger ;
31- private readonly FontAssetHelper _fontAssetHelper ;
3232
33- private readonly List < TMP_FontAsset > _fallbackFontAssets = new ( ) ;
34- private readonly List < TMP_FontAsset > _createdFontAssets = new ( ) ;
35- private readonly List < TMP_FontAsset > _processedFontAssets = new ( ) ;
33+ private readonly List < TMP_FontAsset > _fallbackFontAssets = [ ] ;
34+ private readonly List < TMP_FontAsset > _createdFontAssets = [ ] ;
35+ private readonly List < TMP_FontAsset > _processedFontAssets = [ ] ;
36+
37+ internal static TMP_FontAsset tekoBoldFontAsset { get ; private set ; }
3638
37- public FontLoader ( SiraLog logger , FontAssetHelper fontAssetHelper )
39+ public FontLoader ( SiraLog logger )
3840 {
3941 _logger = logger ;
40- _fontAssetHelper = fontAssetHelper ;
4142 }
4243
4344 public async void Initialize ( )
@@ -104,9 +105,22 @@ private async Task LoadFontAssetsAsync()
104105
105106 await assetBundle . UnloadAsync ( false ) ;
106107
108+ tekoBoldFontAsset = await LoadTekoBoldAsync ( ) ;
109+
107110 ApplyFallbackFonts ( ) ;
108111 }
109112
113+ private Task < TMP_FontAsset > LoadTekoBoldAsync ( )
114+ {
115+ TaskCompletionSource < TMP_FontAsset > taskCompletionSource = new ( ) ;
116+ AsyncOperationHandle < TMP_FontAsset > asyncOperationHandle = UnityEngine . AddressableAssets . Addressables . LoadAssetAsync < TMP_FontAsset > ( "Assets/Visuals/Fonts/Teko-Bold/Teko-Bold SDF.asset" ) ;
117+ asyncOperationHandle . Completed += ( aoh ) =>
118+ {
119+ taskCompletionSource . SetResult ( aoh . Result ) ;
120+ } ;
121+ return taskCompletionSource . Task ;
122+ }
123+
110124 private void LoadFontAsset ( AssetBundle assetBundle , string name )
111125 {
112126 TMP_FontAsset fontAsset = assetBundle . LoadAsset < TMP_FontAsset > ( name ) ;
@@ -154,7 +168,7 @@ private void AddFallbacksToFont(TMP_FontAsset fontAsset, IEnumerable<TMP_FontAss
154168 foreach ( TMP_FontAsset fallback in fallbacks . Reverse ( ) )
155169 {
156170 // creating a copy is necessary to prevent fonts from overwriting each others' atlases
157- TMP_FontAsset fallbackCopy = _fontAssetHelper . CopyFontAsset ( fallback , fontAsset . material ) ;
171+ TMP_FontAsset fallbackCopy = FontAssetHelper . CopyFontAsset ( fallback , fontAsset . material ) ;
158172 _createdFontAssets . Add ( fallbackCopy ) ;
159173
160174 // insert as first possible fallback font
0 commit comments