@@ -27,12 +27,12 @@ public sealed class OverlayLoadingCurtain : ILoadingCurtain
2727
2828 public OverlayLoadingCurtain ( IAssetFile < LoadingCurtainViewRoot > assetFile ) => _assetFile = assetFile ;
2929
30- public async Task Load ( Queue < ILoadingOperation > operations , CancellationToken cancellationToken )
30+ public async Task Load ( Queue < ILoadingOperation > operations , CancellationToken token )
3131 {
3232 _operationIndex = 0 ;
3333 _operationsCount = operations . Count ;
3434
35- _original = await FetchViewOriginal ( cancellationToken ) ;
35+ _original ?? = await _assetFile . LoadAsync ( cancellationToken : token ) ;
3636 _viewModel = new LoadingCurtainViewModel ( ) ;
3737 _view = Object . Instantiate ( _original ) ;
3838
@@ -46,23 +46,24 @@ public async Task Load(Queue<ILoadingOperation> operations, CancellationToken ca
4646 foreach ( var operation in operations )
4747 {
4848 _viewModel . Description . Value = operation . Description ;
49- await operation . Load ( new Progress < float > ( OnProgress ) , cancellationToken ) ;
49+ await operation . Load ( new Progress < float > ( OnProgress ) , token ) ;
5050 _operationIndex ++ ;
5151 }
5252
5353 operationsReady . SetReady ( ) ;
54- await WaitForViewClosed ( cancellationToken ) ;
54+ await WaitForViewClosed ( token ) ;
5555 }
5656
57- public Task Unload ( CancellationToken cancellationToken )
57+ public Task Unload ( CancellationToken token )
5858 {
5959 _operationIndex = 0 ;
6060 _operationsCount = 0 ;
6161 _viewModel ? . Dispose ( ) ;
6262 _viewReady ? . Dispose ( ) ;
6363
64- if ( _view != null )
64+ if ( _view )
6565 {
66+ _view . TearDown ( ) ;
6667 Object . Destroy ( _view . gameObject ) ;
6768 }
6869
@@ -78,22 +79,17 @@ public Task Unload(CancellationToken cancellationToken)
7879 return Task . CompletedTask ;
7980 }
8081
81- private void OnProgress ( float progress ) => _viewModel . Progress . Value = NormalizeProgress ( progress ) ;
82-
83- private float NormalizeProgress ( float progress )
82+ private void OnProgress ( float progress )
8483 {
85- var normalizedProgress = ( _operationIndex + progress ) / _operationsCount ;
86- if ( Mathf . Abs ( normalizedProgress - 1 ) < 0.01f )
84+ var normalized = ( _operationIndex + progress ) / _operationsCount ;
85+ if ( Mathf . Abs ( normalized - 1 ) < 0.01f )
8786 {
88- normalizedProgress = 1 ;
87+ normalized = 1 ;
8988 }
9089
91- return normalizedProgress ;
90+ _viewModel . Progress . Value = normalized ;
9291 }
9392
94- private async Task < LoadingCurtainViewRoot > FetchViewOriginal ( CancellationToken token ) =>
95- _original == null ? await _assetFile . LoadAsync ( cancellationToken : token ) : _original ;
96-
9793 private async Task WaitForViewClosed ( CancellationToken token )
9894 {
9995 while ( _viewReady . IsReady ( ) == false )
0 commit comments