@@ -11,6 +11,12 @@ public class ProgressBar : MonoBehaviour
1111
1212 public Image Image ;
1313
14+ private struct UpdateData
15+ {
16+ public double Progress ;
17+ public PatcherState State ;
18+ }
19+
1420 private void SetBar ( float start , float end )
1521 {
1622 var anchorMax = Image . rectTransform . anchorMax ;
@@ -23,15 +29,32 @@ private void SetBar(float start, float end)
2329 Image . rectTransform . anchorMin = anchorMin ;
2430 }
2531
26- private void SetProgress ( double progress )
32+ private void SetProgress ( UpdateData data )
2733 {
28- if ( progress <= 0 && _isIdle )
34+ if ( data . State == PatcherState . None )
35+ {
36+ Text . text = "" ;
37+ _isIdle = false ;
38+ SetBar ( 0 , 0 ) ;
39+ return ;
40+ }
41+
42+ if ( data . State == PatcherState . DisplayingError )
43+ {
44+ Text . text = "Error!" ;
45+ _isIdle = false ;
46+ SetBar ( 0 , 0 ) ;
47+ return ;
48+ }
49+
50+ if ( data . State == PatcherState . Connecting )
2951 {
3052 Text . text = "Connecting..." ;
53+ _isIdle = true ;
3154 return ;
3255 }
3356
34- _isIdle = false ;
57+ double progress = data . Progress ;
3558
3659 Text . text = progress >= 0.0 ? progress . ToString ( "0.0%" ) : "" ;
3760 float visualProgress = progress >= 0.0 ? ( float ) progress : 0.0f ;
@@ -41,15 +64,18 @@ private void SetProgress(double progress)
4164
4265 private void Start ( )
4366 {
44- Patcher . Instance . UpdaterStatus
45- . SelectSwitchOrDefault ( s => s . Progress , - 1.0 )
67+ var progress = Patcher . Instance . UpdaterStatus
68+ . SelectSwitchOrDefault ( s => s . Progress , - 1.0 ) ;
69+
70+ Patcher . Instance . State
71+ . CombineLatest ( progress , ( state , d ) => new UpdateData { Progress = d , State = state } )
4672 . ObserveOnMainThread ( )
4773 . Subscribe ( SetProgress )
4874 . AddTo ( this ) ;
4975 }
5076
5177
52- private bool _isIdle = true ;
78+ private bool _isIdle = false ;
5379 private const float IdleBarWidth = 0.2f ;
5480 private const float IdleBarSpeed = 1.2f ;
5581 private float _idleProgress = - IdleBarWidth ;
0 commit comments