@@ -11,27 +11,27 @@ public interface IUITween
11
11
UIView LastUIView { get ; }
12
12
13
13
UIView NextUIView { get ; }
14
+ //UITween准备好
15
+ IUITween OnUITweenReady ( Action < UIView , UIView > onUITweenReady ) ;
14
16
//动画开始回调
15
- IUITween OnAnimationStart ( Action OnAnimStart ) ;
17
+ IUITween OnAnimationStart ( Action < UIView , UIView > onAnimStart ) ;
16
18
//动画结束
17
- IUITween OnAnimationComplete ( Action OnAnimComplete ) ;
19
+ IUITween OnAnimationComplete ( Action < UIView , UIView > onAnimComplete ) ;
18
20
//动画切换
19
- IUITween OnAnimationChanged ( Action < IUIAnimation , IUIAnimation > OnAnimChanged ) ;
21
+ IUITween OnAnimationChanged ( Action < IUIAnimation , IUIAnimation > onAnimChanged ) ;
20
22
//设置动画数组
21
23
IUITween SetAnimations ( IUIAnimation [ ] anims ) ;
22
- //设置动画队列
23
- IUITween SetAnimations ( Queue < IUIAnimation > anims ) ;
24
24
//播放动画
25
- IUITween RunAnimation ( ) ;
25
+ IUITween RunAnimation ( bool isQueue = false ) ;
26
26
}
27
27
28
28
internal class UITween : IUITween
29
29
{
30
- private Action _onAnimStart ;
31
- private Action _onAnimComplete ;
30
+ private Action < UIView , UIView > _onUITweenReady ;
31
+ private Action < UIView , UIView > _onAnimStart ;
32
+ private Action < UIView , UIView > _onAnimComplete ;
32
33
private Action < IUIAnimation , IUIAnimation > _onAnimChanged ;
33
- private IUIAnimation [ ] _arrayAnims ;
34
- private Queue < IUIAnimation > _queueAnims ;
34
+ private List < IUIAnimation > _anims = new List < IUIAnimation > ( ) ;
35
35
36
36
/// <summary>
37
37
/// 上一个UIView
@@ -44,14 +44,13 @@ internal class UITween : IUITween
44
44
45
45
public UITween Flush ( )
46
46
{
47
+ _onUITweenReady = null ;
47
48
_onAnimStart = null ;
48
49
_onAnimComplete = null ;
49
50
_onAnimChanged = null ;
50
51
LastUIView = null ;
51
52
NextUIView = null ;
52
- _arrayAnims = null ;
53
- _queueAnims = null ;
54
-
53
+ _anims . Clear ( ) ;
55
54
return this ;
56
55
}
57
56
@@ -65,14 +64,19 @@ public void SetNextUIView(UIView uiView)
65
64
NextUIView = uiView ;
66
65
}
67
66
67
+ private void SetUITweenReady ( )
68
+ {
69
+ _onUITweenReady ? . Invoke ( LastUIView , NextUIView ) ;
70
+ }
71
+
68
72
private void SetAnimationStart ( )
69
73
{
70
- _onAnimStart ? . Invoke ( ) ;
74
+ _onAnimStart ? . Invoke ( LastUIView , NextUIView ) ;
71
75
}
72
76
73
77
private void SetAnimationComplete ( )
74
78
{
75
- _onAnimComplete ? . Invoke ( ) ;
79
+ _onAnimComplete ? . Invoke ( LastUIView , NextUIView ) ;
76
80
Flush ( ) ;
77
81
}
78
82
@@ -81,89 +85,95 @@ private void SetAnimationChanged(IUIAnimation lastAnim, IUIAnimation nextAnim)
81
85
_onAnimChanged ? . Invoke ( lastAnim , nextAnim ) ;
82
86
}
83
87
84
- public IUITween OnAnimationChanged ( Action < IUIAnimation , IUIAnimation > OnAnimChanged )
88
+ public IUITween OnUITweenReady ( Action < UIView , UIView > onUITweenReady )
85
89
{
86
- _onAnimChanged += OnAnimChanged ;
90
+ _onUITweenReady = onUITweenReady ;
87
91
return this ;
88
92
}
89
93
90
- public IUITween OnAnimationComplete ( Action OnAnimComplete )
94
+ public IUITween OnAnimationChanged ( Action < IUIAnimation , IUIAnimation > onAnimChanged )
91
95
{
92
- _onAnimComplete += OnAnimComplete ;
96
+ _onAnimChanged += onAnimChanged ;
93
97
return this ;
94
98
}
95
99
96
- public IUITween OnAnimationStart ( Action OnAnimStart )
100
+ public IUITween OnAnimationComplete ( Action < UIView , UIView > onAnimComplete )
97
101
{
98
- _onAnimStart += OnAnimStart ;
102
+ _onAnimComplete += onAnimComplete ;
99
103
return this ;
100
104
}
101
105
102
- public IUITween SetAnimations ( IUIAnimation [ ] anims )
106
+ public IUITween OnAnimationStart ( Action < UIView , UIView > onAnimStart )
103
107
{
104
- _arrayAnims = anims ;
108
+ _onAnimStart += onAnimStart ;
105
109
return this ;
106
110
}
107
111
108
- public IUITween SetAnimations ( Queue < IUIAnimation > anims )
112
+ public IUITween SetAnimations ( IUIAnimation [ ] anims )
109
113
{
110
- _queueAnims = anims ;
114
+ _anims . AddRange ( anims ) ;
111
115
return this ;
112
116
}
113
117
114
- public IUITween RunAnimation ( )
118
+
119
+ public IUITween RunAnimation ( bool isQueue = false )
115
120
{
116
- RunAnim ( ) ;
121
+ RunAnim ( isQueue ) ;
117
122
return this ;
118
123
}
119
124
120
- private async void RunAnim ( )
125
+ private async void RunAnim ( bool isQueue = false )
121
126
{
122
- if ( _arrayAnims != null && _arrayAnims . Length > 0 )
127
+ //回调准备
128
+ SetUITweenReady ( ) ;
129
+ //播放动画
130
+ if ( _anims != null && _anims . Count > 0 )
123
131
{
124
132
await UniTask . NextFrame ( ) ;
125
- UniTask [ ] animTask = new UniTask [ _arrayAnims . Length ] ;
126
- for ( int i = 0 ; i < _arrayAnims . Length ; i ++ )
127
- {
128
- //call ui view
129
- AnimStartCallUIView ( _arrayAnims [ i ] ) ;
130
- animTask [ i ] = _arrayAnims [ i ] . Run ( ) ;
131
- }
132
- //call tween
133
- this . SetAnimationStart ( ) ;
134
- await UniTask . WhenAll ( animTask ) ;
135
- await UniTask . NextFrame ( ) ;
136
- for ( int i = 0 ; i < _arrayAnims . Length ; i ++ )
133
+ if ( isQueue )
137
134
{
138
- //call ui view
139
- AnimEndCallUIView ( _arrayAnims [ i ] ) ;
135
+ this . SetAnimationStart ( ) ;
136
+ IUIAnimation lastAnim = null ;
137
+ for ( int i = 0 ; i < _anims . Count ; i ++ )
138
+ {
139
+ IUIAnimation nextAnim = _anims [ i ] ;
140
+ //call ui view
141
+ if ( lastAnim != null )
142
+ {
143
+ AnimEndCallUIView ( lastAnim ) ;
144
+ }
145
+ AnimStartCallUIView ( nextAnim ) ;
146
+ //call tween
147
+ this . SetAnimationChanged ( lastAnim , nextAnim ) ;
148
+ await nextAnim . Run ( ) ;
149
+ lastAnim = nextAnim ;
150
+
151
+ }
152
+ await UniTask . NextFrame ( ) ;
140
153
}
141
- //call tween
142
- this . SetAnimationComplete ( ) ;
143
- }
144
- else if ( _queueAnims != null && _queueAnims . Count > 0 )
145
- {
146
- await UniTask . NextFrame ( ) ;
147
- this . SetAnimationStart ( ) ;
148
- IUIAnimation lastAnim = null ;
149
- while ( _queueAnims . Count > 0 )
150
- {
151
- IUIAnimation nextAnim = _queueAnims . Dequeue ( ) ;
152
- //call ui view
153
- if ( lastAnim != null )
154
+ else
155
+ {
156
+ UniTask [ ] animTask = new UniTask [ _anims . Count ] ;
157
+ for ( int i = 0 ; i < _anims . Count ; i ++ )
154
158
{
155
- AnimEndCallUIView ( lastAnim ) ;
159
+ //call ui view
160
+ AnimStartCallUIView ( _anims [ i ] ) ;
161
+ animTask [ i ] = _anims [ i ] . Run ( ) ;
156
162
}
157
- AnimStartCallUIView ( nextAnim ) ;
158
163
//call tween
159
- this . SetAnimationChanged ( lastAnim , nextAnim ) ;
160
- await nextAnim . Run ( ) ;
161
- lastAnim = nextAnim ;
164
+ this . SetAnimationStart ( ) ;
165
+ await UniTask . WhenAll ( animTask ) ;
166
+ await UniTask . NextFrame ( ) ;
167
+ for ( int i = 0 ; i < _anims . Count ; i ++ )
168
+ {
169
+ //call ui view
170
+ AnimEndCallUIView ( _anims [ i ] ) ;
171
+ }
162
172
}
163
- await UniTask . NextFrame ( ) ;
173
+
174
+ //call tween
164
175
this . SetAnimationComplete ( ) ;
165
176
}
166
-
167
177
}
168
178
169
179
private void AnimStartCallUIView ( IUIAnimation uiAnim )
0 commit comments